Go Down

Topic: Serail monitor control problem (Read 636 times) previous topic - next topic

ahwahha

first, code...
Code: [Select]

void setup(){
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
}

int byteRead = 0;

void loop(){
  if(Serial.available()){
    byteRead = Serial.parseInt();
    if(byteRead>255)digitalWrite(13,HIGH);
    else analogWrite(13,byteRead);
    delay(500);
  }
}


problem:

when i input one value,
or if I input a series of value separated by space and when reading reach the last one
the LED have a second of delay ( someone tell me it is timeout ) before reacting to the last value.

when i put a space or any non digit at the end after the last value,
the LED have a second of delay after reacting to the last value and then turn off.

when i input a digit ( eg. 5 ) during that delay period of time,
the digit "added" to the last value ( eg. 25 ) to become a new value ( here: 25 + 5 = 255 )

So can any one tell me what the problem is and how to solve this
if I want the LED change the brightness at any moment immediately?

PaulS

Maybe you need to have a byte variable called intRead. Or maybe a float variable called charRead.

Quote
So can any one tell me what the problem is and how to solve this
if I want the LED change the brightness at any moment immediately?

Quit using parseInt().

ahwahha


Maybe you need to have a byte variable called intRead. Or maybe a float variable called charRead.

Quote
So can any one tell me what the problem is and how to solve this
if I want the LED change the brightness at any moment immediately?

Quit using parseInt().


how?

PaulS

Quote
how?

Simple, really. Highlight the code, and hit delete.

You need to write your own code that reads one character at a time from the serial port and stores it in an array, adding a NULL after each addition. When the character is the end of number/packet marker, call atoi() with the array, reset index, and NULL the array.

Go Up