|
| 1 | +# main.py - code to test the Adafruit CRICKIT board with |
| 2 | +# the BBC micro:bit and MicroPython (NOT CircuitPython) |
| 3 | +# MIT License by Limor Fried and Mike Barela, 2019 |
| 4 | +# This code requires the seesaw.py module as a driver |
| 5 | +import time |
| 6 | +import seesaw |
| 7 | + |
| 8 | +seesaw.init() |
| 9 | +while True: |
| 10 | + # Touch test - check with the Mu plotter! |
| 11 | + print("Touch: \n(", end="") |
| 12 | + for i in range(1, 5): |
| 13 | + print(seesaw.read_touch(i), end=", \t") |
| 14 | + print(")") |
| 15 | + |
| 16 | + # analog read signal test - assumes analog input pin 8 |
| 17 | + print("Analog signal:\n(", end="") |
| 18 | + print(seesaw.analog_read(8), end=", \t") |
| 19 | + print(")") |
| 20 | + |
| 21 | + seesaw.write_digital(2, 0) # Assumes LED on Signal pin 2 |
| 22 | + time.sleep(0.1) |
| 23 | + seesaw.write_digital(2, 1) |
| 24 | + time.sleep(0.1) |
| 25 | + |
| 26 | + if seesaw.read_digital(7): # Assumes button on Signal pin 7 |
| 27 | + print("pin high") |
| 28 | + else: |
| 29 | + print("pin low") |
| 30 | + |
| 31 | + # Servo test - assumes servo on Servo position 1 on CRICKIT |
| 32 | + seesaw.servo(1, 0, min=0.5, max=2.5) |
| 33 | + time.sleep(0.5) |
| 34 | + seesaw.servo(1, 90, min=0.5, max=2.5) |
| 35 | + time.sleep(0.5) |
| 36 | + seesaw.servo(1, 180, min=0.5, max=2.5) |
| 37 | + time.sleep(0.5) |
| 38 | + |
| 39 | + # Drive test |
| 40 | + # seesaw.drive(1, 0.2) |
| 41 | + # seesaw.drive(2, 0.4) |
| 42 | + # seesaw.drive(3, 0.6) |
| 43 | + # seesaw.drive(4, 0.8) |
| 44 | + |
| 45 | + # motor test - assumes a DC motor on CRICKIT Motor 1 terminals |
| 46 | + seesaw.motor(1, 1) |
| 47 | + time.sleep(0.5) |
| 48 | + seesaw.motor(1, 0) |
| 49 | + time.sleep(0.5) |
| 50 | + seesaw.motor(1, -1) |
| 51 | + time.sleep(0.5) |
| 52 | + seesaw.motor(1, 0) |
| 53 | + |
| 54 | + time.sleep(0.1) |
0 commit comments