// give it a name:
int x;
int led4 = 4; //light
int led3 = 3; //n/c
int led6 = 6; //n/c
int led5 = 5; //buzzer
int led13 = 13; //n/c
int state10 = 1;
int state11 = 1;
int state12 = 1;
// on off on off on off on off on off on off on off on off on off on off on off
int t1[] = {15000,14500,500,12000,500,500,500,500,500,15000,500,12000,500,500,500,500,500,500,500,500,500,500};
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT); //buzzer
pinMode(led5, OUTPUT); //light
pinMode(led6, OUTPUT);
pinMode(led13, OUTPUT);
pinMode(10,INPUT_PULLUP);
pinMode(11,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
Serial.begin (115200);
}
// the loop routine runs over and over again forever:
void loop(){
state11 = digitalRead(11);
state12 = digitalRead(12);
Serial.println (state11);
Serial.println (state12);
if(state12==LOW)
{
for (x=0;x<22;x=x+1)
{//9 different array variables +1 for array (0-9)
Serial.println (x);
Serial.println (t1[x]);
if (x==1 || x==3 || x==5 || x==7 || x==9 || x==11 || x==13 || x==15 || x==17 || x==19)
{
digitalWrite(led5, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (x==0 || x==2 || x==4 || x==6 || x==8 || x==10 || x==12 || x==14 || x==16 || x==18 ||x==20 ||x==21)
{
digitalWrite(led5, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led4, LOW); // turn the LED off by making the voltage LOW
}
if (x==0)
{
delay (250);
digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (x==1)
{
digitalWrite(led4, LOW); // turn the LED off by making the voltage LOW
delay (250);
digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)
}
delay(t1[x]); // wait for period t1(x)
}
}
if (state12==HIGH)
{
digitalWrite(led4
, HIGH);
digitalWrite(led5, HIGH);
}
state10 = digitalRead(10);
if (state10 == LOW)
{
digitalWrite(led5, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(led4, LOW); // turn the LED on (HIGH is the voltage level)
delay (500);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
delay (30000);
}
}
The code is for a timer that runs through a series of sequences putting a light and a buzzer on at preset times.
I now need the buzzer to oscillate instead of just switch on and off, as the new buzzer only works this way, the old one just needed a voltage. (D5 in the sketch)
Is there any way to do this without totally altering everything to include millis instead of delays?
Thanks.