Can't read an int in serial.

–3 votes
asked Feb 9, 2016 by leo-le-pogam (230 points)
edited Feb 9, 2016 by leo-le-pogam

I try to select a new frequence in console, it works for the 1st time and not after.

Plz help me :'(

The code:

// Pin 13 has an LED connected on most Arduino boards.
// const permet de fixer la variable
// preferable a #define
const int led = 6;
const int led2 = 5;
const int led3 = 23;

int delayM;

// the setup routine runs once when you press reset:
void setup()
{
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  delayM = 1000;
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop()
{
  if (Serial.available() > 0) {
            // read the incoming byte:
            delayM = Serial.read();
    }

  Serial.print(millis());
  Serial.print("ms LED allumee");
  Serial.print("\n");
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(led2, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(led3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(delayM);              // wait for a second
  Serial.print(millis());
  Serial.print("ms LED eteinte");
  Serial.print("\n");
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(led2, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(led3, LOW);    // turn the LED off by making the voltage LOW
  delay(delayM);               // wait for a second

}

1 Answer

0 votes
answered Feb 9, 2016 by alexa-noel (550 points)
Welcome to OpenWiNo Q&A, where you can ask questions and receive answers from other members of the community.
To change your password you must follow THIS link.

24 questions

32 answers

18 comments

37 users

...