Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import strip
- import time
- class Alert(strip.Animation):
- def init(self):
- self.min0 = 0 # Start LED of the first moving pixel
- self.min1 = 109 # Start LED of the seconds moving pixel
- self.max0 = self.max1 = 37 # LED where the to moving pixels should collide
- self.x0 = self.min0 # x position of the first moving led
- self.x1 = self.min1 # x position of the seconds moving led
- self.d0 = 1 if self.min0 < self.max0 else -1 # Direction of the first moving led
- self.d1 = 1 if self.min1 < self.max1 else -1 # Direction of the second moving led
- self.time = 2 # After n seconds should both moving pixels collide
- self.sp0 = float(self.time) / abs(self.max0 - self.min0) # speed of the first moving led (seconds/x)
- self.sp1 = float(self.time) / abs(self.max1 - self.min1) # speed of the seconds moving led (seconds/x)
- self.t0 = self.t1 = time.time() # timers
- def cycle(self):
- if not (self.x0 == self.x1): # If not both at the same position
- tnow = time.time()
- dt0 = tnow - self.t0
- dt1 = tnow - self.t1
- if dt0 >= self.sp0:
- self.t0 = time.time()
- self.x0 += self.d0
- self.strip.set_led(self.x0, 0, 0, 50)
- if dt1 >= self.sp1:
- self.t1 = time.time()
- self.x1 += self.d1
- self.strip.set_led(self.x1, 50, 0, 0)
- if __name__ == "__main__":
- strp = strip.Strip(109)
- print "strip created"
- strp.show_animation(Alert)
- time.sleep(11)
- print "show_animation done"
- strp.stop_animation()
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement