So a quick overview of what the code is supposed to do
- upon button push it should run code
- output voltage to pin 13
- hold for 5000ms
- output voltage to pin 13
- hold for 5000ms
- stop
What its actually doing
- starting as soon as I upload code
- outputs voltage to pin 13
- outputs voltage to pin 12
- delays 5000ms
- turns off pin 12
- delays 5000ms
- turns on pin 12
and just keeps looping
Not sure why the button press isnt working, why pin 13 is always energized, and why it keeps looping.
Thanks for any help!
const int button = 2;
const int handpiece = 13;
const int valve = 12;
const int delay1 = 5000; //time to leave the handpiece on
const int delay2 = 5000; //time to leave the valve on
int buttonstate = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize
pinMode(button,INPUT);
pinMode(handpiece, OUTPUT);
pinMode(valve, OUTPUT);
Serial.begin(9600);
digitalWrite(button, HIGH); //enable internal pull-up resistor
digitalWrite(valve, LOW); // turn the valve off
digitalWrite(handpiece, LOW); // turn the handpiece off
}
void loop() {
buttonstate = digitalRead(button);
if (buttonstate == HIGH) {
digitalWrite(handpiece, HIGH); // turn the handpiece on
delay(delay1); // time to leave handpiece on
//int tach = analogRead(A1);
//float voltage = tach * (5.0 / 1023.0);
//Serial.println(voltage);
digitalWrite(valve, HIGH); // turn the valve on
delay(delay2); // time to leave valve on
digitalWrite(valve, LOW); // turn the valve off
digitalWrite(handpiece, LOW); // turn the handpiece off
}
else{
digitalWrite(valve, LOW); // turn the valve off
digitalWrite(handpiece, LOW); // turn the handpiece off
}
}