Serial Commands
hi trying touchscreen control machine repetitive task. trying set can type in number of cycles want machine run , have machine run many times.
i doing using serial commands touchscreen side have serial.print(number); number int set when number hit on touch screen. set can type in number 1000 n - 0:999.
my problem when serial send sends value in ascii if hit 3 on touch screen , cycles = serial.read(); value of cycles 51. can work subtracting 48 incomming number, work values 0-9, cant send 12 or something. how can this? have attached sample code shows how using serial command on arduino side.
thanks!
int ledpin = 3; // led connected digital pin 13
int n=0;
// setup() method runs once, when sketch starts
void setup() {
// initialize digital pin output:
pinmode(ledpin, output);
serial.begin(9600);
}
void loop()
{
if( serial.available() > 0){
n = serial.read();
if(n>0){
serial.println(n);
for(int b=0; b<n-48; b++){
digitalwrite(ledpin, high); // set led on
delay(500); // wait second
digitalwrite(ledpin, low); // set led off
delay(300); // wait second
}
}
}
}
i doing using serial commands touchscreen side have serial.print(number); number int set when number hit on touch screen. set can type in number 1000 n - 0:999.
my problem when serial send sends value in ascii if hit 3 on touch screen , cycles = serial.read(); value of cycles 51. can work subtracting 48 incomming number, work values 0-9, cant send 12 or something. how can this? have attached sample code shows how using serial command on arduino side.
thanks!
int ledpin = 3; // led connected digital pin 13
int n=0;
// setup() method runs once, when sketch starts
void setup() {
// initialize digital pin output:
pinmode(ledpin, output);
serial.begin(9600);
}
void loop()
{
if( serial.available() > 0){
n = serial.read();
if(n>0){
serial.println(n);
for(int b=0; b<n-48; b++){
digitalwrite(ledpin, high); // set led on
delay(500); // wait second
digitalwrite(ledpin, low); // set led off
delay(300); // wait second
}
}
}
}
quote
i cant send 12 or something. how can this?
well, "12" sent 0x31 (49 decimal) , 0x32 (50 decimal).
the first digit has decimal weight of 101, , second decimal weight of 100.
you've correctly worked out worked how 100 case...
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Serial Commands
arduino
Comments
Post a Comment