Buenas me gustaría poder unir dos juegos que ya tengo programados en una especie de menú, que uno sea Marduino y el otro el Snake, si alguien me ayuda me haría un favor. Lo único que necesito es que al encender el arduino me den a escoger entre esos dos juegos y coger el que quiera con 3 pulsadores, por ejemplo el pin 7 sea derecha el 6 para escoger y el 5 izquierda.
Marduino y Snake.zip (6.66 KB)
Hola sergiotorres,
Puedes hacer algo así:
Dos botones, cada uno conectado a un pin (p.ej: 5, 6).
Definir una variable botVal que haga lo siguiente:
botVal = 0;
si botIzq pulsado, botVal = 1
si botDer pulsado, botVal = 2
A continuación, definir el siguiente programa:
botVal = 0;
const int botIzq = 5;
const int botDer = 6;
void setup(){
pinMode(botIzq, INPUT);
pinMode(botDer, INPUT);
}
void loop(){
while (botVal = 0){
if (digitalRead(botIzq == HIGH)){
botVal = 1;
break;
}
else if (digitalRead(botDer == HIGH)){
botVal = 2;
break;
}
}
switch (botVal){
case 1:
{
// Aquí iría el programa del primer juego
}
case 2:
{
// Aquí iría el programa del segundo juego
}
}
}
Creo que con esto funcionaría, espero que te sirva!!
P.D. En el setup tendrías que escribir todo lo que haya en los dos juegos.
sketch_feb27a:3: error: 'botVal' does not name a type
botVal = 0;
^
C:\Users\SERGIO\AppData\Local\Temp\arduino_modified_sketch_923948\sketch_feb27a.ino: In function 'void loop()':
sketch_feb27a:13: error: 'botVal' was not declared in this scope
while (botVal = 0){
^
sketch_feb27a:25: error: 'botVal' was not declared in this scope
switch (botVal){
^
sketch_feb27a:97: error: a function-definition is not allowed here before '{' token
float sign(float x) {
^
sketch_feb27a:116: error: a function-definition is not allowed here before '{' token
void inputManager(unsigned int pin0, unsigned int pin1, unsigned int pin2) {
^
sketch_feb27a:1129: error: expected '}' at end of input
}
^
sketch_feb27a:1129: error: expected '}' at end of input
sketch_feb27a:1129: error: expected '}' at end of input
exit status 1
'botVal' does not name a type
Me sale todos esto. cuando junto lo que me has dicho.
Perdona, aquí está corregido:
int botVal = 0;
const int botIzq = 5;
const int botDer = 6;
void setup(){
pinMode(botIzq, INPUT);
pinMode(botDer, INPUT);
}
void loop(){
while (botVal = 0){
if (digitalRead(botIzq == HIGH)){
botVal = 1;
break;
}
else if (digitalRead(botDer == HIGH)){
botVal = 2;
break;
}
}
switch (botVal){
case 1:
{
// Aquí iría el programa del primer juego
}
case 2:
{
// Aquí iría el programa del segundo juego
}
}
}
Creo que solo era poner "int" delante de "botVal", por si acaso vuelve a copiarlo entero.