Advertisement
KRITSADA

microbit receive command from radio control neopixel

Jan 27th, 2020
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. #ภาครับ micro:bit ควบคุม NeoPixel ไร้สาย
  2. #2. ควบคุม NeoPixel ทั้งจำนวนการติด ความสว่าง และ สี จาก micro:bit อีกชุด
  3. from microbit import *
  4. import radio
  5. import neopixel
  6. radio.on()
  7. radio.config(channel=42)
  8. radio.config(power=7)
  9. np = neopixel.NeoPixel(pin14, 12)
  10. R=1;G=1;B=1;X=0;y=11;z=10;x=0
  11. while not button_b.is_pressed():
  12.     Radio = radio.receive()
  13.     if Radio != None:
  14.         dat = Radio.split(",")
  15.         if dat[0] == "C":
  16.             display.show("C")
  17.             y = int(int(dat[1]) / 90)
  18.             print(y)
  19.         elif dat[0] == "L":
  20.             display.show("L")
  21.             z = int(int(dat[1])/4)-1
  22.             print(z)
  23.         elif dat[0] == "B":
  24.             display.show("B")
  25.             x = int(dat[1])
  26.             print(x)
  27.     for i in range(0, y + 1):
  28.         np[i] = (R * z, G * z, B * z)
  29.         np.show()
  30.     for i in range(y + 1, 12):
  31.         np[i] = (0, 0, 0)
  32.         np.show()
  33.     if x == 1:
  34.         sleep(200)
  35.         if X < 6:
  36.             X = X + 1
  37.         else:
  38.             X = 0
  39.         display.show(str(X))
  40.         if X == 0:
  41.             R = 1
  42.             G = 0
  43.             B = 0
  44.         elif X == 1:
  45.             R = 1
  46.             G = 1
  47.             B = 0
  48.         elif X == 2:
  49.             R = 0
  50.             G = 1
  51.             B = 0
  52.         elif X == 3:
  53.             R = 0
  54.             G = 1
  55.             B = 1
  56.         elif X == 4:
  57.             R = 0
  58.             G = 0
  59.             B = 1
  60.         elif X == 5:
  61.             R = 1
  62.             G = 0
  63.             B = 1
  64.         elif X == 6:
  65.             R = 1
  66.             G = 1
  67.             B = 1
  68. for i in range(0, 12):
  69.     np[i] = (0, 0, 0)
  70. np.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement