Hi all,
I'm quite fresh with arduino, and haven't seen a tutorial covering this.
I'm trying to make a switch trigger a servo in the way that it would move it (and turn on the LED at pin 13) and then ignore if the switch turns on or off for a certain amount of time, here 2 seconds.
I thought I would achieve this by inserting a delay(2000) after it reads the pin as being HIGH, but this results in the LED at pin 13 blinking at a 2 second interval.
Any hints are greatly appreciated!
In the end I would like to make the switch trigger a soundfile on the seeduino music shield, and ignore any switch changes until the soundfile has finished...
#include <Servo.h>
Servo servoMain; // Define our Servo
int ledPin = 13; // choose the pin for the LED
int inPin = 8; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int reset= 0; // var to not send out to many messages to servo
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
servoMain.attach(5); // servo on digital pin 5
Serial.println("Ready");
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
// Run Servo
servoMain.write(45);
delay(2000);
reset= 0;
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
if (reset == 0)
{
// Run Servo
servoMain.write(0);
}
reset= 1;
}
}