step 3 polishing
This commit is contained in:
+28
-13
@@ -56,8 +56,8 @@ void step3(void) {
|
||||
while (solved_puzzles < 3) {
|
||||
lcd_set_cursor(&lcd, 1, 1);
|
||||
|
||||
int puzzle = puzzle_dist(gen);
|
||||
// int puzzle = 8;
|
||||
// int puzzle = puzzle_dist(gen);
|
||||
int puzzle = 6;
|
||||
|
||||
bool solved_correctly = false;
|
||||
switch (puzzle) {
|
||||
@@ -564,7 +564,7 @@ void step3(void) {
|
||||
int led_off = led_off_dist(gen);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (led_off != 0) {
|
||||
if (led_off != i) {
|
||||
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]]));
|
||||
buttons_cycling[i] = true;
|
||||
@@ -577,18 +577,29 @@ void step3(void) {
|
||||
|
||||
const uint8_t CORRECT_COLORS[4] = {4, 0, 5, 2};
|
||||
TickType_t lastCycleTime = xTaskGetTickCount();
|
||||
bool button_turned_on = false;
|
||||
|
||||
ButtonKey button;
|
||||
|
||||
std::uniform_int_distribution<> led_turn_on_dist(0, 3);
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (button_colors[i] != CORRECT_COLORS[i]) {
|
||||
strike("Paused the button at the wrong time! (step 3, puzzle 6)");
|
||||
break;
|
||||
} else {
|
||||
buttons_cycling[i] = false;
|
||||
if (((button_state >> i) & 0b1) == 0b1) {
|
||||
if (button_colors[i] == -1) {
|
||||
if (led_turn_on_dist(gen) == 0) {
|
||||
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_strip_refresh(leds);
|
||||
}
|
||||
} else if (button_colors[i] != CORRECT_COLORS[i]) {
|
||||
strike("Paused the button at the wrong time!");
|
||||
break;
|
||||
} else {
|
||||
buttons_cycling[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -608,14 +619,18 @@ void step3(void) {
|
||||
lastCycleTime = xTaskGetTickCount();
|
||||
}
|
||||
if (get_module_time() <= 0) {
|
||||
bool success = true;
|
||||
for (int i = 0; i < sizeof(buttons_cycling); i++) {
|
||||
if (buttons_cycling[i] == true) {
|
||||
strike("Ran out of time! (step 3, puzzle 6)");
|
||||
if ((buttons_cycling[i] == true) || (button_turned_on == false && led_off != -1)) {
|
||||
strike("Ran out of time!");
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
solved_puzzles++;
|
||||
solved_correctly = true;
|
||||
if (success) {
|
||||
solved_puzzles++;
|
||||
solved_correctly = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
@@ -874,7 +889,7 @@ void step3(void) {
|
||||
}
|
||||
if (solved_correctly) {
|
||||
play_raw(MOUNT_POINT "/correct.pcm");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
solved_correctly = false;
|
||||
} else {
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
|
||||
Reference in New Issue
Block a user