GETTING STARTED WITH ARDUINO PROGRAMMING PART 5

PAGE 5

Serial.println:

Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or ‘\r’) and a newline character (ASCII 10, or ‘\n’). This command takes the same forms as Serial.print().

Syntax: Serial.println(val), Serial.println(val, format)

Parameters:

  1. val: the value to print – any data type
  2. format: specifies the number base (for integral data types) or number of decimal places (for floating point types)
  3. Returns: size_t (long): println() returns the number of bytes written, though reading that number is optional

Serial.readString:

Serial.readString() reads characters from the serial buffer into a string. The function terminates if it times out (see setTimeout()). This function is part of the Stream class, and is called by any class that inherits from it (Wire, Serial, etc). See the Stream class main page for more information.

Syntax: Serial.readString()

Parameters:

  1. None
  2. Returns: A string read from the serial buffer

“Note:for serial interrupt use this method serialEvent() whereas the processor goes to this ISR and executes the statements inside and rolls back to its previous task after completion.”

INTERRUPTS:

As we know that Interrupt means sudden change in any current running task either by hardware and software. Similarly these Arduino boards have different Interrupts. Here we are considering only the GPIO hardware interrupts.

attachInterrupt:

Digital Pins With Interrupts The first parameter to attachInterrupt is an interrupt number. Normally you should use digitalPinToInterrupt(pin) to translate the actual digital pin to the specific interrupt number. For example, if you connect to pin 3, use digitalPinToInterrupt(3) as the first parameter to attachInterrupt.

Board Digital Pins Usable For Interrupts
Uno, Nano, Mini, other 328-based 2, 3
Mega, Mega2560, MegaADK 2, 3, 18, 19, 20, 21
Micro, Leonardo, other 32u4-based 0, 1, 2, 3, 7
Zero all digital pins, except 4
Due all digital pins

Note: Inside the attached function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.”

Goto Page 4 Goto Page 6

Leave a Reply