microbit/kitronic_03.py

21 lines
424 B
Python
Raw Normal View History

2021-03-21 08:17:45 +01:00
from microbit import *
def main():
light_on = False
touched = False
while True:
if pin0.is_touched() and not touched:
light_on = not light_on
touched = True
if not pin0.is_touched():
touched = False
if light_on:
pin2.write_analog(pin1.read_analog())
else:
pin2.write_digital(0)
if __name__ == "__main__":
main()