Debian Codegraph @

ports/esp32/boards/UM_NANOS3/modules/nanos3.py

raw
1 # NanoS3 Helper Library
2 # MIT license; Copyright (c) 2023 Seon Rozenblum - Unexpected Maker
3 #
4 # Project home:
5 # https://nanos3.io
6
7 # Import required libraries
8 from micropython import const
9 from machine import Pin, ADC
10 import time
11
12 # TinyS3 Hardware Pin Assignments
13
14 # RGB LED Pins
15 RGB_DATA = const(41)
16 RGB_PWR = const(42)
17
18 # SPI
19 SPI_MOSI = const(35)
20 SPI_MISO = const(37)
21 SPI_CLK = const(36)
22
23 # I2C
24 I2C_SDA = const(8)
25 I2C_SCL = const(9)
26
27
28 # Helper functions
29 def set_pixel_power(state):
30 """Enable or Disable power to the onboard NeoPixel to either show colour, or to reduce power for deep sleep."""
31 Pin(RGB_PWR, Pin.OUT).value(state)
32
33
34 # NeoPixel rainbow colour wheel
35 def rgb_color_wheel(wheel_pos):
36 """Color wheel to allow for cycling through the rainbow of RGB colors."""
37 wheel_pos = wheel_pos % 255
38
39 if wheel_pos < 85:
40 return 255 - wheel_pos * 3, 0, wheel_pos * 3
41 elif wheel_pos < 170:
42 wheel_pos -= 85
43 return 0, wheel_pos * 3, 255 - wheel_pos * 3
44 else:
45 wheel_pos -= 170
46 return wheel_pos * 3, 255 - wheel_pos * 3, 0