Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moter test #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/GPIO1/imgs/pinbit_microbit_Hello_Real_World.fzz
100755 → 100644
Binary file not shown.
Binary file modified examples/GPIO1/imgs/pinbit_microbit_Hello_Real_World.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 24 additions & 22 deletions examples/GPIO1/main.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ var gpioPort0;

var blinkEnable;

async function connect(){
microBitBle = await microBitBleFactory.connect();
msg.innerHTML=("micro:bit BLE接続しました。");
var gpioAccess = await microBitBle.requestGPIOAccess();
var mbGpioPorts = gpioAccess.ports;
gpioPort0 = mbGpioPorts.get(0);
await gpioPort0.export("out"); //port0 out
blinkEnable = true;
LEDblink();
async function connect() {
microBitBle = await microBitBleFactory.connect();
msg.innerHTML = "micro:bit BLE接続しました。";
var gpioAccess = await microBitBle.requestGPIOAccess();
var mbGpioPorts = gpioAccess.ports;
gpioPort0 = mbGpioPorts.get(0);
await gpioPort0.export("out"); //port0 out
gpioPort1 = mbGpioPorts.get(1);
await gpioPort1.export("out"); // port1 out
blinkEnable = true;
LEDblink();
}

async function disconnect(){
blinkEnable = false;
await microBitBle.disconnect();
msg.innerHTML=("micro:bit BLE接続を切断しました。");
async function disconnect() {
blinkEnable = false;
await microBitBle.disconnect();
msg.innerHTML = "micro:bit BLE接続を切断しました。";
}

async function LEDblink(){
var gpio0Val = 0;
while ( blinkEnable ){
gpio0Val = (gpio0Val === 1 ) ? 0 : 1; // 条件 (三項) 演算子
await gpioPort0.write(gpio0Val);
msg.innerHTML= gpio0Val ;
await sleep(1000);
}
async function LEDblink() {
var gpio0Val = 0;
while (blinkEnable) {
gpio0Val = gpio0Val === 1 ? 0 : 1; // 条件 (三項) 演算子
await gpioPort0.write(gpio0Val);
await gpioPort1.write(!gpio0Val);
msg.innerHTML = gpio0Val;
await sleep(10000);
}
}