Skip to content

Commit 174ef61

Browse files
committed
Merge branch 'main' into brightness_crank
2 parents d00e7b6 + 3a5a4ac commit 174ef61

File tree

18 files changed

+771
-13
lines changed

18 files changed

+771
-13
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""CircuitPython I2C possible pin-pair identifying script"""
2+
import board
3+
import busio
4+
from microcontroller import Pin
5+
6+
7+
def is_hardware_i2c(scl, sda):
8+
try:
9+
p = busio.I2C(scl, sda)
10+
p.deinit()
11+
return True
12+
except ValueError:
13+
return False
14+
except RuntimeError:
15+
return True
16+
17+
18+
def get_unique_pins():
19+
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
20+
pins = [pin for pin in [
21+
getattr(board, p) for p in dir(board) if p not in exclude]
22+
if isinstance(pin, Pin)]
23+
unique = []
24+
for p in pins:
25+
if p not in unique:
26+
unique.append(p)
27+
return unique
28+
29+
30+
for scl_pin in get_unique_pins():
31+
for sda_pin in get_unique_pins():
32+
if scl_pin is sda_pin:
33+
continue
34+
if is_hardware_i2c(scl_pin, sda_pin):
35+
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""CircuitPython I2C MCP9808 Temperature Sensor Example"""
2+
import time
3+
import board
4+
import adafruit_mcp9808
5+
6+
i2c = board.I2C() # uses board.SCL and board.SDA
7+
mcp9808 = adafruit_mcp9808.MCP9808(i2c)
8+
9+
while True:
10+
temperature_celsius = mcp9808.temperature
11+
temperature_fahrenheit = temperature_celsius * 9 / 5 + 32
12+
print("Temperature: {:.2f} C {:.2f} F ".format(temperature_celsius, temperature_fahrenheit))
13+
time.sleep(2)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""CircuitPython I2C Device Address Scan"""
2+
import time
3+
import board
4+
5+
i2c = board.I2C()
6+
7+
while not i2c.try_lock():
8+
pass
9+
10+
try:
11+
while True:
12+
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()])
13+
time.sleep(2)
14+
15+
finally: # unlock the i2c bus when ctrl-c'ing out of the loop
16+
i2c.unlock()

Flora_NeoGeo_Watch/Flora_NeoGeo_Watch/Flora_NeoGeo_Watch.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <Adafruit_GPS.h>
1414
#include <Adafruit_NeoPixel.h>
1515
#include <SoftwareSerial.h>
16-
#include <Time.h>
16+
#include <TimeLib.h>
1717
#include <Wire.h>
1818
#include <Adafruit_Sensor.h>
1919
#include <Adafruit_LSM303DLH_Mag.h>

FunHouse_HA_Companion/code.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
funhouse = FunHouse(default_bg=0x0F0F00)
2626
funhouse.peripherals.dotstars.fill(INITIAL_LIGHT_COLOR)
2727

28+
# Don't display the splash yet to avoid
29+
# redrawing labels after each one is added
2830
funhouse.display.show(None)
31+
32+
# Add the labels
2933
funhouse.add_text(
3034
text="Temperature:",
3135
text_position=(20, 30),
@@ -62,12 +66,13 @@
6266
text_color=0xFFFF00,
6367
text_font="fonts/Arial-Bold-24.pcf",
6468
)
69+
70+
# Now display the splash to draw all labels at once
6571
funhouse.display.show(funhouse.splash)
6672

6773
status = Circle(229, 10, 10, fill=0xFF0000, outline=0x880000)
6874
funhouse.splash.append(status)
6975

70-
7176
def update_enviro():
7277
global environment
7378

Kitty_Paw_Keypad/code.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import board
2+
import displayio
3+
import digitalio
4+
from adafruit_st7789 import ST7789
5+
import usb_hid
6+
from adafruit_hid.keyboard import Keyboard
7+
from adafruit_hid.keycode import Keycode
8+
import usb_midi
9+
import adafruit_midi
10+
from adafruit_midi.note_on import NoteOn
11+
from adafruit_midi.note_off import NoteOff
12+
13+
# if you want to use this as an HID keyboard, set keyboard_mode to True
14+
# otherwise, set it to False
15+
keyboard_mode = True
16+
# if you want to use this as a MIDI keyboard, set midi_mode to True
17+
# otherwise, set it to False
18+
midi_mode = False
19+
20+
# change keyboard shortcuts here
21+
# defaults are shortcuts for save, cut, copy & paste
22+
# comment out ctrl depending on windows or macOS
23+
if keyboard_mode:
24+
keyboard = Keyboard(usb_hid.devices)
25+
# modifier for windows
26+
ctrl = Keycode.CONTROL
27+
# modifier for macOS
28+
# ctrl = Keycode.COMMAND
29+
key0 = Keycode.S
30+
key1 = Keycode.X
31+
key2 = Keycode.C
32+
key3 = Keycode.V
33+
shortcuts = [key0, key1, key2, key3]
34+
35+
# change MIDI note numbers here
36+
if midi_mode:
37+
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
38+
midi_notes = [60, 61, 62, 63]
39+
40+
# Release any resources currently in use for the displays
41+
displayio.release_displays()
42+
43+
# spi display setup
44+
spi = board.SPI()
45+
tft_cs = board.D7
46+
tft_dc = board.D5
47+
48+
display_bus = displayio.FourWire(
49+
spi, command=tft_dc, chip_select=tft_cs, reset=board.D6
50+
)
51+
52+
# display setup
53+
display = ST7789(display_bus, width=240, height=240, rowstart=80)
54+
55+
# bitmap setup
56+
bitmap = displayio.OnDiskBitmap(open("/parrot-240-sheet.bmp", "rb"))
57+
58+
# Create a TileGrid to hold the bitmap
59+
parrot0_grid = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter(),
60+
width=1, height=1,
61+
tile_height=240, tile_width=240,
62+
default_tile=0,
63+
x=0, y=0)
64+
65+
# Create a Group to hold the TileGrid
66+
group = displayio.Group()
67+
68+
# Add the TileGrid to the Group
69+
group.append(parrot0_grid)
70+
71+
# Add the Group to the Display
72+
display.show(group)
73+
74+
# digital pins for the buttons
75+
key_pins = [board.A0, board.A1, board.A2, board.A3]
76+
77+
# array for buttons
78+
keys = []
79+
80+
# setup buttons as inputs
81+
for key in key_pins:
82+
key_pin = digitalio.DigitalInOut(key)
83+
key_pin.direction = digitalio.Direction.INPUT
84+
key_pin.pull = digitalio.Pull.UP
85+
keys.append(key_pin)
86+
87+
p = 0 # variable for tilegrid index
88+
a = 0 # variable for tile position
89+
90+
# states for buttons
91+
key0_pressed = False
92+
key1_pressed = False
93+
key2_pressed = False
94+
key3_pressed = False
95+
96+
# array for button states
97+
key_states = [key0_pressed, key1_pressed, key2_pressed, key3_pressed]
98+
99+
while True:
100+
# default tile grid position
101+
parrot0_grid[a] = p
102+
103+
# iterate through 4 buttons
104+
for i in range(4):
105+
inputs = keys[i]
106+
# if button is pressed...
107+
if not inputs.value and key_states[i] is False:
108+
# tile grid advances by 1 frame
109+
p += 1
110+
# update button state
111+
key_states[i] = True
112+
# if a midi keyboard...
113+
if midi_mode:
114+
# send NoteOn for corresponding MIDI note
115+
midi.send(NoteOn(midi_notes[i], 120))
116+
# if an HID keyboard...
117+
if keyboard_mode:
118+
# send keyboard output for corresponding keycode
119+
# the default includes a modifier along with the keycode
120+
keyboard.send(ctrl, shortcuts[i])
121+
# if the tile grid's index is at 9...
122+
if p > 9:
123+
# reset the index to 0
124+
p = 0
125+
# if the button is released...
126+
if inputs.value and key_states[i] is True:
127+
# update button state
128+
key_states[i] = False
129+
# if a midi keyboard...
130+
if midi_mode:
131+
# send NoteOff for corresponding MIDI note
132+
midi.send(NoteOff(midi_notes[i], 120))

Kitty_Paw_Keypad/parrot-240-sheet.bmp

563 KB
Binary file not shown.

0 commit comments

Comments
 (0)