Go Down

Topic: "for loop" on arduino  (Read 22 times) previous topic - next topic

Marinelamoche

Hi everybody, I have a little problem about "for loop" on my main program.

Code: [Select]

char code;

void setup()
{
  Serial.begin(9600);
}

void loop()
{

  while(Serial.available() <= 21){};
  for(int i = 0; i < 22; i++)
  {
    code = Serial.read();
    Serial.print(code);
  }
  Serial.print(code);
  delay(2000);
  Serial.flush();
}


I cant read the variable "code" outside of the "for loop", i can only read her value on the loop

PaulS

Quote
I cant read the variable "code" outside of the "for loop", i can only read her value on the loop
You change the value stored in the one variable 21 times. Only the last value will be available outside of the for loop.

Marinelamoche

Oh, ok
So how can i store these values on array and then read it outside the "for loop"

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy