Ejemplo n.º 1
0
 def handle_events(self):
     ## Change animation on button press, or emote if both pressed.
     left = badge.left.event()
     right = badge.right.event()
     if right and left:
         emote.random()
         self.ival += 50
     elif right:
         self.set_animation(self.selected + 1)
     elif left:
         self.set_animation(self.selected - 1)
     # Service events.
     if badge.ble.any():
         ble()
     if badge.boop.event():
         if hasattr(self.anim, "boop") and callable(getattr(self.anim, "boop")):
             self.anim.boop()
         else:
             emote.boop()
             self.ival = 1000
Ejemplo n.º 2
0
            elif selected == 0:
                selected = len(available) - 1
                anim = available[selected]()
                print("Playing animation " + available[selected].__name__)
            else:
                selected = selected - 1
                anim = available[selected]()
                print("Playing animation " + available[selected].__name__)
        # Service events.
        elif badge.boop.event():
            if hasattr(anim, 'boop'):
                anim.boop()
            else:
                if settings.debug:
                    micropython.mem_info()
                emote.boop()
                ival = 1000
        elif badge.ble:
            check_ble()

        ## Pause for as long as long as both buttons are pressed.
        if badge.right.value() and badge.left.value():
            ival += 50

        ## Run the animation timing
        if ival > 50:
            pyb.delay(50)
            ival -= 50
        else:
            pyb.delay(ival)
            ival = 0