hola buenas tengo que crear un juego del tipo de aplastatopos, es decir que con dos leds y dos botones vaya apareciendo una secuencia y con los botones hay que seguirla y en caso de fallar, un zumbador silbe, y asi asta tres veces que se para el juego para volver a empezar. En caso de haber conseguido seguir la secuencia subes al siguiente nivel.
Gracis, espero respuestas.
hasta ahora he hecho esto del programa:
const int TOUCH_BUTTON = 2;
const int RED_LED = 9;
const int GREEN_LED = 10;
const int POTENCIOMETER = A0;
const int RED_BUTTON = 3;
const int GREEN_BUTTON = 4;
const int WAIT = 0;
const int INIT = 1;
const int SHOW_SEQUENCE = 2;
const int READ_SEQUENCE = 3;
const int RED = 1;
const int GREEN = 2;
int state = WAIT;
int difficulty;
int level;
int sequence[20];
void setup() {
Serial.begin(9600);
pinMode(TOUCH_BUTTON, INPUT);
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
}
void loop() {
switch (state){
case WAIT: //estado "espera"
if(digitalRead(TOUCH_BUTTON) == true){
state = INIT;
Serial.println("Paso a estado -> inicializando");
}
break;
case INIT: //estado "inicializando"
difficulty = getDifficulty();
Serial.println((String)"Dificultad: " + difficulty);
level = 1;
for(int i = 0; i < 20; i++){
sequence = random(1,4);
_ Serial.println((String)"[" + i + "] - " + sequence*);_
_ }*_
* delay(1000);*
* state = SHOW_SEQUENCE;
_ Serial.println("Paso a estado -> mostrar secuencia");_
_ break;_
case SHOW_SEQUENCE: //estado "mostrar secuencia"
_ showSequence(sequence, level, difficulty);_
_ delay(1000);*_
* state = READ_SEQUENCE;
_ Serial.println("Paso a estado -> leer pulsadores");_
_ break;_
case READ_SEQUENCE: //estado "leer pulsadores"*
* level++;*
* if (level == 4){*
* state = WAIT;*
* Serial.println("Paso a estado -> espera");*
* }*
* else{*
* state = SHOW_SEQUENCE;
_ Serial.println("Paso a estado -> mostrar secuencia");_
_ }_
_ break;_
_}_
_}_
_ int getDifficulty(){*_
* int sensorValue = analogRead(POTENCIOMETER);*
_ return (sensorValue * (5.0 / 1023.0));_
}
void showSequence(int seq[], int lev, int dif){
_ int interval = 500 - (dif * 50);
* for (int i = 0; i < lev; i++){*
if (seq == RED){
* digitalWrite(RED_LED, HIGH);*
* delay(interval);_
digitalWrite(RED_LED, LOW);
_ delay(interval);
}
else if (seq == GREEN){_
digitalWrite(GREEN_LED, HIGH);
_ delay(interval);_
digitalWrite(GREEN_LED, LOW);
_ delay(interval);
}
}
}*_