micro:bit お出かけサポート
お出かけサポートシステム(ver2くらい あまり動作しない)
# Add your Python code here. E.g.
from microbit import *
#import microbit
import music
import radio
import os
display.scroll('RadioV1')
radio.config(channel=10, power=4)#BLE init
radio.on()#BLE ON
btnChk = False
myID = 1
grCount = 1
grChk = False
oneTime = False
timerA = 0
timerB = 0
#tune = ["C4:4", "D4:4", "E4:4", "C4:4", "C4:4", "D4:4", "E4:4", "C4:4","E4:4", "F4:4", "G4:8", "E4:4", "F4:4", "G4:8"]
tune2 = ["E4:1"]
#File read
if 'id.txt' in os.listdir():
with open('id.txt') as my_id:
myidtxt = my_id.read()
myID = int(myidtxt)
if 'gr.txt' in os.listdir():
with open('gr.txt') as gr_id:
mygridtxt = gr_id.read()
grCount = int(mygridtxt)
while True:
if button_a.is_pressed() and button_b.is_pressed():
##setingMode
if btnChk is False:
btnChk = True
display.scroll('SET')
display.scroll('ID=' + str(myID))
elif btnChk is True:
btnChk = False #end set mode
shakeChk = False #end shake mode
display.show(Image.YES)
elif button_a.is_pressed():
if btnChk is True and grChk is False:#ID count mode
if myID < 20:
myID += 1
else:
myID = 0
display.scroll('ID' + str(myID))
#sleep(200)
#display.clear()
elif btnChk is False and grChk is True:#group count mode
if grCount < 20:
grCount += 1
else:
grCount = 0
display.scroll('GR' + str(grCount))
else:
music.play(tune2)
elif button_b.is_pressed():
if btnChk is False and grChk is False:
radio.config(power=7)#HelpMode
radio.send('HELP')
radio.config(power=4)#HelpMode
display.scroll('HELP')
sleep(800)
display.clear()
elif btnChk is False and grChk is True:#end gr set mode
btnChk = False #end set mode
grChk = False #end shake mode
radio.send(str(grCount))
display.show(Image.YES)
sleep(500)
display.clear()
#File Save
with open('id.txt', 'w') as my_id:
my_id.write(str(myID))
with open('gr.txt', 'w') as gr_id:
gr_id.write(str(grCount))
if btnChk is True and grChk is False:#end id set mode
btnChk = False
grChk = True#to Group set mode
display.show(Image.YES)
sleep(500)
display.clear()
display.scroll('GR=' + str(grCount))
#else:
#display.scroll('')
s = radio.receive()
if s == 'flash':
display.scroll('Recieve')
elif s == 'HELP':
display.scroll('!')
music.play(music.RINGTONE)
display.show(Image.SAD)
sleep(3000)
display.clear()
elif(s):
if btnChk is False and grChk is False:
grCount = int(s)
display.scroll('GR=' + str(grCount))
with open('gr.txt', 'w') as gr_id:
gr_id.write(str(grCount))
# display.show(Image.HEART)
if running_time() > timerA:
#sendID
sleep(100)
