#include
//melodías a partir del starter de tinkercad
//melodía1: cuando obtiene una respuesta correcta
#define NOTE_C4 262
#define NOTE_G3 196
#define NOTE_A3 220
#define NOTE_B3 247
//melodía2: cuando obtiene una respuesta incorrecta
#define NOTE_D3 146
#define NOTE_C3sost 140
#define NOTE_C3 130
#define NOTE_B2 120
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
int melody2[] = {
NOTE_D3, NOTE_C3sost, NOTE_C3, NOTE_B2
};
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
int noteDurations2[] = {
4, 4, 4, 2
};
//declaración de variables:
Servo motor_der; //servomotor del brazo derecho
Servo motor_izq; //servomotor del brazo izquierdo
char respuesta;
const int pinBuzzer = 6; //Pin de salida de buzzer
int pos = 0;
void setup()
{
Serial.begin(9600);
motor_der.attach(3); //El servomotor al pin 3
motor_izq.attach(4); //El servomotor al pin 4
pinMode(pinBuzzer, OUTPUT); //Pin de salida para Buzzer
}
void loop(){
Serial.println("Ingrese 1 (correcta) o 0 (incorrecta)");
respuesta = Serial.read();//lee si la respuesta era correcta o no
if(respuesta == '1'){
// se reproduce una melodía (tomado del starter de tinkercad):
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(6, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(6);
}
//los brazos se mueven arriba y abajo 1 vez (giro de 180° y de regreso):
for (pos = 0; pos <= 180; pos += 1) {
//girar 180°
motor_der.write(pos);
motor_izq.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
//regresar
motor_der.write(pos);
motor_izq.write(pos);
delay(15);
}
}
if(respuesta == '0'){
for (int thisNote2 = 0; thisNote2 < 5; thisNote2++) {
int noteDuration2 = 1000 / noteDurations2[thisNote2];
tone(6, melody2[thisNote2], noteDuration2);
int pauseBetweenNotes2 = noteDuration2 * 1;
delay(pauseBetweenNotes2);
// stop the tone playing:
noTone(6);
}
}
Designed with
Offline Website Builder