Ok, this is my first project where I've not had @forsvunnet close by to help.
I've got a camera connected to an optocoupler, that just fires HIGH then LOW.
I can't get a button working with it, so when I push a button, it fires opto 3 times.
This is my sketch.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int opto = 12;
int buttonInput = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
// the setup routine runs once when you press reset:
void setup()
{
// initialize the digital pin as an output.m
pinMode(opto, OUTPUT);
pinMode(buttonInput, INPUT);
digitalWrite(buttonInput, LOW);}
// the loop routine runs over and over again forever:
void loop()
{
buttonState = digitalRead(buttonInput);
if (buttonState == HIGH) {
digitalWrite(opto, HIGH);
delay(1000); // wait for a second
digitalWrite(opto, LOW);
delay(1000); // wait for a second
digitalWrite(opto, HIGH);
delay(1000); // wait for a second
digitalWrite(opto, LOW);
} else {
}
}
Anyone point me in the right direction? It's driving me mad.
digitalWrite()
on an input pin (buttonInput
) insetup()
? Should it beopto
instead? Also, do you use a pullup (or pulldown) resistor to force a level onbuttonInput
when the button is not pushed?