diff --git a/backup.py b/backup.py index 0cc1a9f..b3f086a 100644 --- a/backup.py +++ b/backup.py @@ -28,9 +28,71 @@ enc_btn.direction = digitalio.Direction.INPUT # Start the main loop last_position = None -colour = [0,0,0] +colour = [128,128,32] 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]" + # Get neopixel colour value + current_r, current_g, current_b = neopixel[0] + + # Init the oled + oled.fill(0) + + # Draw the menu + oled.text(menu, 0, 0, 1) + oled.text(f"{current_r}:{current_g}:{current_b}", 0, 10, 1) + + # Show the oled + oled.show() + if last_position is not None: + # If we went right + if enc.position > last_position: + # Check if we are in the sub_menu + if not sub_menu: + if not (menu_item + 1) > 3: + menu_item += 1 + else: + if menu_item == 0: + if not (current_r + 1) > 255: + current_r += 1 + elif menu_item == 1: + if not (current_g + 1) > 255: + current_g += 1 + elif menu_item == 2: + if not (current_b + 1) > 255: + current_b += 1 + + # If we went left + elif enc.position < last_position: + # Check if we are in the sub_menu + if not sub_menu: + if not (menu_item - 1) < 0: + menu_item -= 1 + else: + if menu_item == 0: + if not (current_r - 1) < 0: + current_r -= 1 + elif menu_item == 1: + if not (current_g - 1) < 0: + current_g -= 1 + elif menu_item == 2: + if not (current_b - 1) < 0: + current_b -= 1 + + if not enc_btn.value: + sub_menu = not sub_menu + time.sleep(0.1) + + neopixel.fill((current_r, current_g, current_b)) + last_position = enc.position + while True: if menu_item == 0: menu = "[R] G B" @@ -49,6 +111,7 @@ while True: 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: diff --git a/code.py b/code.py index be2a45c..fb0e769 100644 --- a/code.py +++ b/code.py @@ -31,6 +31,7 @@ last_position = None colour = [128,128,32] menu_item = 0 sub_menu = False + while True: if menu_item == 0: menu = "[R] G B" @@ -38,29 +39,57 @@ while True: menu = "R [G] B" if menu_item == 2: menu = "R G [B]" + # Get neopixel colour value + current_r, current_g, current_b = neopixel[0] + + # Init the oled oled.fill(0) + + # Draw the menu 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.text("*" if sub_menu else " ", 64, 0, 1) + oled.text(f"{current_r}:{current_g}:{current_b}", 0, 10, 1) + + # Show the oled oled.show() + if last_position is not None: + # If we went right + if enc.position > last_position: + # Check if we are in the sub_menu + if not sub_menu: + if not (menu_item + 1) > 3: + menu_item += 1 + else: + if menu_item == 0: + if not (current_r + 1) > 255: + current_r += 1 + elif menu_item == 1: + if not (current_g + 1) > 255: + current_g += 1 + elif menu_item == 2: + if not (current_b + 1) > 255: + current_b += 1 + + # If we went left + elif enc.position < last_position: + # Check if we are in the sub_menu + if not sub_menu: + if not (menu_item - 1) < 0: + menu_item -= 1 + else: + if menu_item == 0: + if not (current_r - 1) < 0: + current_r -= 1 + elif menu_item == 1: + if not (current_g - 1) < 0: + current_g -= 1 + elif menu_item == 2: + if not (current_b - 1) < 0: + current_b -= 1 + + if not enc_btn.value: + sub_menu = not sub_menu + time.sleep(0.1) + + neopixel.fill((current_r, current_g, current_b)) + last_position = enc.position