Serial Understanding Experiments

The following code from https://www.arduino.cc/en/Serial/Read:

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, BIN);
}
}

—-

FOR BIN:

1,2,3 leads to:

I received: 110001
I received: 110010
I received: 110011

For OCT: 61,62,63

For HEX: 31,32,33

For DEC: 49,50,51

Serial.print(x, DEC);  // print as an ASCII-encoded decimal
Serial.print(x, HEX);  // print as an ASCII-encoded hexadecimal
Serial.print(x, OCT);  // print as an ASCII-encoded octal
Serial.println(x, BIN);  // print as an ASCII-encoded binary

Leave a Reply

Your email address will not be published. Required fields are marked *