Go Down

Topic: Set a variable with Serial Arduino (Read 163 times) previous topic - next topic

tdthien1997

Dec 20, 2018, 12:01 pm Last Edit: Dec 20, 2018, 12:10 pm by tdthien1997
i want something like
Code: [Select]

int i = 0;
void setup(){
  Serial.begin(9600);
}

void loop(){
  if(Serial.available()){ // if i input 1 to serial
    i = Serial.parseInt();
  }
  Serial.println(i); // i want my variable is set to 1 and display a list of 1
                          // if Serial change to 2, my value will change and display a list of 2
}

I'm new with arduino and don't know the best way to do this :(

Deva_Rishi

Check out the Serial examples (under communication) included with the IDE
To 'Correct' you have to be Correct. (and not be condescending..)

Go Up