Paso 3: Codeing
A continuación se utiliza el código para hacer que la alarma funciona, Ive ponerlo por lo que toca la melodía de la cuenta Final de
int rcvpin = A0;
int buzzpin = 9;
void setup()
{
pinMode(rcvpin,INPUT);
pinMode(buzzpin,OUTPUT);
Buzz(200);
Buzz(200);
Buzz(200);
Delay(2000);
Serial.Begin(9600);
}
void loop()
{
int ldrval=analogRead(rcvpin);
Serial.println(ldrval);
Si (ldrval < = 800)
{
Buzz(50);
playmelody();
}
}
#define C_note 261
#define C_sharp 277
#define D_note 293
#define D_sharp 311
#define E_note 329
#define F_note 349
#define F_sharp 369
#define G_note 391
#define G_sharp 415
#define A_note 440
#define A_sharp 466
#define B_note 246
int melody2 [] = {F_sharp, 16, E_note, F_sharp, 16, 64, B_note, 64,
G_note, 16, F_sharp, G_note, 16, 32, F_sharp, E_note, 32, 64,
G_note, 16, F_sharp, G_note, 16, 64, B_note, 64,
E_note, 16, D_note, E_note, 16, 32, D_note, 32,
C_note, 32, E_note, D_note, 32, 64, F_sharp, 16,
E_note, 16, F_sharp, B_note, 64, 64,
0, 0};
melodía de int [] = {C_sharp, B_note, C_sharp, F_sharp, D_note, C_sharp, D_note, C_sharp, B_note, D_note,
C_sharp, D_note, F_sharp, B_note, A_note, B_note, A_note, G_sharp, B_note, A_note,
G_sharp, A_note, B_note, A_note, B_note, C_sharp, B_note, A_note, G_sharp, F_note,
D_note C_sharp C_sharp, C_sharp, D_note, C_sharp, B_note, C_sharp};
void playmelody() {}
int i = 0;
mientras que (melody2 [i] > 0) {}
tono (buzzpin, melody2[i]);
Delay(MELODY2[i+1]*10);
i = i + 2;
}
noTone(buzzpin);
}
void buzz (tiempo de char sin signo)
{
analogWrite(buzzpin,170);
Delay(Time);
analogWrite(buzzpin,0);
Delay(Time);
}