I'm struggling in the very beginning of my first project.
The problem starts with a simple thing:
I want to read in 2 buttons and want to set a value depending on the pressed button.
The variable 'Target' shall get an integer value.
No matter what I try, 'Target' doesn't get the value.
Also the serial monitor reports that both buttons are pressed.
All the buttons are working properly, tested step by step with the blink example.
What am I doing so entirely wrong?
See code below.
Thank you,
Gregor
boolean Moving = false;
int Position_0 = 7;
int Position_1_up = 8;
int Position_1_down = 6;
int Position_2 = 5;
int Order_0 = 3;
int Order_1 = 2;
int Order_2 = 4;
int Door = 9;
int Motor_up = 11;
int Motor_down = 12;
int Light = 13;
int Target = 0;
void setup() {
Serial.begin(9600);
pinMode(Position_0, INPUT);
pinMode(Position_1_up, INPUT);
pinMode(Position_1_down, INPUT);
pinMode(Position_2, INPUT);
pinMode(Order_0, INPUT);
pinMode(Order_1, INPUT);
pinMode(Order_2, INPUT);
pinMode(Door, INPUT);
pinMode(Motor_up, OUTPUT);
pinMode(Motor_down, OUTPUT);
pinMode(Light, OUTPUT);
digitalWrite(Motor_up, HIGH);
digitalWrite(Motor_down, HIGH);
digitalWrite(Light, HIGH);
}
void loop() {
{
if (digitalRead(Order_0) == HIGH)
Target == 156;
Serial.println("0 pressed");
}
{
if (digitalRead(Order_1) == HIGH)
Target == 789;
Serial.println("1 pressed");
}
Serial.println(Target);
}
The buttons are wired to a resistor as recommended in several places to avoid noise.
As said, I tested the wiring and the general function with the blink example.
Works exactly as expected.
Same for the outputs, they go to a relay board and act as expected.
It must be something very stupid I do in the code...
{
if (digitalRead(Order_0) == LOW)
Target == 156; << these only need 1 =
Serial.println("0 pressed");
}
{
if (digitalRead(Order_1) == LOW)
Target == 789; << these only need 1 =
Serial.println("1 pressed");
}