arduino / ArduinoCore-samd

Arduino Core for SAMD21 CPU
GNU Lesser General Public License v2.1
473 stars 722 forks source link

SamdSercom tutorial has a bug: integer is read but only byte is sent #552

Open michaelshiloh opened 4 years ago

michaelshiloh commented 4 years ago

In the "Adding more Serial Interfaces to SAMD microcontrollers (SERCOM)" tutorial, in the section for "Create a new Serial instance", the example code shows:

  int sensorValue = analogRead(A0);
  // print out the value you read on mySerial wired in loopback:
  mySerial.write(sensorValue);

analogRead() will return values greater than 256 (assuming the resolution of the ADC is the default 10 bits) but the write() will only write a byte. This should be explained, and optionally scaled to fit in a byte.

michaelshiloh commented 4 years ago

error in tutorial could be confusing