Advertisement
KRITSADA

VEC Excercise microbit Running On TM1637

Jan 27th, 2020
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. ###เฉลยโจทย์ LED วิ่งไล่กันด้วย TM1637 และ 7 Segment
  2. ##4 เขียนโค้ดไฟวิ่งอย่างง่ายผ่าน TM1637  
  3.  
  4. from microbit import *
  5. import tm1637
  6. tm=tm1637.TM1637(clk=pin15,dio=pin16)
  7. x=[[0x01,0,0,0],[0,0x01,0,0],[0,0,0x01,0],[0,0,0,0x02],[0,0,0,0x04],[0,0,0,0x08],[0,0,0x08,0],[0,0x08,0,0],[0x08,0,0,0],[0x10,0,0,0],[0x20,0,0,0]]
  8. a=True
  9. while(1):
  10.     if button_a.was_pressed():
  11.         if a:   a=False
  12.         else: a=True
  13.     for i in range(0,11):
  14.         if a:
  15.             tm.write(x[10-i])
  16.         else:
  17.             tm.write(x[i])
  18.         if button_b.was_pressed():
  19.             while not button_b.was_pressed():pass
  20.         sleep(100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement