Forgive me if this is a super beginner issue, but that's what I am...
I have a sketch written that takes inputs from 4 different buttons.
This part is working fine.
I also have several outputs also working fine (ie turning on different LEDs, running a servo, etc).
As I iterate the development I have reached the point where I want to assign a number of actions to the buttons, some of which have overlap.
For example, I want button A to close relay #1 for 3 seconds when pressed, but I want button D to close the same relay for the duration of the button press only.
When I took the code for closing the relay which works on button A and tried to do the exact same code for button D, the relay did not click but the light lit up.
So as I sit, if I press button A the relay clicks (and the little LED on the board lights up)
When I press button D the LED on the board lights, but the relay does not click.
If I comment out the code for A then D starts working.
Is there some issue with two digital inputs with the same output?
Hopefully I have explained this correctly.
// Set pin numbers and define servo for choke:
//includes
#include <Servo.h>
// Define Servo
Servo choke;
int pos = 0;
// Define Remote Buttons
const int AbuttonPin = 11; // Remote input for A button
const int BbuttonPin = 9; // Remote input for B button
const int CbuttonPin = 7; // Remote input for C button
const int DbuttonPin = 12; // Remote input for D button
// define digital outputs
const int starterOutputPin = 2; // output pin to starter relay
const int BoutputPin = 8; // the number of the LED pin
// set states:
int AbuttonState = 0; // variable for reading the pushbutton status
int BbuttonState = 0; // variable for reading the pushbutton status
int CbuttonState = 0; // variable for reading the pushbutton status
int DbuttonState = 0; // variable for reading the pushbutton status
void setup() {
// Attach servo control to pin
choke.attach(6);
// initialize the LED pin as an output:
pinMode(starterOutputPin, OUTPUT);
pinMode(BoutputPin, OUTPUT);
// initialize the pushbutton pins as inputs:
pinMode(AbuttonPin, INPUT);
pinMode(BbuttonPin, INPUT);
pinMode(CbuttonPin, INPUT);
pinMode(DbuttonPin, INPUT);
}
void loop() {
// D Button Code -Manual Starter
DbuttonState = digitalRead(DbuttonPin);
// check if the Dpushbutton is pressed.
// if it is, the DbuttonState is HIGH:
if (DbuttonState == LOW) {
// turn LED on:
digitalWrite(starterOutputPin, HIGH);
} else {
// turn LED off:
digitalWrite(starterOutputPin, LOW);
}
// A Button Code
AbuttonState = digitalRead(AbuttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (AbuttonState == LOW) {
// turn LED on:
digitalWrite(starterOutputPin, HIGH);
} else {
// turn LED off:
digitalWrite(starterOutputPin, LOW);
}
// B Button Code
BbuttonState = digitalRead(BbuttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (BbuttonState == LOW) {
// turn LED on:
digitalWrite(BoutputPin, HIGH);
} else {
// turn LED off:
digitalWrite(BoutputPin, LOW);
}
// C Button Code
CbuttonState = digitalRead(CbuttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (CbuttonState == LOW) {
// Run servo:
choke.write(90);
} else {
// stop servo:
choke.write(0);
}
}