Skip to content

Commit a4d7e1a

Browse files
committed
Clone Introducing Gemma to Gemma/
For guide changes
1 parent 872402c commit a4d7e1a

File tree

19 files changed

+484
-0
lines changed

19 files changed

+484
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Gemma IO demo - analog inputs
6+
7+
import time
8+
9+
import board
10+
from analogio import AnalogIn
11+
from digitalio import DigitalInOut, Direction
12+
13+
led = DigitalInOut(board.L)
14+
led.direction = Direction.OUTPUT
15+
16+
analog0in = AnalogIn(board.A0)
17+
analog1in = AnalogIn(board.A1)
18+
analog2in = AnalogIn(board.A2)
19+
20+
21+
def getVoltage(pin):
22+
return (pin.value * 3.3) / 65536
23+
24+
25+
while True:
26+
print("A0: %f \t\t A1: %f \t\t A2: %f" %
27+
(getVoltage(analog0in),
28+
getVoltage(analog1in),
29+
getVoltage(analog2in)))
30+
31+
time.sleep(0.1)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# CircuitPython IO demo - analog output
6+
7+
import board
8+
from analogio import AnalogOut
9+
10+
aout = AnalogOut(board.A0)
11+
12+
while True:
13+
# Count up from 0 to 65535, with 64 increment
14+
# which ends up corresponding to the DAC's 10-bit range
15+
for i in range(0, 65535, 64):
16+
aout.value = i
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Gemma IO demo - captouch
6+
7+
import time
8+
9+
import board
10+
import touchio
11+
12+
touch0 = touchio.TouchIn(board.A0)
13+
touch1 = touchio.TouchIn(board.A1)
14+
touch2 = touchio.TouchIn(board.A2)
15+
16+
while True:
17+
if touch0.value:
18+
print("A0 touched!")
19+
if touch1.value:
20+
print("A1 touched!")
21+
if touch2.value:
22+
print("A2 touched!")
23+
time.sleep(0.01)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# CircuitPython IO demo #1 - General Purpose I/O
6+
7+
import time
8+
9+
import board
10+
from digitalio import DigitalInOut, Direction, Pull
11+
12+
led = DigitalInOut(board.D13)
13+
led.direction = Direction.OUTPUT
14+
15+
button = DigitalInOut(board.D2)
16+
button.direction = Direction.INPUT
17+
button.pull = Pull.UP
18+
19+
while True:
20+
# we could also just do "led.value = not button.value" !
21+
if button.value:
22+
led.value = False
23+
else:
24+
led.value = True
25+
26+
time.sleep(0.01) # debounce delay
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# CircuitPython demo - Dotstar
6+
7+
import time
8+
from rainbowio import colorwheel
9+
import adafruit_dotstar
10+
import board
11+
12+
numpix = 64
13+
strip = adafruit_dotstar.DotStar(board.D2, board.D0, numpix, brightness=0.2)
14+
15+
16+
def rainbow_cycle(wait):
17+
for j in range(255):
18+
for i in range(len(strip)):
19+
idx = int((i * 256 / len(strip)) + j)
20+
strip[i] = colorwheel(idx & 255)
21+
strip.show()
22+
time.sleep(wait)
23+
24+
25+
while True:
26+
strip.fill((255, 0, 0))
27+
strip.show()
28+
time.sleep(1)
29+
30+
strip.fill((0, 255, 0))
31+
strip.show()
32+
time.sleep(1)
33+
34+
strip.fill((0, 0, 255))
35+
strip.show()
36+
time.sleep(1)
37+
38+
rainbow_cycle(0.001) # high speed rainbow cycle w/1ms delay per sweep
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# CircuitPlayground demo - Keyboard emu
6+
7+
import time
8+
9+
import board
10+
import usb_hid
11+
from adafruit_hid.keyboard import Keyboard
12+
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
13+
from adafruit_hid.keycode import Keycode
14+
from digitalio import DigitalInOut, Direction, Pull
15+
16+
# A simple neat keyboard demo in circuitpython
17+
18+
# The button pins we'll use, each will have an internal pullup
19+
buttonpins = [board.D2, board.D1, board.D0]
20+
# our array of button objects
21+
buttons = []
22+
# The keycode sent for each button, will be paired with a control key
23+
buttonkeys = [Keycode.A, Keycode.B, "Hello World!\n"]
24+
controlkey = Keycode.SHIFT
25+
26+
# the keyboard object!
27+
# sleep for a bit to avoid a race condition on some systems
28+
time.sleep(1)
29+
kbd = Keyboard(usb_hid.devices)
30+
# we're americans :)
31+
layout = KeyboardLayoutUS(kbd)
32+
33+
# make all pin objects, make them inputs w/pullups
34+
for pin in buttonpins:
35+
button = DigitalInOut(pin)
36+
button.direction = Direction.INPUT
37+
button.pull = Pull.UP
38+
buttons.append(button)
39+
40+
led = DigitalInOut(board.D13)
41+
led.direction = Direction.OUTPUT
42+
43+
print("Waiting for button presses")
44+
45+
while True:
46+
# check each button
47+
for button in buttons:
48+
if not button.value: # pressed?
49+
i = buttons.index(button)
50+
print("Button #%d Pressed" % i)
51+
52+
# turn on the LED
53+
led.value = True
54+
55+
while not button.value:
56+
pass # wait for it to be released!
57+
# type the keycode or string
58+
k = buttonkeys[i] # get the corresp. keycode/str
59+
if isinstance(k, str):
60+
layout.write(k)
61+
else:
62+
kbd.press(controlkey, k) # press...
63+
kbd.release_all() # release!
64+
65+
# turn off the LED
66+
led.value = False
67+
68+
time.sleep(0.01)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Gemma/Trinket IO demo - I2C scan
6+
7+
import time
8+
9+
import board
10+
import busio
11+
12+
# can also use board.SDA and board.SCL for neater looking code!
13+
i2c = busio.I2C(board.D2, board.D0)
14+
15+
while not i2c.try_lock():
16+
pass
17+
18+
while True:
19+
print("I2C addresses found:", [hex(i) for i in i2c.scan()])
20+
time.sleep(2)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# I2C sensor demo
6+
7+
import time
8+
9+
import adafruit_si7021
10+
import board
11+
import busio
12+
13+
i2c = busio.I2C(board.SCL, board.SDA)
14+
15+
# lock the I2C device before we try to scan
16+
while not i2c.try_lock():
17+
pass
18+
print("I2C addresses found:", [hex(i) for i in i2c.scan()])
19+
20+
# unlock I2C now that we're done scanning.
21+
i2c.unlock()
22+
23+
# Create library object on our I2C port
24+
si7021 = adafruit_si7021.SI7021(i2c)
25+
26+
# Use library to read the data!
27+
while True:
28+
print("Temp: %0.2F *C Humidity: %0.1F %%" %
29+
(si7021.temperature, si7021.relative_humidity))
30+
time.sleep(1)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
7+
import board
8+
import digitalio
9+
import microcontroller
10+
11+
led = digitalio.DigitalInOut(board.D13)
12+
led.switch_to_output()
13+
14+
try:
15+
with open("/temperature.txt", "a") as fp:
16+
while True:
17+
temp = microcontroller.cpu.temperature
18+
# do the C-to-F conversion here if you would like
19+
fp.write('{0:f}\n'.format(temp))
20+
fp.flush()
21+
led.value = not led.value
22+
time.sleep(1)
23+
except OSError as e:
24+
delay = 0.5
25+
if e.args[0] == 28:
26+
delay = 0.25
27+
while True:
28+
led.value = not led.value
29+
time.sleep(delay)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import board
6+
import digitalio
7+
import storage
8+
9+
switch = digitalio.DigitalInOut(board.D0)
10+
switch.direction = digitalio.Direction.INPUT
11+
switch.pull = digitalio.Pull.UP
12+
13+
# If the D0 is connected to ground with a wire
14+
# CircuitPython can write to the drive
15+
storage.remount("/", readonly=switch.value)

0 commit comments

Comments
 (0)