/** ****************************************************************************************
* \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
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...");
Led_configura();
Leds_test(5);
randomSeed(analogRead(1));
delay(1000);
MemoryTest();MemoryTest();MemoryTest();
}
//------------------------------------------------------------------------------------------
//=== LOOP ================================================================================
//------------------------------------------------------------------------------------------
void loop() {
// put your main code here, to run repeatedly:
}