def main(): global clkPinLast # GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(BUTTON2PIN, GPIO.IN) GPIO.setup(BUTTON3PIN, GPIO.IN) GPIO.setup(BUTTON2PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(BUTTON3PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(LEDPIN, GPIO.OUT) GPIO.output(LEDPIN, False) GPIO.setup(LED2PIN, GPIO.OUT) ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, rotaryChange, switchPressed) recordButton = Button(BUTTONPIN, buttonPressed) hallIntro = HallSensor(HALLPIN, playIntro) hallSensor = HallSensor(HALL2PIN, sensorTrigger) if (GPIO.input(HALLPIN) == GPIO.HIGH): mounted = True print("init:", mounted) else: mounted = False print("init:", mounted) print(mounted) ky040.start() recordButton.start() hallIntro.start() hallSensor.start() print('Start program loop...') print("Waiting ...") try: while (True): # von 17 bis 7Uhr geht die Beleuchtung an if datetime.datetime.now().time() >= datetime.time( 17, 0, 0, 0) or datetime.datetime.now().time() <= datetime.time( 7, 0, 0, 0): GPIO.output(LED2PIN, True) else: GPIO.output(LED2PIN, False) time.sleep(0.01) finally: print('Stopping GPIO monitoring...') ky040.stop() recordButton.stop() hallIntro.stop() hallSensor.stop() GPIO.cleanup() print('Program ended.')
g1.brightness = g1.brightness + 20 print("turned brightness to: "+ str(g1.brightness)) def switchPressed(): g1.on = not g1.on #GPIO.output(led , not GPIO.input(led)) print("Lights on: "+str(g1.on)) ky040 = KY040(clk1, dt1, switch1, rotaryChanged, switchPressed) ky040.start(); GPIO.setmode(GPIO.BCM) b = phue.Bridge(ip='192.168.1.78',username='******') #b.connect() g1 = phue.Group(b,1) try: while True: sleep(.01)
else: pygame.mixer.music.pause() paused = True curr_song = 0 def change_song(dir): global curr_song global paused curr_song += 2 * dir - 1 curr_song %= len(playlist) pygame.mixer.music.load(playlist[curr_song]) pygame.mixer.music.play() paused = False GPIO.setmode(GPIO.BCM) ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, change_song, toggle_play) ky040.start() pygame.mixer.music.play() pygame.mixer.music.pause() try: while True: sleep(0.1) finally: ky040.stop() GPIO.cleanup()
if direction == 1: os.system("sudo amixer set PCM -- " + str(min(100, max(0, volume + volume_step))) + "%") else: os.system("sudo amixer set PCM -- " + str(min(100, max(0, volume - volume_step))) + "%") def switchPressed(): print "button pressed" if __name__ == "__main__": CLOCKPIN = 5 DATAPIN = 6 SWITCHPIN = 13 GPIO.setmode(GPIO.BCM) ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, rotaryChange, switchPressed) ky040.start() try: while True: time.sleep(0.05) finally: ky040.stop() GPIO.cleanup()
threshold = length_module_irl / len(tones) # BPM Player aus synth.py initialisieren bpm_player = sy.BPMPlayer("met4th.wav","metronome.wav",120,4,1) bpm_player.start() # Thread zum Lesen der Entfernung starten stop_threads = False sensor_thread = threading.Thread(target=read_from_sensor, args =(lambda : stop_threads, )) sensor_thread.start() GPIO.setmode(GPIO.BCM) # Modul zum Auslesen des Drehreglers initialisieren ky040 = KY040(CLOCKPIN,DATAPIN,SWITCHPIN,rotary_change,switch_pressed) ky040.start() # Main Loop try: while running: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key in perc: print("key pressed") perc[event.key].play() # Programm beenden except KeyboardInterrupt:
CLOCKPIN = 5 DATAPIN = 6 SWITCHPIN = 13 player = MusicPlayer(YEAR_DIRS) prev_press = 0 def button_press(): global prev_press if time.time() - prev_press > 1.0: player.toggle_pause() else: shutdown() prev_press = time.time() GPIO.setmode(GPIO.BCM) ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, player.change_chan, button_press) ky040.start() try: while True: for e in pygame.event.get(): if e.type == pygame.USEREVENT: player.change_song(1) finally: ky040.stop() GPIO.cleanup()
HAS_BMXSENSOR = True HAS_ROTARY = False board = Board() board.init() Button.init(pin=Pin(0, mode=Pin.IN, pull=Pin.PULL_UP)) heartbeat = Heartbeat(board.display) if HAS_CO2SENSOR: beeper = Beeper() co2sensor = CO2Sensor(board.display, beeper) if HAS_BMXSENSOR: bmx = BME680(board.display) if HAS_ROTARY: ky040 = KY040(board.display) scheduler = Scheduler() config = Config(board, scheduler) scheduler.register(board.display) if HAS_CO2SENSOR: scheduler.register(co2sensor) if HAS_BMXSENSOR: scheduler.register(bmx) if HAS_ROTARY: scheduler.register(ky040) scheduler.register(heartbeat)