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