initial
This commit is contained in:
parent
ed2eac73f2
commit
bda248ccf7
0
.vscode/launch.json
vendored
Normal file
0
.vscode/launch.json
vendored
Normal file
65
backup.py
Normal file
65
backup.py
Normal 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
66
code.py
Normal 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
BIN
font5x8.bin
Normal file
Binary file not shown.
0
lib/adafruit_bitmap_font/__init__.py
Normal file
0
lib/adafruit_bitmap_font/__init__.py
Normal file
BIN
lib/adafruit_bitmap_font/bdf.mpy
Normal file
BIN
lib/adafruit_bitmap_font/bdf.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_bitmap_font/bitmap_font.mpy
Normal file
BIN
lib/adafruit_bitmap_font/bitmap_font.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_bitmap_font/glyph_cache.mpy
Normal file
BIN
lib/adafruit_bitmap_font/glyph_cache.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_bitmap_font/pcf.mpy
Normal file
BIN
lib/adafruit_bitmap_font/pcf.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_bitmap_font/ttf.mpy
Normal file
BIN
lib/adafruit_bitmap_font/ttf.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_displayio_ssd1306.mpy
Normal file
BIN
lib/adafruit_displayio_ssd1306.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_framebuf.mpy
Normal file
BIN
lib/adafruit_framebuf.mpy
Normal file
Binary file not shown.
BIN
lib/adafruit_ssd1306.mpy
Normal file
BIN
lib/adafruit_ssd1306.mpy
Normal file
Binary file not shown.
BIN
lib/bitmap_font.mpy
Normal file
BIN
lib/bitmap_font.mpy
Normal file
Binary file not shown.
BIN
lib/font5x8.bin
Normal file
BIN
lib/font5x8.bin
Normal file
Binary file not shown.
BIN
lib/neopixel.mpy
Normal file
BIN
lib/neopixel.mpy
Normal file
Binary file not shown.
23
upload.sh
Normal file
23
upload.sh
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user