#include "pitches.h"
int Pin = 1;
int otherPin = 12;
ledone int = 2;
int ledtwo = 3;
int ledthree = 4;
int ledfour = 5;
int ledfive = 6;
int ledsix = 7;
int ledseven = 8;
int ledeight = 9;
int lednine = 10;
int ledten = 11;
int x = 1;
int y = 1;
int val;
int buttonState;
valt int;
int buttonStatet;
int buttonPresses = 0;
int otherbuttonPresses = 0;
int sensorReading = analogRead(A0);
melodía de int [] = {}
NOTE_A4, NOTE_B4, NOTE_C5, NOTE_A4, NOTE_DS5};
int noteDurations [] = {}
1,4,2,2,1};
void setup () {}
para (int thisNote = 0; thisNote < 5; thisNote ++) {}
int noteDuration = 1000/noteDurations [thisNote];
tono (0, melodía [thisNote], noteDuration);
Delay(noteDuration+30);
}
pinMode (Pin, entrada);
pinMode (otherPin, entrada);
pinMode (ledone, salida);
pinMode (ledtwo, salida);
pinMode (ledthree, salida);
pinMode (ledfour, salida);
pinMode (ledfive, salida);
pinMode (ledsix, salida);
pinMode (ledseven, salida);
pinMode (ledeight, salida);
pinMode (lednine, salida);
pinMode (ledten, salida);
Serial.Begin(9600);
buttonState = digitalRead(Pin);
buttonStatet = digitalRead(otherPin);
para (int ledfive = 6, ledsix = 7; ledfive > = 1, ledsix < = 11; ledfive = ledfive-1, ledsix = ledsix + 1) {}
pinMode (ledfive, salida);
digitalWrite (ledfive, HIGH);
digitalWrite (ledsix, HIGH);
Delay(500);
digitalWrite (ledfive, bajo);
digitalWrite (ledsix, bajo);
}
}
void loop)
{
Val = digitalRead(Pin);
valt = digitalRead(otherPin);
Si (val! = buttonState)
{
Si (val == HIGH) {}
buttonPresses ++;
}
}
buttonState = val;
Si (valt! = buttonStatet) {}
Si (valt == HIGH) {}
otherbuttonPresses ++;
}
}
buttonStatet = valt;
Si (buttonPresses == 10)
{
digitalWrite (ledone, HIGH);
Serial.println ("un jugador está abriendo fuera!");
tono (0, NOTE_A4, 200);
}
Si (buttonPresses == 20)
{
digitalWrite (ledone, HIGH);
digitalWrite (ledtwo, HIGH);
Serial.println ("un jugador va caliente!");
tono (0, NOTE_B4, 200);
}
Si (buttonPresses == 30)
{
digitalWrite (ledone, HIGH);
digitalWrite (ledtwo, HIGH);
digitalWrite (ledthree, HIGH);
Serial.println ("jugador de uno está cerca!");
tono (0, NOTE_C5, 200);
}
Si (buttonPresses == 40)
{
digitalWrite (ledone, HIGH);
digitalWrite (ledtwo, HIGH);
digitalWrite (ledthree, HIGH);
digitalWrite (ledfour, HIGH);
Serial.println ("un jugador es casi!");
tono (0, NOTE_D5, 200);
}
Si (buttonPresses == 50)
{
digitalWrite (ledone, HIGH);
digitalWrite (ledtwo, HIGH);
digitalWrite (ledthree, HIGH);
digitalWrite (ledfour, HIGH);
digitalWrite (ledfive, HIGH);
Si (y == 1)
{
melodía de int [] = {}
NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_F5, NOTE_D5, NOTE_F5, NOTE_E5,};
int noteDurations [] = {}
4,8,8,8,6,6,6,1.5,};
para (int thisNote = 0; thisNote < 8; thisNote ++) {}
int noteDuration = 1000/noteDurations [thisNote];
tono (0, melodía [thisNote], noteDuration);
Delay(noteDuration+50);}
y = 2;
}
Serial.println ("jugador uno gana!");
Serial.println ("volver a subir el bosquejo para jugar otra vez!");
digitalWrite (ledsix, bajo);
digitalWrite (ledseven, bajo);
digitalWrite (ledeight, bajo);
digitalWrite (lednine, bajo);
digitalWrite (ledten, bajo);
otherbuttonPresses = 0;
}
Si (otherbuttonPresses == 10)
{
digitalWrite (ledten, HIGH);
Serial.println ("jugador dos es ardiente fuera!");
tono (0, NOTE_A5, 200);
}
Si (otherbuttonPresses == 20)
{
digitalWrite (ledten, HIGH);
digitalWrite (lednine, HIGH);
Serial.println ("jugador dos va caliente!");
tono (0, NOTE_B5, 200);
}
Si (otherbuttonPresses == 30)
{
digitalWrite (ledten, HIGH);
digitalWrite (lednine, HIGH);
digitalWrite (ledeight, HIGH);
Serial.println ("Reproductor de dos está cerca!");
tono (0, NOTE_C6, 200);
}
Si (otherbuttonPresses == 40)
{
digitalWrite (ledten, HIGH);
digitalWrite (lednine, HIGH);
digitalWrite (ledeight, HIGH);
digitalWrite (ledseven, HIGH);
Serial.println ("Reproductor de dos es casi!");
tono (0, NOTE_D6, 200);
}
Si (otherbuttonPresses == 50)
{
digitalWrite (ledten, HIGH);
digitalWrite (lednine, HIGH);
digitalWrite (ledeight, HIGH);
digitalWrite (ledseven, HIGH);
digitalWrite (ledsix, HIGH);
Si (x == 1)
{
melodía de int [] = {}
NOTE_E6, NOTE_E6, NOTE_E6, NOTE_E6, NOTE_F6, NOTE_D6, NOTE_F6, NOTE_E6,};
int noteDurations [] = {}
4,8,8,8,6,6,6,1.5,};
para (int thisNote = 0; thisNote < 8; thisNote ++) {}
int noteDuration = 1000/noteDurations [thisNote];
tono (0, melodía [thisNote], noteDuration);
Delay(noteDuration+50);}
x = 2;
}
Serial.println ("jugador dos victorias!");
Serial.println ("volver a subir el bosquejo para jugar otra vez!");
digitalWrite (ledone, LOW);
digitalWrite (ledtwo, bajo);
digitalWrite (ledthree, bajo);
digitalWrite (ledfour, bajo);
digitalWrite (ledfive, bajo);
buttonPresses = 0;
}
}
Aquí está la ficha pitches.h, ya que lo necesitará para este programa ejecutar con éxito.
/*************************************************
* Públicas constantes
*************************************************/
/*************************************************
* Públicas constantes
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978