hi, i'm new to this. could someone please tell me if my sketch is ok. i want to open a toggle switch to on, with 5volts on it(input). and at the outputs(22,24) sound an alarm and light up a led for 4 seconds. and in that four seconds it will sound and lite for a half second, that means 8 times, then stop with the switch still to on position. when i close it, i dont want nothing until i re-open it. i'm missing the half second delay???
thanks in advance, paul
/*
Blink
Turns on an LED and a alarm on for half second, then off for half second, repeatedly
for 4 seconds and stops on high point ON.
*/
const int buttonPin = 23; // the number of the toggle switch pin
const int ledPin = 22; // the number of the 5volt bulb pin
int buttonpin = 23; // variable for reading the toggle status
void setup() {
// initialize the digital pins as an output and input.
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
pinMode(23,INPUT);
}
void loop() {
int buttonpin=digitalRead(23);
if (buttonPin == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
digitalWrite(24,HIGH);
delay(4000);
digitalWrite(22,LOW);
digitalWrite(24,LOW);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
digitalWrite(24,LOW);
}
}
Moderator edit: Please put code in code boxes. Use the # icon blah blah blah blah