/** ****************************************************************************************
* \mainpage
*
* @brief Gioco di memoria con led e pulsanti sfruttando gli array
* https://wokwi.com/projects/389786310514471937
*
* @author Filippo Bilardo
* @date 15/02/24
* @version 1.0 15/02/24 Versione iniziale
*/
//------------------------------------------------------------------------------------------
//=== INCLUDES =============================================================================
//------------------------------------------------------------------------------------------
#include "Led.h"
#include "Puls.h"
#include "Buzz.h"
//------------------------------------------------------------------------------------------
//=== CONSTANTS ============================================================================
//------------------------------------------------------------------------------------------
#define P1_PIN 12
#define P2_PIN 10
#define P3_PIN 8
#define P4_PIN 6
Pulsante P1(P1_PIN);
Pulsante P2(P2_PIN);
Pulsante P3(P3_PIN);
Pulsante P4(P4_PIN);
int power(int exponent) {
int base = 2, result = 1;
for (int i = 0; i < exponent; ++i) {
result *= base;
}
return result;
}
/**
* Crea un vettore di 4 elementi riempito con valori casuali
* Accende i led corrispondenti ai valori del vettore
* uno alla volta per un tempo di 500ms
*/
void MemoryTest() {
int seq[4];
for(int i=0; i<4; i++) {
seq[i] = random(0, 4);
}
for(int i=0; i<4; i++) {
Leds_value(power(seq[i]));
delay(300);
Leds_value(0);
delay(500);
}
}
//------------------------------------------------------------------------------------------
//=== SETUP ================================================================================
//------------------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
Serial.println("Avvio...");
Buzz_configura();
Buzz_test1();
Led_configura();
Leds_test(5);
randomSeed(analogRead(1));
delay(1000);
//MemoryTest();MemoryTest();MemoryTest();
}
//------------------------------------------------------------------------------------------
//=== LOOP ================================================================================
//------------------------------------------------------------------------------------------
void loop() {
// put your main code here, to run repeatedly:
P1.press() ? Led_accendi(LED1_PIN), Buzz_tone(1) : Led_spegni(LED1_PIN);
P2.press() ? Led_accendi(LED2_PIN), Buzz_tone(2) : Led_spegni(LED2_PIN);
P3.press() ? Led_accendi(LED3_PIN), Buzz_tone(3) : Led_spegni(LED3_PIN);
P4.press() ? Led_accendi(LED4_PIN), Buzz_tone(4) : Led_spegni(LED4_PIN);
}