yd-pyboard/test/main.py

53 lines
763 B
Python
Raw Normal View History

2024-02-09 17:46:30 +08:00
import time
import _thread
from pyb import LED
from pyb import Accel
import neopixel
accel = Accel()
p = machine.Pin.board.RGB
n = neopixel.NeoPixel(p, 1)
def funcA(sec):
time.sleep(sec)
while 1:
LED(1).toggle()
time.sleep(0.5)
LED(2).toggle()
time.sleep(0.5)
LED(3).toggle()
time.sleep(0.5)
LED(4).toggle()
time.sleep(0.5)
def funcC(sec):
time.sleep(sec)
while 1:
if accel.x()>=10:
n[0] = (18, 0, 0)
n.write()
elif accel.x()<=-10:
n[0] = (0, 0, 20)
n.write()
elif accel.x()<10 and accel.y()>-10:
n[0] = (0, 20, 0)
n.write()
time.sleep(0.2)
if __name__ == '__main__':
_thread.start_new_thread(funcA, (0.5,))
_thread.start_new_thread(funcC, (1,))