#include <iostream>
#include <cstdlib>
#include <ctime>
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/time.h"
#include "debounce.hpp"
#define ONBOARD_LED 25
#define BLINK_LED_DELAY 500
#define LED0 12
#define LED1 13
#define LED2 14
#define LED3 15
#define BTN0 16
#define BTN1 17
#define BTN2 18
#define BTN3 19
#define BTN4 20
#define PATTERN_LEN 10
#define NUMBER_OF_BTNS 5
volatile bool waiting_for_pattern = true;
int rand_pattern[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int level = 0;
int user_input_number = 0;
int game_over = false;
int user_point = 0;
void core1_entry() {
while (1) {
gpio_put(ONBOARD_LED, 1);
sleep_ms(BLINK_LED_DELAY);
gpio_put(ONBOARD_LED, 0);
sleep_ms(BLINK_LED_DELAY);
}
}
int main() {
stdio_init_all();
gpio_init(ONBOARD_LED);
gpio_set_dir(ONBOARD_LED, true);
gpio_init(LED0);
gpio_set_dir(LED0, true);
gpio_init(LED1);
gpio_set_dir(LED1, true);
gpio_init(LED2);
gpio_set_dir(LED2, true);
gpio_init(LED3);
gpio_set_dir(LED3, true);
srand(time(NULL));
Debouncer btn0(BTN0);
Debouncer btn1(BTN1);
Debouncer btn2(BTN2);
Debouncer btn3(BTN3);
Debouncer btn4(BTN4);
gpio_set_irq_enabled_with_callback(BTN0, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, &btn0, &Debouncer::gpioCallback);
gpio_set_irq_enabled(BTN1, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
gpio_set_irq_enabled(BTN2, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
gpio_set_irq_enabled(BTN3, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
gpio_set_irq_enabled(BTN4, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
multicore_launch_core1(core1_entry);
int pattern = 0;
while (1) {
if (game_over) {
continue;
}
if (waiting_for_pattern) {
// Generate and display the pattern
for (int i = 0; i <= level; i++) {
pattern = rand() % 4;
rand_pattern[i] = pattern;
std::cout << "\npattern[" << i << "] = " << pattern << std::endl;
// Set the corresponding LEDs
gpio_put(LED0, pattern == 0);
gpio_put(LED1, pattern == 1);
gpio_put(LED2, pattern == 2);
gpio_put(LED3, pattern == 3);
sleep_ms(BLINK_LED_DELAY);
gpio_put(LED0, 0);
gpio_put(LED1, 0);
gpio_put(LED2, 0);
gpio_put(LED3, 0);
sleep_ms(BLINK_LED_DELAY);
}
level++;
if (level >= PATTERN_LEN) {
level = PATTERN_LEN - 1;
}
waiting_for_pattern = false;
}
}
return 0;
}