This commit is contained in:
Benjamyn Love 2022-02-06 20:59:59 +11:00
parent ed2eac73f2
commit bda248ccf7
17 changed files with 154 additions and 0 deletions

0
.vscode/launch.json vendored Normal file
View File

65
backup.py Normal file
View File

@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: Unlicense
"""CircuitPython I2C Device Address Scan"""
import board
import adafruit_ssd1306
import neopixel
import rotaryio
import busio
import digitalio
import time
# Setup the i2c bus
i2c = busio.I2C(board.A3, board.A2)
# Get the oled
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Setup the NeoPixel
neopixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
# Setup the encoder
enc = rotaryio.IncrementalEncoder(board.D5, board.D4)
# Setup the encoder button
enc_btn = digitalio.DigitalInOut(board.D3)
enc_btn.direction = digitalio.Direction.INPUT
# Start the main loop
last_position = None
colour = [0,0,0]
menu_item = 0
sub_menu = False
while True:
if menu_item == 0:
menu = "[R] G B"
if menu_item == 1:
menu = "R [G] B"
if menu_item == 2:
menu = "R G [B]"
oled.fill(0)
oled.text(menu, 0, 0, 1)
current_value = neopixel[0]
oled.text(f"{current_value[0]}:{current_value[1]}:{current_value[2]}", 0, 10, 1)
position = enc.position
if last_position == None or position != last_position:
print(position)
last_position = position
if not enc_btn.value:
sub_menu = not sub_menu
enc.position = 0
if not sub_menu:
menu_item = position % 3
else:
colour[menu_item] = position
if enc.position < 0:
position = 0
enc.position = 0
if enc.position > 255:
position = 255
enc.position = 255
neopixel.fill((colour[0],colour[1],colour[2]))
# oled.text(f'Position: {position}', 0, 0, 1)
oled.show()

66
code.py Normal file
View File

@ -0,0 +1,66 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: Unlicense
"""CircuitPython I2C Device Address Scan"""
import board
import adafruit_ssd1306
import neopixel
import rotaryio
import busio
import digitalio
import time
# Setup the i2c bus
i2c = busio.I2C(board.A3, board.A2)
# Get the oled
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Setup the NeoPixel
neopixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
# Setup the encoder
enc = rotaryio.IncrementalEncoder(board.D5, board.D4)
# Setup the encoder button
enc_btn = digitalio.DigitalInOut(board.D3)
enc_btn.direction = digitalio.Direction.INPUT
# Start the main loop
last_position = None
colour = [0,0,0]
menu_item = 0
sub_menu = False
while True:
if menu_item == 0:
menu = "[R] G B"
if menu_item == 1:
menu = "R [G] B"
if menu_item == 2:
menu = "R G [B]"
oled.fill(0)
oled.text(menu, 0, 0, 1)
current_value = neopixel[0]
oled.text(f"{current_value[0]}:{current_value[1]}:{current_value[2]}", 0, 10, 1)
position = enc.position
if last_position == None or position != last_position:
print(position)
last_position = position
if not enc_btn.value:
sub_menu = not sub_menu
enc.position = 0
time.sleep(0.1)
if not sub_menu:
menu_item = position % 3
else:
colour[menu_item] = position
if enc.position < 0:
position = 0
enc.position = 0
if enc.position > 255:
position = 255
enc.position = 255
neopixel.fill((colour[0],colour[1],colour[2]))
# oled.text(f'Position: {position}', 0, 0, 1)
oled.show()

BIN
font5x8.bin Normal file

Binary file not shown.

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/adafruit_framebuf.mpy Normal file

Binary file not shown.

BIN
lib/adafruit_ssd1306.mpy Normal file

Binary file not shown.

BIN
lib/bitmap_font.mpy Normal file

Binary file not shown.

BIN
lib/font5x8.bin Normal file

Binary file not shown.

BIN
lib/neopixel.mpy Normal file

Binary file not shown.

23
upload.sh Normal file
View File

@ -0,0 +1,23 @@
#!/bin/bash
echo "Mounting the disk"
# mount the disk
diskpath=$(udisksctl mount -b /dev/disk/by-label/CIRCUITPY)
echo "Disk mounted"
# Change to the mounted folder
cd $(echo $diskpath | awk '{print $4}')
echo "Backing up code to ~/Documents/Projects/light_control/backup.py"
# Backing up code
cp code.py ~/Documents/Projects/light_control/backup.py
echo "Replacing code"
# Replacing code
cp -f ~/Documents/Projects/light_control/code.py code.py
echo "Code uploaded, unmounting circuitpy"
sync
cd ~
udisksctl unmount -b /dev/disk/by-label/CIRCUITPY