This commit is contained in:
benjamyn committed 2022-02-06 20:59:59 +11:00
1 parent ed2eac73f2
commit bda248ccf7
17 files changed
+154

No files matched your search

View File
Whitespace-only changes.
+65
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
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
View File
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+23
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