def _setup_wifi(self): esp32_cs = DigitalInOut(board.D13) esp32_reset = DigitalInOut(board.D12) esp32_ready = DigitalInOut(board.D11) esp32_gpio0 = DigitalInOut(board.D10) spi = board.SPI() self.esp = adafruit_esp32spi.ESP_SPIcontrol( spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0 ) # self._esp._debug = 1 for _ in range(3): # retries try: self.logger.info("ESP firmware: " + ''.join([chr(b) for b in self.esp.firmware_version])) break except RuntimeError: self.logger.warning("Retrying ESP32 connection") time.sleep(1) self.esp.reset() else: self.logger.error("Was not able to find ESP32") return if self.debug: while not self.esp.is_connected: try: self.esp.connect(secrets) self.logger.debug("IP address is {0}".format(self.esp.pretty_ip(self.esp.ip_address))) except RuntimeError as error: self.logger.error("Could not connect to internet. {0}".format(error)) RED_LED = PWMOut.PWMOut(self.esp, 26) GREEN_LED = PWMOut.PWMOut(self.esp, 27) BLUE_LED = PWMOut.PWMOut(self.esp, 25) status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) self.wifi = ESPSPI_WiFiManager(self.esp, secrets, status_light) #, debug=True) self.wifi.connect() self.get_local_time() # MQTT.set_socket(socket, self.esp) # self.mqtt_client = MQTT.MQTT(broker=secrets['broker'], # username=secrets['user'], # password=secrets['pass'], # is_ssl=False) if self.debug: self.mqtt_client.set_logger_level("DEBUG")
import time import board import adafruit_rgbled # Pin the Red LED is connected to RED_LED = board.D5 # Pin the Green LED is connected to GREEN_LED = board.D6 # Pin the Blue LED is connected to BLUE_LED = board.D7 # Create the RGB LED object led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED) # Optionally, you can also create the RGB LED object with inverted PWM # led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True) def wheel(pos): # Input a value 0 to 255 to get a color value. # The colours are a transition r - g - b - back to r. if pos < 0 or pos > 255: return 0, 0, 0 if pos < 85: return int(255 - pos * 3), int(pos * 3), 0 if pos < 170: pos -= 85 return 0, int(255 - pos * 3), int(pos * 3) pos -= 170
import busio import adafruit_pca9685 import adafruit_rgbled # PCA9685 Initialization i2c = busio.I2C(board.SCL, board.SDA) pca = adafruit_pca9685.PCA9685(i2c) pca.frequency = 60 # PCA9685 LED Channels RED_LED = pca.channels[0] GREEN_LED = pca.channels[1] BLUE_LED = pca.channels[2] # Create the RGB LED object led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True) # Optionally, you can also create the RGB LED object with inverted PWM # led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True) def wheel(pos): # Input a value 0 to 255 to get a color value. # The colours are a transition r - g - b - back to r. if pos < 0 or pos > 255: return 0, 0, 0 if pos < 85: return int(255 - pos * 3), int(pos * 3), 0 if pos < 170: pos -= 85 return 0, int(255 - pos * 3), int(pos * 3)
AUDIO_PIN = board.A0 RED_PIN = board.D11 GREEN_PIN = board.D12 BLUE_PIN = board.D13 POTENTIOMETER_PIN = board.A2 #High power mode enable = DigitalInOut(POWER_PIN) enable.direction = Direction.OUTPUT enable.value = False #Audio audio = audioio.AudioOut(AUDIO_PIN) #LED LED = adafruit_rgbled.RGBLED(RED_PIN, GREEN_PIN, BLUE_PIN) #Potentiometer potentiometer = AnalogIn(POTENTIOMETER_PIN) #Switch switch = DigitalInOut(SWITCH_PIN) switch.direction = Direction.INPUT switch.pull = Pull.UP # Set up accelerometer on I2C bus, 4G range: i2c = busio.I2C(board.SCL, board.SDA) accel = adafruit_lis3dh.LIS3DH_I2C(i2c) accel.range = adafruit_lis3dh.RANGE_4_G
import usb_midi import adafruit_midi from adafruit_midi.note_on import NoteOn from adafruit_midi.note_off import NoteOff from simpleio import map_range from analogio import AnalogIn from digitalio import DigitalInOut, Direction from adafruit_midi.control_change import ControlChange import math import adafruit_rgbled #setup analog joystick and slider inputs xAxis = AnalogIn(board.A1) yAxis = AnalogIn(board.A0) sAxis = AnalogIn(board.A2) led = adafruit_rgbled.RGBLED(board.GP0, board.GP1, board.GP2) ledw = digitalio.DigitalInOut(board.GP3) ledw.direction = digitalio.Direction.OUTPUT note_states = [ False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False ] # note states midi_notes = [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51] # array of default MIDI notes ledcolor = [[255, 0, 0], [255, 80, 0], [255, 255, 0], [0, 255, 0], [0, 0, 255], [0, 100, 255], [100, 0, 255], [255, 255, 255]] ledwcolor = [[255, 0, 0], [255, 80, 0], [255, 255, 0], [0, 255, 0], [0, 0, 255], [0, 100, 255], [100, 0, 255], [255, 255, 255], [255, 0, 0], [255, 80, 0], [255, 255, 0], [0, 255, 0], [0, 0, 255],
auto_write=True) button_boot = digitalio.DigitalInOut(board.USER_SW) button_boot.direction = digitalio.Direction.INPUT button_boot.pull = digitalio.Pull.UP button_a = digitalio.DigitalInOut(board.SW_A) button_a.direction = digitalio.Direction.INPUT button_a.pull = digitalio.Pull.UP button_b = digitalio.DigitalInOut(board.SW_B) button_b.direction = digitalio.Direction.INPUT button_b.pull = digitalio.Pull.UP led = adafruit_rgbled.RGBLED(board.LED_R, board.LED_G, board.LED_B, invert_pwm=True) def button_read(button): return not button.value while True: if button_read(button_a): led_strip.fill((255, 0, 0)) led.color = (255, 0, 0) if button_read(button_b): led_strip.fill((0, 255, 0)) led.color = (0, 255, 0) if button_read(button_boot):
def replace(tup, x, y): tup_list = list(tup) for element in tup_list: if element == x: tup_list[tup_list.index(element)] = y new_tuple = tuple(tup_list) return new_tuple ##################### # initializations # ##################### # dotstar and rgbled brddot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1) rgbled = adafruit_rgbled.RGBLED(pwm2, pwm4, pwm3, invert_pwm=True) # lets default to solid mode, 'pulse' is the alternative mode = "solid" # first pass at luminosity, and initialize the oldluminosity var luminosity, pulseTimeout = setLuminosity() oldluminosity = luminosity # default to a yellow to indicate we haven't received anything from the server color = (0, 0, luminosity) colorName = 'blue' setColor(color) ################## # run the loop #
esp32_cs = DigitalInOut(board.D13) esp32_ready = DigitalInOut(board.D11) esp32_reset = DigitalInOut(board.D12) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" #status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" #status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) """Uncomment for externally defined RGB LED""" import adafruit_rgbled from adafruit_esp32spi import PWMOut RED_LED = PWMOut.PWMOut(esp, 26) GREEN_LED = PWMOut.PWMOut(esp, 27) BLUE_LED = PWMOut.PWMOut(esp, 25) status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) ### This code for controling the LED on the airlift is borrowed from: ### https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/master/examples/esp32spi_aio_post.py ### And it was added by https://github.com/brentru wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( esp, secrets, status_light) # neopixels ### Internally to the PyGamer there are 5 Neopixel connected to D8 ### ( https://learn.adafruit.com/adafruit-pygamer/pinouts ) ### But to access the NEOPIXEL I need that wifimanager use another LED status pixels = neopixel.NeoPixel(board.NEOPIXEL, 5, brightness=0.3) pixels.fill(0) # we'll save the value in question
esp32_reset = DigitalInOut(board.D12) esp32_ready = DigitalInOut(board.D11) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) esp32_cs.value = True time.sleep(5) print("WiFi Powerd UP") RED_LED = PWMOut.PWMOut(esp, 26) GREEN_LED = PWMOut.PWMOut(esp, 27) BLUE_LED = PWMOut.PWMOut(esp, 25) airlift_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, dot) # Setup Sensor i2c = board.I2C() sensor = adafruit_sht31d.SHT31D(i2c) sensor.frequency = adafruit_sht31d.FREQUENCY_1 sensor.mode = adafruit_sht31d.MODE_PERIODIC sensor.heater = True time.sleep(1) sensor.heater = False print("Sensor Heater OK") # Setup Adafruit IO