Skip to content

Instantly share code, notes, and snippets.

@codepope
Created March 21, 2020 18:02
Show Gist options
  • Save codepope/ccd501b58973c82d6851f70401af9353 to your computer and use it in GitHub Desktop.
Save codepope/ccd501b58973c82d6851f70401af9353 to your computer and use it in GitHub Desktop.
A small snippet regarding getting the Clue and the Elecfreaks Joystick:Bit working together.
from adafruit_clue import clue
import board
from analogio import AnalogIn
clue.sea_level_pressure = 1020
ap0=AnalogIn(board.P0)
ap1=AnalogIn(board.P1)
ap2=AnalogIn(board.P2)
clue_data = clue.simple_text_display(title="CLUE Sensor Data!", title_scale=2)
buttons = {0: 'A',
516: 'B',
684: 'C',
768: 'D',
853: 'E',
819: 'F'}
def button_press():
press = ap2.value / 64
if press < 900:
for key in buttons:
if press>key-5 and press<key+5:
return buttons[key]
def joystick_push():
x = ap0.value
y = ap1.value
return x, y
while True:
clue_data[0].text = "Acceleration: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration)
clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro)
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)
clue_data[3].text = "Pressure: {:.3f}hPa".format(clue.pressure)
clue_data[4].text = "Altitude: {:.1f}m".format(clue.altitude)
clue_data[5].text = "Temperature: {:.1f}C".format(clue.temperature)
clue_data[6].text = "Humidity: {:.1f}%".format(clue.humidity)
clue_data[7].text = "Proximity: {}".format(clue.proximity)
clue_data[8].text = "Gesture: {}".format(clue.gesture)
clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(*clue.color)
clue_data[10].text = "Joystick X,Y: {}".format(joystick_push())
clue_data[11].text = "Buttons: {}".format(button_press())
clue_data.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment