update LED driver

This commit is contained in:
Mitchell Marino 2025-03-26 17:13:30 -05:00
parent 51001d6bc4
commit 7cdddb2c83
11 changed files with 153 additions and 107 deletions

View File

@ -1,21 +1,14 @@
#ifndef ALL_H #ifndef ALL_H
#define ALL_H #define ALL_H
// #include "driver/uart.h"
// #include "driver/i2c.h"
// #include "drivers/tft.h"
// #include "drivers/wires.h"
// #include "drivers/sd.h"
// #include "drivers/char_lcd.h"
// #include "drivers/leds.h"
// #include "drivers/power.h"
#include "char_lcd.h" #include "char_lcd.h"
#include "bottom_half.h" #include "bottom_half.h"
#include "sd.h" #include "sd.h"
#include "speaker.h" #include "speaker.h"
#include "game_timer.h" #include "game_timer.h"
#include "drivers/tft.h"
#include "drivers/leds.h"
#include "drivers/power.h"
void init_drivers(); void init_drivers();

View File

@ -1,4 +1,6 @@
#include "leds.h" #include "leds.h"
#include "led_strip.h"
#include <esp_log.h>
static const char* TAG = "leds"; static const char* TAG = "leds";
@ -25,8 +27,12 @@ void init_leds() {
ESP_LOGI(TAG, "LEDs initialized!"); ESP_LOGI(TAG, "LEDs initialized!");
} }
void leds_set(IndicatorLED led, uint8_t r, uint8_t g, uint8_t b) { void led_set(uint32_t led, uint8_t r, uint8_t g, uint8_t b) {
led_strip_set_pixel(leds, i, i, LED_COUNT-i, 0) led_strip_set_pixel(leds, led, r, g, b);
}
void led_set(uint32_t led, uint32_t color) {
led_set(led, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
} }
void leds_flush() { void leds_flush() {

View File

@ -1,36 +1,55 @@
#ifndef LEDS_H #ifndef LEDS_H
#define LEDS_H #define LEDS_H
#include "led_strip.h" #include <stdint.h>
#define LED_COUNT 21 #define LED_COUNT 21
#define NEOPIXEL_PIN GPIO_NUM_7 #define NEOPIXEL_PIN GPIO_NUM_7
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000) #define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
typedef enum { enum LEDColor: uint32_t {
led_shape1 = 0, LED_COLOR_OFF = 0x00'00'00,
led_shape2 = 1, LED_COLOR_RED = 0x17'00'00,
led_shape3 = 2, LED_COLOR_RED_STRONG = 0xFF'00'00,
led_shape4 = 3, LED_COLOR_ORANGE = 0x17'02'00,
led_module_sseg = 4, LED_COLOR_ORANGE_STRONG = 0xFF'20'00,
led_game_sseg = 5, LED_COLOR_YELLOW = 0x07'07'00,
led_tft = 6, LED_COLOR_YELLOW_STRONG = 0xFF'FF'00,
led_mic = 7, LED_COLOR_GREEN = 0x00'07'00,
led_ir_led = 8, LED_COLOR_GREEN_STRONG = 0x00'FF'00,
led_speaker = 9, LED_COLOR_BLUE = 0x00'00'17,
led_rfid = 10, LED_COLOR_BLUE_STRONG = 0x00'00'FF,
led_keypad = 11, LED_COLOR_PINK = 0x10'00'04,
led_char_lcd = 12, LED_COLOR_PINK_STRONG = 0xFF'00'80,
led_switch4 = 13, LED_COLOR_WHITE = 0x04'04'04,
led_switch3 = 14, LED_COLOR_WHITE_STRONG = 0xFF'FF'FF,
led_switch2 = 15, };
led_switch1 = 16,
led_button4 = 17, enum IndicatorLED {
led_button3 = 18, LED_SHAPE1 = 0u,
led_button2 = 19, LED_SHAPE2 = 1u,
led_button1 = 20, LED_SHAPE3 = 2u,
} IndicatorLED; LED_SHAPE4 = 3u,
LED_MODULE_SSEG = 4u,
LED_GAME_SSEG = 5u,
LED_TFT = 6u,
LED_MIC = 7u,
LED_IR_LED = 8u,
LED_SPEAKER = 9u,
LED_RFID = 10u,
LED_KEYPAD = 11u,
LED_LCD = 12u,
LED_S4 = 13u,
LED_S3 = 14u,
LED_S2 = 15u,
LED_S1 = 16u,
LED_B4 = 17u,
LED_B3 = 18u,
LED_B2 = 19u,
LED_B1 = 20u,
LED_MAX = 20u,
};
/// @brief Initializes the indicator LEDs /// @brief Initializes the indicator LEDs
void init_leds(); void init_leds();
@ -38,7 +57,12 @@ void init_leds();
/// Sets the color of an LED. /// Sets the color of an LED.
/// ///
/// Call `flush_leds()` to send the data to the LEDs. /// Call `flush_leds()` to send the data to the LEDs.
void leds_set(IndicatorLED led, uint8_t r, uint8_t g, uint8_t b); void led_set(uint32_t led, uint32_t color);
/// Sets the color of an LED with rgb.
///
/// Call `flush_leds()` to send the data to the LEDs.
void led_set(uint32_t led, uint8_t r, uint8_t g, uint8_t b);
/// Outputs the data to the leds. /// Outputs the data to the leds.
void leds_flush(); void leds_flush();

View File

@ -37,7 +37,7 @@ void bat_monitor_task(void* arg) {
} }
void init_power_board() { void init_power_board() {
ESP_LOGI(TAG, "Initializing power board...") ESP_LOGI(TAG, "Initializing power board...");
if (!lipo.begin()) { if (!lipo.begin()) {
ESP_LOGE(TAG, "Failed to init communication with the battery gas guage"); ESP_LOGE(TAG, "Failed to init communication with the battery gas guage");

View File

@ -7,8 +7,8 @@ void clean_bomb(void) {
clear_wires_pressed_released_cut(); clear_wires_pressed_released_cut();
// clear leds // clear leds
led_strip_clear(leds); leds_clear();
led_strip_refresh(leds); leds_flush();
// clear module timer // clear module timer
stop_module_timer(); stop_module_timer();

View File

@ -5,22 +5,23 @@ static const char* TAG = "step0";
extern uint32_t initial_game_time; extern uint32_t initial_game_time;
extern uint32_t skip_to_step; extern uint32_t skip_to_step;
static void set_game_time(void); static void set_game_time();
static void skip_to_step1(void) { skip_to_step = 1; } static void skip_to_step1() { skip_to_step = 1; }
static void skip_to_step2(void) { skip_to_step = 2; } static void skip_to_step2() { skip_to_step = 2; }
static void skip_to_step3(void) { skip_to_step = 3; } static void skip_to_step3() { skip_to_step = 3; }
static void skip_to_step4(void) { skip_to_step = 4; } static void skip_to_step4() { skip_to_step = 4; }
static void skip_to_step5(void) { skip_to_step = 5; } static void skip_to_step5() { skip_to_step = 5; }
static void skip_to_step6(void) { skip_to_step = 6; } static void skip_to_step6() { skip_to_step = 6; }
static void try_step1(void) { clean_bomb(); step1(); } static void try_step1() { clean_bomb(); step1(); }
static void try_step2(void) { clean_bomb(); step2(); } static void try_step2() { clean_bomb(); step2(); }
static void try_step3(void) { clean_bomb(); step3(); } static void try_step3() { clean_bomb(); step3(); }
static void try_step4(void) { clean_bomb(); step4(); } static void try_step4() { clean_bomb(); step4(); }
static void try_step5(void) { clean_bomb(); step5(); } static void try_step5() { clean_bomb(); step5(); }
static void try_step6(void) { clean_bomb(); step6(); } static void try_step6() { clean_bomb(); step6(); }
static void issue_strike(void) { strike("Strike Issued"); } static void issue_strike() { strike("Strike Issued"); }
static void debug_switches(void); static void flashbang();
static void battery_stats(void) { static void debug_switches();
static void battery_stats() {
BaseType_t xReturned; BaseType_t xReturned;
TaskHandle_t xHandle = NULL; TaskHandle_t xHandle = NULL;
xReturned = xTaskCreate(bat_monitor_task, "bat_monitor", 4096, NULL, 5, &xHandle); xReturned = xTaskCreate(bat_monitor_task, "bat_monitor", 4096, NULL, 5, &xHandle);
@ -34,9 +35,10 @@ static void battery_stats(void) {
} }
/// Wait for "*9819" /// Wait for "*9819"
void step0(void) { void step0() {
led_strip_set_pixel(leds, Led::speaker, 0, 0, 20); led_set(IndicatorLED::LED_SPEAKER, LED_COLOR_BLUE);
led_strip_refresh(leds); leds_flush();
StarCodeHandler star_codes[] = { StarCodeHandler star_codes[] = {
{ {
.code = "*9819", .code = "*9819",
@ -146,6 +148,12 @@ void step0(void) {
.should_exit = false, .should_exit = false,
.callback = issue_strike, .callback = issue_strike,
}, },
{
.code = "*1112",
.display_text = "????",
.should_exit = false,
.callback = flashbang,
},
}; };
int len = sizeof(star_codes)/sizeof(StarCodeHandler); int len = sizeof(star_codes)/sizeof(StarCodeHandler);
do_star_codes(star_codes, len); do_star_codes(star_codes, len);
@ -163,7 +171,7 @@ static void _update_display(uint8_t* digits, uint8_t cursor_pos) {
lcd_set_cursor_pos(mapped_cursor_pos, 1); lcd_set_cursor_pos(mapped_cursor_pos, 1);
} }
static void set_game_time(void) { static void set_game_time() {
uint8_t hours = (initial_game_time / (1000*60*60)) % 10; uint8_t hours = (initial_game_time / (1000*60*60)) % 10;
uint8_t minutes = (initial_game_time / (1000*60)) % 60; uint8_t minutes = (initial_game_time / (1000*60)) % 60;
uint8_t seconds = (initial_game_time / (1000)) % 60; uint8_t seconds = (initial_game_time / (1000)) % 60;
@ -195,8 +203,8 @@ static void set_game_time(void) {
} }
clean_bomb(); clean_bomb();
led_strip_set_pixel(leds, Led::speaker, 0, 0, 20); led_set(IndicatorLED::LED_SPEAKER, 0, 0, 20);
led_strip_refresh(leds); leds_flush();
return; return;
} else { } else {
int just_pressed = -1; int just_pressed = -1;
@ -266,7 +274,7 @@ static void print_4bin_rev(char* out_str, uint8_t n) {
out_str[4] = '\0'; out_str[4] = '\0';
} }
static void debug_switches(void) { static void debug_switches() {
clean_bomb(); clean_bomb();
uint8_t switch_state = 0xFF; uint8_t switch_state = 0xFF;
uint8_t switch_touch_state = 0xFF; uint8_t switch_touch_state = 0xFF;
@ -346,3 +354,18 @@ static void debug_switches(void) {
} }
} }
static void flashbang() {
play_clip_wav(MOUNT_POINT "/flash.wav", true, false, 1, 0);
vTaskDelay(pdMS_TO_TICKS(4000));
for (int bright = 255; bright >= 0; bright -= 2) {
for (int led_idx = 0; led_idx < IndicatorLED::LED_MAX; led_idx++) {
led_set(led_idx, bright, bright, bright);
}
leds_flush();
vTaskDelay(pdMS_TO_TICKS(10));
}
leds_clear();
leds_flush();
}

View File

@ -115,9 +115,9 @@ static void generate_switch_leds(void) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
uint8_t* rgb = NEOPIXEL_COLORS[switch_leds[i]]; uint8_t* rgb = NEOPIXEL_COLORS[switch_leds[i]];
led_strip_set_pixel(leds, Led::switch1 - i, rgb[0], rgb[1], rgb[2]); led_set(IndicatorLED::LED_S1 - i, rgb[0], rgb[1], rgb[2]);
} }
led_strip_refresh(leds); leds_flush();
} }
static void set_text_and_color(const char* text_str, int color) { static void set_text_and_color(const char* text_str, int color) {
@ -208,18 +208,18 @@ static bool play_part(uint32_t time) {
switch (part) { switch (part) {
case 0: case 0:
lcd_print("COLOR"); lcd_print("COLOR");
led_strip_set_pixel(leds, Led::char_lcd, 20, 0, 20); led_set(IndicatorLED::LED_LCD, 20, 0, 20);
break; break;
case 1: case 1:
lcd_print("NUMBER"); lcd_print("NUMBER");
led_strip_set_pixel(leds, Led::char_lcd, 0, 0, 30); led_set(IndicatorLED::LED_LCD, 0, 0, 30);
break; break;
case 2: case 2:
lcd_print("SWITCH"); lcd_print("SWITCH");
led_strip_set_pixel(leds, Led::char_lcd, 20, 20, 0); led_set(IndicatorLED::LED_LCD, 20, 20, 0);
break; break;
} }
led_strip_refresh(leds); leds_flush();
int times = 0; int times = 0;
int correct = generate_part(); int correct = generate_part();

View File

@ -48,8 +48,8 @@ std::map<int, int> number_map = {
static void new_puzzle(void) { static void new_puzzle(void) {
// scramble lights // scramble lights
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
led_strip_set_pixel(leds, 9, INDICATOR_RED[map_dist(gen)], INDICATOR_GREEN[map_dist(gen)], INDICATOR_BLUE[map_dist(gen)]); led_set(IndicatorLED::LED_SPEAKER, INDICATOR_RED[map_dist(gen)], INDICATOR_GREEN[map_dist(gen)], INDICATOR_BLUE[map_dist(gen)]);
led_strip_refresh(leds); leds_flush();
uint8_t random_segments[4] = {0, 0, 0, 0}; uint8_t random_segments[4] = {0, 0, 0, 0};
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -72,8 +72,8 @@ static void new_puzzle(void) {
} }
// ESP_LOGI(TAG, "Chosen Map: %i", chosen_map); // ESP_LOGI(TAG, "Chosen Map: %i", chosen_map);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 9, INDICATOR_RED[chosen_map], INDICATOR_GREEN[chosen_map], INDICATOR_BLUE[chosen_map])); led_set(IndicatorLED::LED_SPEAKER, INDICATOR_RED[chosen_map], INDICATOR_GREEN[chosen_map], INDICATOR_BLUE[chosen_map]);
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
bool bit = (answer_sseg >> i) & 1; bool bit = (answer_sseg >> i) & 1;

View File

@ -140,9 +140,9 @@ static void write_leds() {
// update all the leds // update all the leds
for (int i = 0; i < LED_COUNT; i++) { for (int i = 0; i < LED_COUNT; i++) {
auto colors = NEOPIXEL_COLORS[indicator_led_idxs[i]]; auto colors = NEOPIXEL_COLORS[indicator_led_idxs[i]];
led_strip_set_pixel(leds, i, colors[0], colors[1], colors[2]); led_set(i, colors[0], colors[1], colors[2]);
} }
led_strip_refresh(leds); leds_flush();
} }
static uint8_t four_bit_flag(bool b0, bool b1, bool b2, bool b3) { static uint8_t four_bit_flag(bool b0, bool b1, bool b2, bool b3) {
@ -212,7 +212,7 @@ static bool one_second() {
start_module_timer(); start_module_timer();
rng_leds(); rng_leds();
int speaker_color = indicator_led_idxs[Led::speaker]; int speaker_color = indicator_led_idxs[IndicatorLED::LED_SPEAKER];
int lcd_string_idx = lcd_string_dist(gen); int lcd_string_idx = lcd_string_dist(gen);
bool was_high = (tone / 3) == 1; bool was_high = (tone / 3) == 1;
write_leds(); write_leds();
@ -238,10 +238,10 @@ static bool one_second() {
uint8_t correct_button_mask = 0b1011; uint8_t correct_button_mask = 0b1011;
uint8_t correct_buttons = four_bit_flag( uint8_t correct_buttons = four_bit_flag(
indicator_led_idxs[Led::char_lcd] != 6, // green indicator_led_idxs[IndicatorLED::LED_LCD] != 6, // green
red_led_count > blue_led_count, // red red_led_count > blue_led_count, // red
0, // yellow UNCHECKED 0, // yellow UNCHECKED
indicator_led_idxs[Led::rfid] == 4 || indicator_led_idxs[Led::rfid] == 6 // blue indicator_led_idxs[IndicatorLED::LED_RFID] == 4 || indicator_led_idxs[IndicatorLED::LED_RFID] == 6 // blue
); );
debug_correct_values(correct_buttons, correct_button_mask, correct_switches); debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
@ -346,7 +346,7 @@ static bool six_second() {
bool was_high = (tone / 3) == 1; bool was_high = (tone / 3) == 1;
bool second_switch_correct_state = (indicator_led_idxs[Led::switch2] == 0) || (indicator_led_idxs[Led::switch2] == 6); bool second_switch_correct_state = (indicator_led_idxs[IndicatorLED::LED_S2] == 0) || (indicator_led_idxs[IndicatorLED::LED_S2] == 6);
second_switch_correct_state = second_switch_correct_state || was_high; second_switch_correct_state = second_switch_correct_state || was_high;
rng_leds(); rng_leds();
@ -363,7 +363,7 @@ static bool six_second() {
} }
int purple_led_on_bottom_count = 0; int purple_led_on_bottom_count = 0;
for (int i = Led::rfid; i < LED_COUNT; i++) { for (int i = IndicatorLED::LED_RFID; i < LED_COUNT; i++) {
if (indicator_led_idxs[i] == 5) { if (indicator_led_idxs[i] == 5) {
purple_led_on_bottom_count++; purple_led_on_bottom_count++;
} }
@ -378,7 +378,7 @@ static bool six_second() {
uint8_t correct_button_mask = 0b1101; uint8_t correct_button_mask = 0b1101;
uint8_t correct_buttons = four_bit_flag( uint8_t correct_buttons = four_bit_flag(
(!was_high) || (green_led_count >= 2) || indicator_led_idxs[Led::keypad] == 4, // green (!was_high) || (green_led_count >= 2) || indicator_led_idxs[IndicatorLED::LED_KEYPAD] == 4, // green
0, // red UNCHECKED 0, // red UNCHECKED
blue_led_count >= 3, // yellow blue_led_count >= 3, // yellow
contains_coconut // blue contains_coconut // blue

View File

@ -25,7 +25,7 @@ void set_unique_leds(std::vector<int>& input_options, const int num, const int r
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
std::uniform_int_distribution<> led_option_dist(0, input_options.size() - 1); std::uniform_int_distribution<> led_option_dist(0, input_options.size() - 1);
int led = led_option_dist(gen); int led = led_option_dist(gen);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, input_options[led], r, g, b)); led_set(input_options[led], r, g, b);
input_options.erase(input_options.begin() + led); input_options.erase(input_options.begin() + led);
} }
} }
@ -37,7 +37,7 @@ void set_unique_leds_random_color(std::vector<int>& input_options, const int num
std::uniform_int_distribution<> led_color_dist(0, sizeof(r) - 1); std::uniform_int_distribution<> led_color_dist(0, sizeof(r) - 1);
int color = led_color_dist(gen); int color = led_color_dist(gen);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, input_options[led], r[color], g[color], b[color])); led_set(input_options[led], r[color], g[color], b[color]);
input_options.erase(input_options.begin() + led); input_options.erase(input_options.begin() + led);
} }
} }
@ -208,7 +208,7 @@ void step5(void) {
clean_bomb(); clean_bomb();
std::vector<int> led_options = all_leds; std::vector<int> led_options = all_leds;
set_unique_leds_random_color(led_options, led_number_dist(gen), INDICATOR_RED, INDICATOR_GREEN, INDICATOR_BLUE); set_unique_leds_random_color(led_options, led_number_dist(gen), INDICATOR_RED, INDICATOR_GREEN, INDICATOR_BLUE);
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
last_cycle_tick = xTaskGetTickCount(); last_cycle_tick = xTaskGetTickCount();
scrambled_times++; scrambled_times++;
} }
@ -243,7 +243,7 @@ void step5(void) {
std::uniform_int_distribution<> non_green_indicators_dist(0, (20 - green_indicators)); std::uniform_int_distribution<> non_green_indicators_dist(0, (20 - green_indicators));
set_unique_leds_random_color(indicator_options, non_green_indicators_dist(gen), NON_GREEN_INDICATOR_RED, NON_GREEN_INDICATOR_GREEN, NON_GREEN_INDICATOR_BLUE); set_unique_leds_random_color(indicator_options, non_green_indicators_dist(gen), NON_GREEN_INDICATOR_RED, NON_GREEN_INDICATOR_GREEN, NON_GREEN_INDICATOR_BLUE);
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
// wait for submit // wait for submit
KeypadKey key; KeypadKey key;
@ -271,7 +271,7 @@ void step5(void) {
const int INDICATOR_BLUE[6] = {0, 10, 0, 0, 5, 5}; const int INDICATOR_BLUE[6] = {0, 10, 0, 0, 5, 5};
set_unique_leds_random_color(indicator_options, indicators_num, INDICATOR_RED, INDICATOR_BLUE, INDICATOR_GREEN); set_unique_leds_random_color(indicator_options, indicators_num, INDICATOR_RED, INDICATOR_BLUE, INDICATOR_GREEN);
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
uint8_t starting_switch_state = get_switch_state(); uint8_t starting_switch_state = get_switch_state();
std::string pressed_keys; std::string pressed_keys;
@ -315,10 +315,10 @@ void step5(void) {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (lit_leds[i]) { if (lit_leds[i]) {
int color = led_color_dist(gen); int color = led_color_dist(gen);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, idx_to_led_map[i], INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color])); led_set(idx_to_led_map[i], INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]);
} }
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
int green_button_pressed = 0; int green_button_pressed = 0;
int blue_button_pressed = 0; int blue_button_pressed = 0;
@ -389,10 +389,10 @@ void step5(void) {
int speaker_color = color_dist(gen); int speaker_color = color_dist(gen);
int s3_color = color_dist(gen); int s3_color = color_dist(gen);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 6, COLOR_RED[tft_color], COLOR_GREEN[tft_color], COLOR_BLUE[tft_color])); led_set(6, COLOR_RED[tft_color], COLOR_GREEN[tft_color], COLOR_BLUE[tft_color]);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 9, COLOR_RED[speaker_color], COLOR_GREEN[speaker_color], COLOR_BLUE[speaker_color])); led_set(9, COLOR_RED[speaker_color], COLOR_GREEN[speaker_color], COLOR_BLUE[speaker_color]);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 14, COLOR_RED[s3_color], COLOR_GREEN[s3_color], COLOR_BLUE[s3_color])); led_set(14, COLOR_RED[s3_color], COLOR_GREEN[s3_color], COLOR_BLUE[s3_color]);
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
int buttons_pressed = 0; int buttons_pressed = 0;
@ -444,7 +444,7 @@ void step5(void) {
int button_colors[4] = {button_color_dist(gen), button_color_dist(gen), button_color_dist(gen), button_color_dist(gen)}; int button_colors[4] = {button_color_dist(gen), button_color_dist(gen), button_color_dist(gen), button_color_dist(gen)};
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (20 - i), BUTTON_COLOR_RED[button_colors[i]], BUTTON_COLOR_GREEN[button_colors[i]], BUTTON_COLOR_BLUE[button_colors[i]])); led_set(IndicatorLED::LED_B1 - i, BUTTON_COLOR_RED[button_colors[i]], BUTTON_COLOR_GREEN[button_colors[i]], BUTTON_COLOR_BLUE[button_colors[i]]);
} }
// switches // switches
@ -456,10 +456,10 @@ void step5(void) {
int switch_colors[4] = {switch_color_dist(gen), switch_color_dist(gen), switch_color_dist(gen), switch_color_dist(gen)}; int switch_colors[4] = {switch_color_dist(gen), switch_color_dist(gen), switch_color_dist(gen), switch_color_dist(gen)};
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (16 - i), SWITCH_COLOR_RED[switch_colors[i]], SWITCH_COLOR_GREEN[switch_colors[i]], 0)); led_set(IndicatorLED::LED_S1 - i, SWITCH_COLOR_RED[switch_colors[i]], SWITCH_COLOR_GREEN[switch_colors[i]], 0);
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
ButtonKey button; ButtonKey button;
KeypadKey key; KeypadKey key;
@ -475,11 +475,11 @@ void step5(void) {
if (button_colors[i] > 3) { if (button_colors[i] > 3) {
button_colors[i] = 0; button_colors[i] = 0;
} }
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (20 - i), BUTTON_COLOR_RED[button_colors[i]], BUTTON_COLOR_GREEN[button_colors[i]], BUTTON_COLOR_BLUE[button_colors[i]])); led_set(IndicatorLED::LED_B1 - i, BUTTON_COLOR_RED[button_colors[i]], BUTTON_COLOR_GREEN[button_colors[i]], BUTTON_COLOR_BLUE[button_colors[i]]);
} }
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
} }
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) { if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
solved_correctly = submit_4(button_colors, switch_colors, starting_switch_state); solved_correctly = submit_4(button_colors, switch_colors, starting_switch_state);
@ -507,7 +507,7 @@ void step5(void) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
set_unique_leds(indicator_options, indicator_numbers[i], INDICATOR_RED[i], INDICATOR_GREEN[i], INDICATOR_BLUE[i]); set_unique_leds(indicator_options, indicator_numbers[i], INDICATOR_RED[i], INDICATOR_GREEN[i], INDICATOR_BLUE[i]);
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
std::array<int, 4> buttons_pressed = {0, 0, 0, 0}; std::array<int, 4> buttons_pressed = {0, 0, 0, 0};
ButtonKey button; ButtonKey button;
@ -562,14 +562,14 @@ void step5(void) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (led_off != i) { if (led_off != i) {
button_colors[i] = led_color_dist(gen); button_colors[i] = led_color_dist(gen);
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (20 - i), COLORS_RED[button_colors[i]], COLORS_GREEN[button_colors[i]], COLORS_BLUE[button_colors[i]])); led_set(IndicatorLED::LED_B1 - i, COLORS_RED[button_colors[i]], COLORS_GREEN[button_colors[i]], COLORS_BLUE[button_colors[i]]);
buttons_cycling[i] = true; buttons_cycling[i] = true;
} else { } else {
button_colors[i] = -1; button_colors[i] = -1;
buttons_cycling[i] = false; buttons_cycling[i] = false;
} }
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
const uint8_t CORRECT_COLORS[4] = {4, 0, 5, 2}; const uint8_t CORRECT_COLORS[4] = {4, 0, 5, 2};
TickType_t lastCycleTime = xTaskGetTickCount(); TickType_t lastCycleTime = xTaskGetTickCount();
@ -593,8 +593,8 @@ void step5(void) {
break; break;
} else if (led_turn_on_dist(gen) == 0) { } else if (led_turn_on_dist(gen) == 0) {
button_turned_on = true; button_turned_on = true;
led_strip_set_pixel(leds, (20 - i), COLORS_RED[CORRECT_COLORS[i]], COLORS_GREEN[CORRECT_COLORS[i]], COLORS_BLUE[CORRECT_COLORS[i]]); led_set(IndicatorLED::LED_B1 - i, COLORS_RED[CORRECT_COLORS[i]], COLORS_GREEN[CORRECT_COLORS[i]], COLORS_BLUE[CORRECT_COLORS[i]]);
led_strip_refresh(leds); leds_flush();
} }
} else if (button_colors[i] != CORRECT_COLORS[i]) { } else if (button_colors[i] != CORRECT_COLORS[i]) {
strike("Wrong time!"); strike("Wrong time!");
@ -610,16 +610,16 @@ void step5(void) {
} }
} }
if ((xTaskGetTickCount() - lastCycleTime) >= pdMS_TO_TICKS(500)) { if ((xTaskGetTickCount() - lastCycleTime) >= pdMS_TO_TICKS(500)) {
for (int i = 0; i < 4; i++) { for (uint32_t i = 0; i < 4; i++) {
if (buttons_cycling[i]) { if (buttons_cycling[i]) {
button_colors[i]++; button_colors[i]++;
if (button_colors[i] > 5) { if (button_colors[i] > 5) {
button_colors[i] = 0; button_colors[i] = 0;
} }
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (20 - i), COLORS_RED[button_colors[i]], COLORS_GREEN[button_colors[i]], COLORS_BLUE[button_colors[i]])); led_set(IndicatorLED::LED_B1 - i, COLORS_RED[button_colors[i]], COLORS_GREEN[button_colors[i]], COLORS_BLUE[button_colors[i]]);
} }
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
lastCycleTime = xTaskGetTickCount(); lastCycleTime = xTaskGetTickCount();
} }
@ -737,7 +737,7 @@ void step5(void) {
set_unique_leds(led_options, modifier_indicators[i], INDICATOR_RED[i], INDICATOR_GREEN[i], INDICATOR_BLUE[i]); set_unique_leds(led_options, modifier_indicators[i], INDICATOR_RED[i], INDICATOR_GREEN[i], INDICATOR_BLUE[i]);
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
std::string answer_string = std::to_string(expression_answer); std::string answer_string = std::to_string(expression_answer);
std::string entered_string = ""; std::string entered_string = "";
@ -803,7 +803,7 @@ void step5(void) {
} }
ESP_ERROR_CHECK(led_strip_refresh(leds)); leds_flush();
std::uniform_int_distribution<> answer_color_dist(0, 4); std::uniform_int_distribution<> answer_color_dist(0, 4);

BIN
resources/flash.wav Normal file

Binary file not shown.