int first_led = 2;
int second_led = 3;
int third_led = 4;
int fourth_led = 5;
int val = 0;
void setup(){
Serial.begin(9600);
pinMode(first_led,OUTPUT);
pinMode(second_led,OUTPUT);
pinMode(third_led,OUTPUT);
pinMode(fourth_led,OUTPUT);
}
void loop()
{
if(Serial.available()>0) {
val = Serial.read();
Serial.println(val);
}
if(val == 1){
digitalWrite(first_led, HIGH);
delay(1000);
digitalWrite(second_led, HIGH);
delay(1000);
digitalWrite(third_led, HIGH);
delay(1000);
digitalWrite(fourth_led, HIGH);
delay(1000);
}else{
digitalWrite(first_led, LOW);
delay(1000);
digitalWrite(second_led, LOW);
delay(1000);
digitalWrite(third_led, LOW);
delay(1000);
digitalWrite(fourth_led, LOW);
delay(1000);
}
}
Hello jamyneck643
It seems to be a school assigment, isn´t it?
And your questions is?
It is very unlikely that val will ever be 1 with serial data from serial monitor. What does the Serial.read() return?
No sure with your problem kindly properly elaborate and is it a assignment given to u to help u further
my question, how to user input work?
Hello jamyneck643
Generaly spoken the sketch needs the following basic functions:
- command line interpreter
- a FSM
- a timer modul with associated functions like startTimer() and stopTimer().
- some arrays for the prepared led states to be used.
Have a nice day and enjoy coding in C++.
Дайте миру шанс!
1 Like
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.