I have a small project and I have some problems while working on that. The idea of the project is the followingas below: I have an LED which is commandedoperated by two "buttons". The buttons are basically 1/0takes two values (1 or0) which I have to send from Serial Monitorserial monitor. One button command ais for LDR sensor, which lights up the LED when its value is below 300 (in my code). The other button just lights the LED (Value 1) or turns it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the Serial Monitor to let me input the values for the two buttons separately,serial monitor it's just looping forevercontinuously and I cant type anything as input.
Can anybody, please,anyone help me with this to find a solution to be able to input values for both buttons?
const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;
int sensorValue = 0; //
char Buton1; //LDR button
char Buton2; //Blutooth button
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available())
{
Serial.println("Button1 value: ");
Buton1 = Serial.read();
if (Buton1 == '1')
{
Buton2 = Serial.read();
Serial.println("Button2 value: ");
Buton2 = Serial.read();
if (Buton1 == '1' and Buton2 == '0')
{
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
Serial.print ("Sensor: ");
Serial.println(sensorValue);
if (sensorValue < 300);
{
digitalWrite(digitalOutPin, 255);
}
}
else if (Buton1 == '1' and Buton2 == '1')
{
digitalWrite(digitalOutPin, 255);
Serial.print("Both buttons are ON ! !");
}
}
else if (Buton1 == '0')
{
Serial.println("Button2 value: ");
Buton2 = Serial.read();
}
if (Buton1 == '0' and Buton2 == '1')
{
digitalWrite(digitalOutPin, 255);
}
else if (Buton1 == '0' and Buton2 == '0')
{
Serial.println("Both buttons are inactive ! Please reset");
break;
}
}
}