Пример #1
0
 def __light_action(self, nlu_entities=None):
     action = None
     position = None
     light = Light(23)
     if nlu_entities is not None:
         if 'action' in nlu_entities:
             action = nlu_entities['action'][0]['value']
         if 'position' in nlu_entities:
             position = nlu_entities['position'][0]['value']
         if action == 'on':
             light.turn_on()
         elif action == 'off':
             light.turn_off()
             self.__text_action("Ok")
         else:
             self.__text_action(
                 "I'm sorry, I couldn't understand what you meant by that")
Пример #2
0
from light import Light

LIGHT_PIN = 9
BUTTON_PIN = 10

GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

counter = Counter("/home/pi/counter.txt")
player = Player()
light = Light(LIGHT_PIN)
light.turn_off()

prev_input = 0

try:
    while True:
        input = GPIO.input(BUTTON_PIN)
        if ((not prev_input) and input):
            counter.increment()
            light.turn_on()
            player.play_random()
            light.turn_off()
        prev_input = input
        time.sleep(0.05)
except KeyboardInterrupt:
    pass
finally:
    GPIO.cleanup()
GPIO.cleanup()