Hello,
I am trying to program a Sparkfun Redboard to act as a 3-input to 4- output converter (If you know what I mean).
The following is supposed to happen:
If Input 1 and input 2 are on, Output 3 turns on.
If Only Input 1 is on, Output 1 turns on.
If only Input 2 is on, then Output 2 turns on.
And finally, if Input 3 is on, Output 4 turns on.
The issue I am having has to do with Inputs 1 and 2.
If Input 2 is on, then Output 3 turns on
And if Input 3 is on, then Input 1 turns on.
I have no clue what is causing the bug to occur, but I'm sure someone can help me fix this.
Here is the code:
//Pin Setup
int F1In = 14;
int F2In = 15;
int F3In = 16;
int Out1 = 4;
int Out2 = 5;
int Out3 = 6;
int Out4 = 7;
void setup() {
// put your setup code here, to run once:
//Initialize Pins
pinMode(F1In, INPUT_PULLUP);
pinMode(F2In, INPUT_PULLUP);
pinMode(F3In, INPUT_PULLUP);
pinMode(Out1,OUTPUT);
pinMode(Out2, OUTPUT);
pinMode(Out3, OUTPUT);
pinMode(Out4, OUTPUT);
//Activate Serial
Serial.begin(9600);
}
void loop() {
if (digitalRead(F1In)== HIGH && digitalRead(F2In) == HIGH){
Serial.print("3");
}
else if (digitalRead(F1In) == HIGH) {
Serial.print("1");
}
else if (digitalRead(F2In) == HIGH){
Serial.print("2");
}
else if (digitalRead(F3In) == HIGH){
Serial.print("4");
}
}
void Clear(){
digitalWrite(Out1, LOW);
digitalWrite(Out2, LOW);
digitalWrite(Out3, LOW);
digitalWrite(Out4, LOW);
}
If anybody can help me with this, Please tell me what to do or better yet, fix this code so it will work as intended.