demos
This commit is contained in:
parent
e083ca6185
commit
2bb1814e8d
10 changed files with 310 additions and 0 deletions
24
Introducing_Gemma_M0/Gemma_AnalogIn.py
Normal file
24
Introducing_Gemma_M0/Gemma_AnalogIn.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Gemma IO demo - analog inputs
|
||||
|
||||
from digitalio import DigitalInOut, Direction
|
||||
from analogio import AnalogIn
|
||||
import board
|
||||
import time
|
||||
|
||||
led = DigitalInOut(board.L)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
analog0in = AnalogIn(board.A0)
|
||||
analog1in = AnalogIn(board.A1)
|
||||
analog2in = AnalogIn(board.A2)
|
||||
|
||||
def getVoltage(pin):
|
||||
return (pin.value * 3.3) / 65536
|
||||
|
||||
while True:
|
||||
print("A0: %f \t\t A1: %f \t\t A2: %f" %
|
||||
(getVoltage(analog0in),
|
||||
getVoltage(analog1in),
|
||||
getVoltage(analog2in)))
|
||||
|
||||
time.sleep(0.1)
|
||||
13
Introducing_Gemma_M0/Gemma_AnalogOut.py
Normal file
13
Introducing_Gemma_M0/Gemma_AnalogOut.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Gemma IO demo - analog output
|
||||
|
||||
from analogio import AnalogOut
|
||||
import board
|
||||
import time
|
||||
|
||||
aout = AnalogOut(board.A0)
|
||||
|
||||
while True:
|
||||
# Count up from 0 to 65535, with 64 increment
|
||||
# which ends up corresponding to the DAC's 10-bit range
|
||||
for i in range (0,65535,64):
|
||||
aout.value = i
|
||||
18
Introducing_Gemma_M0/Gemma_CapTouch.py
Normal file
18
Introducing_Gemma_M0/Gemma_CapTouch.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Gemma IO demo - captouch
|
||||
|
||||
import touchio
|
||||
import board
|
||||
import time
|
||||
|
||||
touch0 = touchio.TouchIn(board.A0)
|
||||
touch1 = touchio.TouchIn(board.A1)
|
||||
touch2 = touchio.TouchIn(board.A2)
|
||||
|
||||
while True:
|
||||
if touch0.value:
|
||||
print("A0 touched!")
|
||||
if touch1.value:
|
||||
print("A1 touched!")
|
||||
if touch2.value:
|
||||
print("A2 touched!")
|
||||
time.sleep(0.01)
|
||||
51
Introducing_Gemma_M0/Gemma_DotStar.py
Normal file
51
Introducing_Gemma_M0/Gemma_DotStar.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Gemma IO demo - Dotstar
|
||||
|
||||
from digitalio import *
|
||||
from board import *
|
||||
import dotstar
|
||||
import time
|
||||
|
||||
numpix = 64
|
||||
strip = dotstar.DotStar(D2, D0, numpix, brightness=0.2)
|
||||
|
||||
led = DigitalInOut(D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
def wheel(pos):
|
||||
# Input a value 0 to 255 to get a color value.
|
||||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0):
|
||||
return [0, 0, 0]
|
||||
if (pos > 255):
|
||||
return [0, 0, 0]
|
||||
if (pos < 85):
|
||||
return [int(pos * 3), int(255 - (pos*3)), 0]
|
||||
elif (pos < 170):
|
||||
pos -= 85
|
||||
return [int(255 - pos*3), 0, int(pos*3)]
|
||||
else:
|
||||
pos -= 170
|
||||
return [0, int(pos*3), int(255 - pos*3)]
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
for j in range(255):
|
||||
for i in range(len(strip)):
|
||||
idx = int ((i * 256 / len(strip)) + j)
|
||||
strip[i] = wheel(idx & 255)
|
||||
strip.write()
|
||||
time.sleep(wait)
|
||||
|
||||
while True:
|
||||
strip.fill([255, 0, 0])
|
||||
strip.write()
|
||||
time.sleep(1)
|
||||
|
||||
strip.fill([0, 255, 0])
|
||||
strip.write()
|
||||
time.sleep(1)
|
||||
|
||||
strip.fill([0, 0, 255])
|
||||
strip.write()
|
||||
time.sleep(1)
|
||||
|
||||
rainbow_cycle(0)
|
||||
58
Introducing_Gemma_M0/Gemma_HIDkeyboard.py
Normal file
58
Introducing_Gemma_M0/Gemma_HIDkeyboard.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# Gemma IO demo - Keyboard emu
|
||||
|
||||
import digitalio
|
||||
import touchio
|
||||
from board import *
|
||||
import time
|
||||
from adafruit_hid.keyboard import Keyboard
|
||||
from adafruit_hid.keycode import Keycode
|
||||
|
||||
# A simple neat keyboard demo in circuitpython
|
||||
|
||||
# The button pins we'll use, each will have an internal pullup
|
||||
buttonpins = [D2, D0]
|
||||
# our array of button objects
|
||||
buttons = []
|
||||
# One pin will be capacitive touch
|
||||
ptcbutton = touchio.TouchIn(D1)
|
||||
|
||||
# The keycode sent for each button, will be paired with a control key
|
||||
buttonkeys = [Keycode.A, Keycode.B, Keycode.C]
|
||||
controlkey = Keycode.SHIFT
|
||||
|
||||
# the keyboard object!
|
||||
kbd = Keyboard()
|
||||
|
||||
# make all pin objects, make them inputs w/pullups
|
||||
for pin in buttonpins:
|
||||
button = digitalio.DigitalInOut(pin)
|
||||
button.direction = digitalio.Direction.INPUT
|
||||
button.pull = digitalio.Pull.UP
|
||||
buttons.append(button)
|
||||
|
||||
led = digitalio.DigitalInOut(D13)
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("Waiting for button presses")
|
||||
|
||||
while True:
|
||||
# check each button
|
||||
for button in buttons:
|
||||
if (not button.value): # pressed?
|
||||
i = buttons.index(button)
|
||||
print("Button #%d Pressed" % i)
|
||||
|
||||
# turn on the LED
|
||||
led.value = True
|
||||
|
||||
while (not button.value):
|
||||
pass # wait for it to be released!
|
||||
# type the keycode!
|
||||
k = buttonkeys[i] # get the corresp. keycode
|
||||
kbd.press(controlkey, k)
|
||||
kbd.release_all()
|
||||
|
||||
# turn off the LED
|
||||
led.value = False
|
||||
|
||||
time.sleep(0.01)
|
||||
15
Introducing_Gemma_M0/Gemma_I2CScan.py
Normal file
15
Introducing_Gemma_M0/Gemma_I2CScan.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Gemma IO demo - I2C scan
|
||||
|
||||
from digitalio import *
|
||||
from board import *
|
||||
import busio
|
||||
import time
|
||||
|
||||
led = DigitalInOut(D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
i2c = busio.I2C(D2, D0)
|
||||
|
||||
while True:
|
||||
print("I2C addresses found:", [hex(i) for i in i2c.scan()])
|
||||
time.sleep(2)
|
||||
19
Introducing_Gemma_M0/Gemma_I2Csi7021.py
Normal file
19
Introducing_Gemma_M0/Gemma_I2Csi7021.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Gemma M0 IO Demo - I2C demo
|
||||
|
||||
from digitalio import *
|
||||
from board import *
|
||||
import busio
|
||||
import adafruit_si7021
|
||||
import time
|
||||
|
||||
led = DigitalInOut(D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
i2c = busio.I2C(D2, D0)
|
||||
print("I2C addresses found:", [hex(i) for i in i2c.scan()])
|
||||
|
||||
si7021 = adafruit_si7021.SI7021(i2c)
|
||||
|
||||
while True:
|
||||
print("Temp: %0.2F *C Humidity: %0.1F %%" % (si7021.temperature, si7021.relative_humidity))
|
||||
time.sleep(1)
|
||||
54
Introducing_Gemma_M0/Gemma_NeoPixel.py
Normal file
54
Introducing_Gemma_M0/Gemma_NeoPixel.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Gemma IO demo - NeoPixel
|
||||
|
||||
from digitalio import *
|
||||
from board import *
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
pixpin = D1
|
||||
numpix = 10
|
||||
|
||||
led = DigitalInOut(D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3)
|
||||
|
||||
|
||||
def wheel(pos):
|
||||
# Input a value 0 to 255 to get a color value.
|
||||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0):
|
||||
return [0, 0, 0]
|
||||
if (pos > 255):
|
||||
return [0, 0, 0]
|
||||
if (pos < 85):
|
||||
return [int(pos * 3), int(255 - (pos*3)), 0]
|
||||
elif (pos < 170):
|
||||
pos -= 85
|
||||
return [int(255 - pos*3), 0, int(pos*3)]
|
||||
else:
|
||||
pos -= 170
|
||||
return [0, int(pos*3), int(255 - pos*3)]
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
for j in range(255):
|
||||
for i in range(len(strip)):
|
||||
idx = int ((i * 256 / len(strip)) + j)
|
||||
strip[i] = wheel(idx & 255)
|
||||
strip.write()
|
||||
time.sleep(wait)
|
||||
|
||||
while True:
|
||||
strip.fill([255, 0, 0])
|
||||
strip.write()
|
||||
time.sleep(0.2)
|
||||
|
||||
strip.fill([0, 255, 0])
|
||||
strip.write()
|
||||
time.sleep(0.2)
|
||||
|
||||
strip.fill([0, 0, 255])
|
||||
strip.write()
|
||||
time.sleep(0.2)
|
||||
|
||||
rainbow_cycle(0.001)
|
||||
35
Introducing_Gemma_M0/Gemma_Touch_DotStar.py
Normal file
35
Introducing_Gemma_M0/Gemma_Touch_DotStar.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Gemma IO demo - captouch to dotstar
|
||||
|
||||
import touchio
|
||||
import busio
|
||||
import board
|
||||
import time
|
||||
|
||||
dotstar = busio.SPI(board.APA102_SCK, board.APA102_MOSI)
|
||||
touch0 = touchio.TouchIn(board.A0)
|
||||
touch1 = touchio.TouchIn(board.A1)
|
||||
touch2 = touchio.TouchIn(board.A2)
|
||||
|
||||
r = g = b = 0
|
||||
|
||||
def setPixel(red, green, blue):
|
||||
if not dotstar.try_lock():
|
||||
return
|
||||
print("setting pixel to: %d %d %d" % (red, green, blue))
|
||||
|
||||
data = bytearray([0x00, 0x00, 0x00, 0x00,
|
||||
0xff, blue, green, red,
|
||||
0xff, 0xff, 0xff, 0xff])
|
||||
dotstar.write(data)
|
||||
dotstar.unlock()
|
||||
time.sleep(0.01)
|
||||
|
||||
while True:
|
||||
if touch0.value:
|
||||
r = (r+1) % 256
|
||||
if touch1.value:
|
||||
g = (g+1) % 256
|
||||
if touch2.value:
|
||||
b = (b+1) % 256
|
||||
|
||||
setPixel(r, g, b)
|
||||
23
Introducing_Gemma_M0/Gemma_UART.py
Normal file
23
Introducing_Gemma_M0/Gemma_UART.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Gemma IO demo - USB/Serial echo
|
||||
|
||||
from digitalio import *
|
||||
from board import *
|
||||
import busio
|
||||
import time
|
||||
|
||||
led = DigitalInOut(D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
|
||||
uart = busio.UART(D0, D2, baudrate=9600)
|
||||
|
||||
while True:
|
||||
data = uart.read(32) # read up to 32 bytes
|
||||
#print(data) # this is a bytearray type
|
||||
|
||||
if data != None:
|
||||
led.value = True
|
||||
|
||||
datastr = ''.join([chr(b) for b in data]) # convert bytearray to string
|
||||
print(datastr, end="")
|
||||
|
||||
led.value = False
|
||||
Loading…
Reference in a new issue