Go Down

Topic: Serial Input confused on type SOLVED (Read 633 times) previous topic - next topic

grendle

Feb 20, 2013, 06:42 am Last Edit: Feb 20, 2013, 04:56 pm by grendle Reason: 1
this snippet works fine, ultimately I am trying to have it set up where I can enter 1 to 540, to represent minutes. This is my testing code. I type in "1" and get 49 blinks on the led instead of "1" blink. I understand why after looking at the asc chart, but, my problem is how can I make 'inByte' = "1". Have gone through the tut's on playground and started on Nick Gannons tut few minutes ago but brain is fried for tonight. So far I'm confused on how to approach this. Any wisdom would be greatly appreciated. Thanks.

Code: [Select]

char inByte; // Byte input from command prompt

void setup(){
 Serial.begin(9600);
 Serial.println("Enter number");
 while (!Serial.available()) {
 }
 inByte = Serial.read();

 Serial.println(inByte);

 for (int a=0; a<inByte; a++){
   digitalWrite(13,HIGH);
   delay(500);
   digitalWrite(13,LOW);
   delay(500);

 }

 Serial.println("Done");


}
void loop(){
}


daveclark5

i am a bit of newb.  but i don't understand why you are using a char instead of an int.  do you think that this is the ascii number your printing ? http://www.asciitable.com/

// from arduino forums http://arduino.cc/en/Serial/Read?action=sourceblock&num=1

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

Nick Gammon


... and started on Nick Gannons tut few minutes ago...


Nick Gammon

grendle

Quote
i am a bit of newb.  but i don't understand why you are using a char instead of an int

i tried that, same results. the following does not work
Code: [Select]
for (int a=0; a<inByte, DEC; a++){
like it works for serial print. thanks tho.

Quote
Nick Gammon

my apologies, no offense intended, i was really really tired last night when i posted, and this was an honest mistake.

PaulS

Code: [Select]
for (int a=0; a<inByte, DEC; a++){
What do you think "inByte, DEC" is doing? Not what you think, I'm pretty sure.

Go Up