Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import strip
  2. import time
  3.  
  4.  
  5. class Alert(strip.Animation):
  6. def init(self):
  7. self.min0 = 0 # Start LED of the first moving pixel
  8. self.min1 = 109 # Start LED of the seconds moving pixel
  9.  
  10. self.max0 = self.max1 = 37 # LED where the to moving pixels should collide
  11.  
  12. self.x0 = self.min0 # x position of the first moving led
  13. self.x1 = self.min1 # x position of the seconds moving led
  14.  
  15. self.d0 = 1 if self.min0 < self.max0 else -1 # Direction of the first moving led
  16. self.d1 = 1 if self.min1 < self.max1 else -1 # Direction of the second moving led
  17.  
  18. self.time = 2 # After n seconds should both moving pixels collide
  19.  
  20. self.sp0 = float(self.time) / abs(self.max0 - self.min0) # speed of the first moving led (seconds/x)
  21. self.sp1 = float(self.time) / abs(self.max1 - self.min1) # speed of the seconds moving led (seconds/x)
  22.  
  23. self.t0 = self.t1 = time.time() # timers
  24.  
  25. def cycle(self):
  26. if not (self.x0 == self.x1): # If not both at the same position
  27. tnow = time.time()
  28. dt0 = tnow - self.t0
  29. dt1 = tnow - self.t1
  30.  
  31. if dt0 >= self.sp0:
  32. self.t0 = time.time()
  33. self.x0 += self.d0
  34. self.strip.set_led(self.x0, 0, 0, 50)
  35.  
  36. if dt1 >= self.sp1:
  37. self.t1 = time.time()
  38. self.x1 += self.d1
  39. self.strip.set_led(self.x1, 50, 0, 0)
  40.  
  41.  
  42. if __name__ == "__main__":
  43. strp = strip.Strip(109)
  44. print "strip created"
  45. strp.show_animation(Alert)
  46. time.sleep(11)
  47. print "show_animation done"
  48. strp.stop_animation()
  49. time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement