You may want to add buttons, LEDs, switches or simple sensors to your robot project. With Crickit, you get 8 x 'general purpose in/out' (GPIO) pins called signals. Each signal can be a digital input (button/switch), digital output (LED, for example), or analog input.
This lets you add a ton of external components easily, and its all handled by seesaw. Perfect when you have a Feather without analog inputs (like the ESP8266) or just need a ton of extra pins.
The signal pins are on a 3x8 female header, so you can poke wires directly in!
import time from adafruit_crickit import crickit # For signal control, we'll chat directly with seesaw, use 'ss' to shorted typing! ss = crickit.seesaw # Two buttons are pullups, connect to ground to activate BUTTON_1 = crickit.SIGNAL1 # button #1 connected to signal port 1 & ground BUTTON_2 = crickit.SIGNAL2 # button #2 connected to signal port 2 & ground ss.pin_mode(BUTTON_1, ss.INPUT_PULLUP) ss.pin_mode(BUTTON_2, ss.INPUT_PULLUP) # Two LEDs are outputs, on by default LED_1 = crickit.SIGNAL3 # LED #1 connected to signal port 3 & ground LED_2 = crickit.SIGNAL4 # LED #2 connected to signal port 4 & ground ss.pin_mode(LED_1, ss.OUTPUT) ss.pin_mode(LED_2, ss.OUTPUT) ss.digital_write(LED_1, True) ss.digital_write(LED_2, True) while True: if not ss.digital_read(BUTTON_1): print("Button 1 pressed") ss.digital_write(LED_1, True) else: ss.digital_write(LED_1, False) if not ss.digital_read(BUTTON_2): print("Button 2 pressed") ss.digital_write(LED_2, True) else: ss.digital_write(LED_2, False)
Each of the 8 signal pin numbers is available under the crickit
object as SIGNAL1
through SIGNAL8
. Note these are not DigitalInOut or Pin objects! We need to use the crickit.seesaw
object to set the mode, direction, and readings
To simplify our code we shorted the crickit.seesaw
object to just ss
# For signal control, we'll chat directly with seesaw, use 'ss' to shorted typing! ss = crickit.seesaw
Digital Pin Modes
You can set the mode of each signal pin with ss.pin_mode(signal, mode)
where signal
is the crickit.SIGNAL#
from above and mode can be ss.OUTPUT
, ss.INPUT
or ss.INPUT_PULLUP
ss.pin_mode(BUTTON_1, ss.INPUT_PULLUP) ss.pin_mode(BUTTON_2, ss.INPUT_PULLUP) ... ss.pin_mode(LED_1, ss.OUTPUT) ss.pin_mode(LED_2, ss.OUTPUT)
Digital Read
Then, you can read the values True or False with ss.digital_read(signal)
Don't forget you have to set it to be an INPUT first!
ss.digital_read(BUTTON_1)
Digital Write
Or, you can set the signal you want to a high value with ss.digital_write(signal, True)
, or set to low value with ss.digital_write(signal, False)
. Don't forget you have to set it to be an OUTPUT first!
# LED On ss.digital_write(LED_2, True) # LED Off ss.digital_write(LED_2, False)
And here is the example code. You can see we read the signal with ss.analog_read(signal)
which returns a value from 0 to 1023.
import time from adafruit_crickit import crickit # For signal control, we'll chat directly with seesaw, use 'ss' to shorted typing! ss = crickit.seesaw # potentiometer connected to signal #3 pot = crickit.SIGNAL3 while True: print((ss.analog_read(pot),)) time.sleep(0.25)
By printing the value in a python tuple (ss.analog_read(pot),)
we can use the Mu plotter to see the values immediately!