-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-pico.py
44 lines (30 loc) · 994 Bytes
/
main-pico.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
""" Send data to Windows when a button is pressed
"""
from machine import Pin
import time
DELAY = time.ticks_ms()
DELAY_MS = 250
def more_volume(inst):
global DELAY, DELAY_MS
if time.ticks_diff(time.ticks_ms(), DELAY) < DELAY_MS:
return
print("U")
DELAY = time.ticks_ms()
def less_volume(inst):
global DELAY, DELAY_MS
if time.ticks_diff(time.ticks_ms(), DELAY) < DELAY_MS:
return
print("D")
DELAY = time.ticks_ms()
def change_device(inst):
global DELAY, DELAY_MS
if time.ticks_diff(time.ticks_ms(), DELAY) < DELAY_MS:
return
print("C")
DELAY = time.ticks_ms()
but1 = Pin(4, Pin.IN, Pin.PULL_DOWN)
but2 = Pin(3, Pin.IN, Pin.PULL_DOWN)
but3 = Pin(2, Pin.IN, Pin.PULL_DOWN)
but1.irq(handler=more_volume, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING)
but2.irq(handler=less_volume, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING)
but3.irq(handler=change_device, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING)