-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeathers3.py
More file actions
executable file
·73 lines (57 loc) · 2.08 KB
/
feathers3.py
File metadata and controls
executable file
·73 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#FeatherS3 Helper Library
# 2022 Seon Rozenblum, Unexpected Maker
#
# Project home:
# https://feathers3.io
#
# Import required libraries
import time
import board
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn
# Init Blink LED
led13 = DigitalInOut(board.LED)
led13.direction = Direction.OUTPUT
# Init LDO2 Pin
ldo2 = DigitalInOut(board.LDO2)
ldo2.direction = Direction.OUTPUT
# Setup the BATTERY voltage sense pin
vbat_voltage = AnalogIn(board.BATTERY)
# Setup the VBUS sense pin
vbus_sense = DigitalInOut(board.VBUS_SENSE)
vbus_sense.direction = Direction.INPUT
# Helper functions
def led_blink():
"""Set the internal LED IO13 to it's inverse state"""
led13.value = not led13.value
def led_set( state ):
"""Set the internal LED IO13 to this state"""
led13.value = state
def set_ldo2_power(state):
"""Enable or Disable power to the onboard NeoPixel to either show colour, or to reduce power fro deep sleep."""
global ldo2
ldo2.value = state
def get_battery_voltage():
"""Get the approximate battery voltage."""
# I don't really understand what CP is doing under the hood here for the ADC range & calibration,
# but the onboard voltage divider for VBAT sense is setup to deliver 1.1V to the ADC based on it's
# default factory configuration.
# This forumla should show the nominal 4.2V max capacity (approximately) when 5V is present and the
# VBAT is in charge state for a 1S LiPo battery with a max capacity of 4.2V
global vbat_voltage
return (vbat_voltage.value / 5371)
def get_vbus_present():
"""Detect if VBUS (5V) power source is present"""
global vbus_sense
return vbus_sense.value
def rgb_color_wheel(wheel_pos):
"""Color wheel to allow for cycling through the rainbow of RGB colors."""
wheel_pos = wheel_pos % 255
if wheel_pos < 85:
return 255 - wheel_pos * 3, 0, wheel_pos * 3
elif wheel_pos < 170:
wheel_pos -= 85
return 0, wheel_pos * 3, 255 - wheel_pos * 3
else:
wheel_pos -= 170
return wheel_pos * 3, 255 - wheel_pos * 3, 0