readBytes()/ readBytesuntill()
Read data using readbytes function and multiply two number.
int iB = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
char sdata[2];
// send data only when you receive data:
if (Serial.available()==2) {
// read the incoming byte:
iB = Serial.readBytes(sdata, 2);
// say what you got:
Serial.print("I received: ");
Serial.println(sdata[0], DEC);
Serial.println(", ");
Serial.println(sdata[1], DEC);
if(1)
{
int a,b,c;
a=sdata[0]-'0';
b=sdata[1]-'0';
c=a*b;
Serial.print("Operation of number is:");
Serial.println(c,DEC);
}
}
}
int iB = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
char sdata[10];
// send data only when you receive data:
if (Serial.available()==2) {
// read the incoming byte:
iB = Serial.readBytesUntil('=',sdata, 3);
// say what you got:
Serial.print("I received: ");
Serial.println(sdata[0], DEC);
Serial.println(", ");
Serial.println(sdata[1], DEC);
if(1)
{
int a,b,c;
a=sdata[0]-'0';
b=sdata[1]-'0';
c=a*b;
Serial.print("Operation of number is:");
Serial.println(c,DEC);
}
}
}
Comments
Post a Comment