# 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()