38 lines
830 B
Python
38 lines
830 B
Python
|
# Imports
|
||
|
from machine import Pin
|
||
|
import time
|
||
|
|
||
|
gruen = Pin(18, Pin.OUT)
|
||
|
gelb = Pin(19, Pin.OUT)
|
||
|
rot = Pin(20, Pin.OUT)
|
||
|
|
||
|
|
||
|
# Set up tilt sensor pin
|
||
|
tilt = Pin(26, Pin.IN, Pin.PULL_DOWN)
|
||
|
|
||
|
# Set up a counter variable at zero
|
||
|
tiltcount = 0
|
||
|
|
||
|
# Create a state variable at zero
|
||
|
state = 0
|
||
|
|
||
|
while True: # Run forever
|
||
|
|
||
|
time.sleep(1.1) # Short delay
|
||
|
rot.value(1)
|
||
|
|
||
|
|
||
|
if state == 0 and tilt.value() == 1: # If state is 0 and our pin is HIGH
|
||
|
rot.value(0)
|
||
|
tiltcount = tiltcount + 1 # Add +1 to tiltcount
|
||
|
|
||
|
state = 1 # Change state to 1
|
||
|
|
||
|
print("tilts =",tiltcount) # Print our new tiltcount
|
||
|
|
||
|
if state == 1 and tilt.value() == 0: # If state is 1 and our pin is LOW
|
||
|
|
||
|
state = 0 # Change the state to 0
|
||
|
|
||
|
|