Pemrograman Arduino - TeachMeSoft

Pemrograman Arduino




Daftar Isi


1 Functions (Fungsi)
   ↪ 1 Digital I/O
         --  digitalRead()
         --  digitalWrite()
         --  pinMode()
   ↪ 2 Analog I/O
         --  analogRead()
         --  analogReference()
         --  analogWrite()
   ↪ 3 Zero, Due & MKR Family
         --  analogReadResolution()
         --  analogWriteResolution()
   ↪ 4 Advanced I/O
         --  noTone()
         --  pulseIn()
         --  pulseInLong()
         --  shiftIn()
         --  shiftOut()
         --  tone()
   ↪ 5 Time
         --  delay()
         --  delayMicroseconds()
         --  micros()
         --  millis()
   ↪ 6 Math
         --  abs()
         --  constrain()
         --  map()
         --  max()
         --  min()
         --  pow()
         --  sq()
         --  sqrt()
   ↪ 7 Trigonometry
         --  cos()
         --  sin()
         --  tan()
   ↪ 8 Characters
         --  isAlpha()
         --  isAlphaNumeric()
         --  isAscii()
         --  isControl()
         --  isDigit()
         --  isGraph()
         --  isHexadecimalDigit()
         --  isLowerCase()
         --  isPrintable()
         --  isPunct()
         --  isSpace()
         --  isUpperCase()
         --  isWhitespace()
   ↪ 9 Random Numbers
         --  random()
         --  randomSeed()
   ↪ 10 Bits and Bytes
         --  bit()
         --  bitClear()
         --  bitRead()
         --  bitSet()
         --  bitWrite()
         --  highByte()
         --  lowByte()
   ↪ 11 External Interrupts
         --  attachInterrupt()
         --  detachInterrupt()
   ↪ 12 Interrupts
         --  interrupts()
         --  noInterrupts()
   ↪ 13 Communication
         --  Serial
         --  Stream
   ↪ 14 USB
         --  Keyboard
         --  Mouse

2 Variable
   ↪ 1 Constants
         --  Floating Point Constants
         --  Integer Constants
         --  HIGH | LOW
         --  INPUT | OUTPUT | INPUT_PULLUP
         --  LED_BUILTIN
         --  true | false
   ↪ 2 Conversion
         --  (unsigned int)
         --  (unsigned long)
         --  byte()
         --  char()
         --  float()
         --  int()
         --  long()
         --  word()
   ↪ 3 Data Types
         --  String()
         --  array
         --  bool
         --  boolean
         --  byte
         --  char
         --  double
         --  float
         --  int
         --  long
         --  short
         --  size_t
         --  string
         --  unsigned char
         --  unsigned int
         --  unsigned long
         --  void
         --  word
   ↪ 4 Variable Scope & Qualifiers
         --  const
         --  scope
         --  static
         --  volatile
   ↪ 5 Utilities
         --  PROGMEM
         --  sizeof()

3 Structure
   ↪ 1 Sketch
         --  loop()
         --  setup()
   ↪ 2 Control Structure
         --  break
         --  continue
         --  do...while
         --  else
         --  for
         --  goto
         --  if
         --  return
         --  switch...case
         --  while
   ↪ 3 Further Syntax
         --  #define (define)
         --  #include (include)
         --  /* */ (block comment)
         --  // (single line comment)
         --  ; (semicolon)
         --  {} (curly braces)
   ↪ 4 Arithmetic Operators
         --  % (remainder)
         --  * (multiplication)
         --  + (addition)
         --  - (subtraction)
         --  / (division)
         --  = (assignment operator)
   ↪ 5 Comparison Operators
         --  != (not equal to)
         --  < (less than)
         --  <= (less than or equal to)
         --  == (equal to)
         --  > (greater than)
         --  >= (greater than or equal to)
   ↪ 6 Boolean Operators
         --  ! (logical not)
         --  && (logical and)
         --  || (logical or)
   ↪ 7 Pointer Access Operators
         --  & (reference operator)
         --  * (dereference operator)
   ↪ 8 Bitwise Operators
         --  & (bitwise and)
         --  << (bitshift left)
         --  >> (bitshift right)
         --  ^ (bitwise xor)
         --  | (bitwise or)
         --  ~ (bitwise not)
   ↪ 9 Compound Operators
         --  %= (compound remainder)
         --  &= (compound bitwise and)
         --  *= (compound multiplication)
         --  ++ (increment)
         --  += (compound addition)
         --  -- (decrement)
         --  -= (compound subtraction)
         --  /= (compound division)
         --  ^= (compound bitwise xor)
         --  |= (compound bitwise or)






 1 Functions (Fungsi)


   ↪ 1 Digital I/O
         --  digitalRead()
         --  digitalWrite()
         --  pinMode()
   ↪ 2 Analog I/O
         --  analogRead()
         --  analogReference()
         --  analogWrite()
   ↪ 3 Zero, Due & MKR Family
         --  analogReadResolution()
         --  analogWriteResolution()
   ↪ 4 Advanced I/O
         --  noTone()
         --  pulseIn()
         --  pulseInLong()
         --  shiftIn()
         --  shiftOut()
         --  tone()
   ↪ 5 Time
         --  delay()
         --  delayMicroseconds()
         --  micros()
         --  millis()
   ↪ 6 Math
         --  abs()
         --  constrain()
         --  map()
         --  max()
         --  min()
         --  pow()
         --  sq()
         --  sqrt()
   ↪ 7 Trigonometry
         --  cos()
         --  sin()
         --  tan()
   ↪ 8 Characters
         --  isAlpha()
         --  isAlphaNumeric()
         --  isAscii()
         --  isControl()
         --  isDigit()
         --  isGraph()
         --  isHexadecimalDigit()
         --  isLowerCase()
         --  isPrintable()
         --  isPunct()
         --  isSpace()
         --  isUpperCase()
         --  isWhitespace()
   ↪ 9 Random Numbers
         --  random()
         --  randomSeed()
   ↪ 10 Bits and Bytes
         --  bit()
         --  bitClear()
         --  bitRead()
         --  bitSet()
         --  bitWrite()
         --  highByte()
         --  lowByte()
   ↪ 11 External Interrupts
         --  attachInterrupt()
         --  detachInterrupt()
   ↪ 12 Interrupts
         --  interrupts()
         --  noInterrupts()
   ↪ 13 Communication
         --  Serial
         --  Stream
   ↪ 14 USB
         --  Keyboard
         --  Mouse


1 Digital I/O

 digitalRead()


Description
Reads the value from a specified digital pin, either HIGH or LOW.

Syntax
digitalRead(pin)

Parameters
pin: the Arduino pin number you want to read

Returns
HIGH or LOW

Example Code
Sets pin 13 to the same value as pin 7, declared as an input.

int ledPin = 13;  // LED connected to digital pin 13
int inPin = 7;    // pushbutton connected to digital pin 7
int val = 0;      // variable to store the read value

void setup() {
  pinMode(ledPin, OUTPUT);  // sets the digital pin 13 as output
  pinMode(inPin, INPUT);    // sets the digital pin 7 as input
}

void loop() {
  val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);  // sets the LED to the button's value
}

If the pin isn’t connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly).

The analog input pins can be used as digital pins, referred to as A0, A1, etc. The exception is the Arduino Nano, Pro Mini, and Mini’s A6 and A7 pins, which can only be used as analog inputs.


digitalWrite()

Description
Write a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the Digital Pins tutorial for more information.

If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when calling digitalWrite(HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.

Syntax
digitalWrite(pin, value)

Parameters
pin: the Arduino pin number.
value: HIGH or LOW.

Returns
Nothing

Example Code
The code makes the digital pin 13 an OUTPUT and toggles it by alternating between HIGH and LOW at one second pace.

void setup() {
  pinMode(13, OUTPUT);    // sets the digital pin 13 as output
}

void loop() {
  digitalWrite(13, HIGH); // sets the digital pin 13 on
  delay(1000);            // waits for a second
  digitalWrite(13, LOW);  // sets the digital pin 13 off
  delay(1000);            // waits for a second
}

Notes and Warnings
The analog input pins can be used as digital pins, referred to as A0, A1, etc. The exception is the Arduino Nano, Pro Mini, and Mini’s A6 and A7 pins, which can only be used as analog inputs.


pinMode()

Description
Configures the specified pin to behave either as an input or an output. See the Digital Pins page for details on the functionality of the pins.

As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups.

Syntax
pinMode(pin, mode)

Parameters
pin: the Arduino pin number to set the mode of.
mode: INPUT, OUTPUT, or INPUT_PULLUP. See the Digital Pins page for a more complete description of the functionality.

Returns
Nothing

Example Code
The code makes the digital pin 13 OUTPUT and Toggles it HIGH and LOW

void setup() {
  pinMode(13, OUTPUT);    // sets the digital pin 13 as output
}

void loop() {
  digitalWrite(13, HIGH); // sets the digital pin 13 on
  delay(1000);            // waits for a second
  digitalWrite(13, LOW);  // sets the digital pin 13 off
  delay(1000);            // waits for a second
}

Notes and Warnings
The analog input pins can be used as digital pins, referred to as A0, A1, etc.


2 Analog I/O


 analogRead() 

Description
Reads the value from the specified analog pin. Arduino boards contain a multichannel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and the operating voltage(5V or 3.3V) into integer values between 0 and 1023. On an Arduino UNO, for example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit. See the table below for the usable pins, operating voltage and maximum resolution for some Arduino boards.

The input range can be changed using analogReference(), while the resolution can be changed (only for Zero, Due and MKR boards) using analogReadResolution().

On ATmega based boards (UNO, Nano, Mini, Mega), it takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

BOARDOPERATING VOLTAGEUSABLE PINSMAX RESOLUTION
Uno
5 Volts
A0 to A5
10 bits
Mini, Nano
5 Volts
A0 to A7
10 bits
Mega, Mega2560, MegaADK
5 Volts
A0 to A14
10 bits
Micro
5 Volts
A0 to A11*
10 bits
Leonardo
5 Volts
A0 to A11*
10 bits
Zero
3.3 Volts
A0 to A5
12 bits**
Due
3.3 Volts
A0 to A11
12 bits**
MKR Family boards
3.3 Volts
A0 to A6
12 bits**

*A0 through A5 are labelled on the board, A6 through A11 are respectively available on pins 4, 6, 8, 9, 10, and 12
**The default analogRead() resolution for these boards is 10 bits, for compatibility. You need to use analogReadResolution() to change it to 12 bits.

Syntax
analogRead(pin)

Parameters
pin: the name of the analog input pin to read from (A0 to A5 on most boards, A0 to A6 on MKR boards, A0 to A7 on the Mini and Nano, A0 to A15 on the Mega).

Returns
The analog reading on the pin. Although it is limited to the resolution of the analog to digital converter (0-1023 for 10 bits or 0-4095 for 12 bits). Data type: int.

Example Code
The code reads the voltage on analogPin and displays it.

int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read

void setup() {
  Serial.begin(9600);           //  setup serial
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  Serial.println(val);          // debug value
}

Notes and Warnings
If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).


 analogReference()
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:

Arduino AVR Boards (Uno, Mega, Leonardo, etc.)


  • DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
  • INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega32U4 and ATmega8 (not available on the Arduino Mega)
  • INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
  • INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
  • EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.


Arduino SAMD Boards (Zero, etc.)


  • AR_DEFAULT: the default analog reference of 3.3V
  • AR_INTERNAL: a built-in 2.23V reference
  • AR_INTERNAL1V0: a built-in 1.0V reference
  • AR_INTERNAL1V65: a built-in 1.65V reference
  • AR_INTERNAL2V23: a built-in 2.23V reference
  • AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference


Arduino megaAVR Boards (Uno WiFi Rev2)


  1. DEFAULT: a built-in 0.55V reference
  2. INTERNAL: a built-in 0.55V reference
  3. VDD: Vdd of the ATmega4809. 5V on the Uno WiFi Rev2
  4. INTERNAL0V55: a built-in 0.55V reference
  5. INTERNAL1V1: a built-in 1.1V reference
  6. INTERNAL1V5: a built-in 1.5V reference
  7. INTERNAL2V5: a built-in 2.5V reference
  8. INTERNAL4V3: a built-in 4.3V reference
  9. EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference


Arduino SAM Boards (Due)


  • AR_DEFAULT: the default analog reference of 3.3V. This is the only supported option for the Due.


Syntax
analogReference(type)

Parameters
type: which type of reference to use (see list of options in the description).

Returns
Nothing

Notes and Warnings
After changing the analog reference, the first few readings from analogRead() may not be accurate.

Don’t use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you’re using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead(). Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.

Alternatively, you can connect the external reference voltage to the AREF pin through a 5K resistor, allowing you to switch between external and internal reference voltages. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) = ~2.2V at the AREF pin.



 analogWrite()

Description
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady rectangular wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin.

BOARDPWM PINSPWM FREQUENCY
Uno, Nano, Mini
3, 5, 6, 9, 10, 11
490 Hz (pins 5 and 6: 980 Hz)
Mega
2 - 13, 44 - 46
490 Hz (pins 4 and 13: 980 Hz)
Leonardo, Micro, Yún
3, 5, 6, 9, 10, 11, 13
490 Hz (pins 3 and 11: 980 Hz)
Uno WiFi Rev.2
3, 5, 6, 9, 10
976 Hz
MKR boards *
0 - 8, 10, A3 (18), A4 (19)
732 Hz
MKR1000 WiFi *
0 - 8, 10, 11, A3 (18), A4 (19)
732 Hz
Zero *
3 - 13, A0 (14), A1 (15)
732 Hz
Due **
2-13
1000 Hz
101
3, 5, 6, 9
pins 3 and 9: 490 Hz, pins 5 and 6: 980 H

* In addition to PWM capabilities on the pins noted above, the MKR and Zero boards have true analog output when using analogWrite() on the DAC0 (A0) pin.
** In addition to PWM capabilities on the pins noted above, the Due has true analog output when using analogWrite() on pins DAC0 and DAC1.

You do not need to call pinMode() to set the pin as an output before calling analogWrite(). The analogWrite function has nothing to do with the analog pins or the analogRead function.

Syntax
analogWrite(pin, value)

Parameters
pin: the Arduino pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int.

Returns
Nothing

Example Code
Sets the output to the LED proportional to the value read from the potentiometer.

int ledPin = 9;      // LED connected to digital pin 9
int analogPin = 3;   // potentiometer connected to analog pin 3
int val = 0;         // variable to store the read value

void setup() {
  pinMode(ledPin, OUTPUT);  // sets the pin as output
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

Notes and Warnings
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g. 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.



3 Zero, Due & MKR Family


 analogReadResolution() 

Description
analogReadResolution() is an extension of the Analog API for the Arduino Due, Zero and MKR Family.

Sets the size (in bits) of the value returned by analogRead(). It defaults to 10 bits (returns values between 0-1023) for backward compatibility with AVR based boards.

The Due, Zero and MKR Family boards have 12-bit ADC capabilities that can be accessed by changing the resolution to 12. This will return values from analogRead() between 0 and 4095.

Syntax
analogReadResolution(bits)

Parameters
bits: determines the resolution (in bits) of the value returned by the analogRead() function. You can set this between 1 and 32. You can set resolutions higher than 12 but values returned by analogRead() will suffer approximation. See the note below for details.

Returns
Nothing

Example Code
The code shows how to use ADC with different resolutions.

void setup() {
  // open a serial connection
  Serial.begin(9600);
}

void loop() {
  // read the input on A0 at default resolution (10 bits)
  // and send it out the serial connection
  analogReadResolution(10);
  Serial.print("ADC 10-bit (default) : ");
  Serial.print(analogRead(A0));

  // change the resolution to 12 bits and read A0
  analogReadResolution(12);
  Serial.print(", 12-bit : ");
  Serial.print(analogRead(A0));

  // change the resolution to 16 bits and read A0
  analogReadResolution(16);
  Serial.print(", 16-bit : ");
  Serial.print(analogRead(A0));

  // change the resolution to 8 bits and read A0
  analogReadResolution(8);
  Serial.print(", 8-bit : ");
  Serial.println(analogRead(A0));

  // a little delay to not hog Serial Monitor
  delay(100);
}

Notes and Warnings
If you set the analogReadResolution() value to a value higher than your board’s capabilities, the Arduino will only report back at its highest resolution, padding the extra bits with zeros.

For example: using the Due with analogReadResolution(16) will give you an approximated 16-bit number with the first 12 bits containing the real ADC reading and the last 4 bits padded with zeros.

If you set the analogReadResolution() value to a value lower than your board’s capabilities, the extra least significant bits read from the ADC will be discarded.

Using a 16 bit resolution (or any resolution higher than actual hardware capabilities) allows you to write sketches that automatically handle devices with a higher resolution ADC when these become available on future boards without changing a line of code.



 analogWriteResolution()

Description
analogWriteResolution() is an extension of the Analog API for the Arduino Due.

analogWriteResolution() sets the resolution of the analogWrite() function. It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards.

The Due has the following hardware capabilities:


  • 12 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution.
  • 2 pins with 12-bit DAC (Digital-to-Analog Converter)


By setting the write resolution to 12, you can use analogWrite() with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over.

The Zero has the following hardware capabilities:


  • 10 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution.
  • 1 pin with 10-bit DAC (Digital-to-Analog Converter).


By setting the write resolution to 10, you can use analogWrite() with values between 0 and 1023 to exploit the full DAC resolution

The MKR Family of boards has the following hardware capabilities:


  • 4 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed from 8 (default) to 12-bit resolution.
  • 1 pin with 10-bit DAC (Digital-to-Analog Converter)


By setting the write resolution to 12 bits, you can use analogWrite() with values between 0 and 4095 for PWM signals; set 10 bit on the DAC pin to exploit the full DAC resolution of 1024 values.

Syntax
analogWriteResolution(bits)

Parameters
bits: determines the resolution (in bits) of the values used in the analogWrite() function. The value can range from 1 to 32. If you choose a resolution higher or lower than your board’s hardware capabilities, the value used in analogWrite() will be either truncated if it’s too high or padded with zeros if it’s too low. See the note below for details.

Returns
Nothing

Example Code
Explain Code

void setup() {
  // open a serial connection
  Serial.begin(9600);
  // make our digital pin an output
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  // read the input on A0 and map it to a PWM pin
  // with an attached LED
  int sensorVal = analogRead(A0);
  Serial.print("Analog Read) : ");
  Serial.print(sensorVal);

  // the default PWM resolution
  analogWriteResolution(8);
  analogWrite(11, map(sensorVal, 0, 1023, 0, 255));
  Serial.print(" , 8-bit PWM value : ");
  Serial.print(map(sensorVal, 0, 1023, 0, 255));

  // change the PWM resolution to 12 bits
  // the full 12 bit resolution is only supported
  // on the Due
  analogWriteResolution(12);
  analogWrite(12, map(sensorVal, 0, 1023, 0, 4095));
  Serial.print(" , 12-bit PWM value : ");
  Serial.print(map(sensorVal, 0, 1023, 0, 4095));

  // change the PWM resolution to 4 bits
  analogWriteResolution(4);
  analogWrite(13, map(sensorVal, 0, 1023, 0, 15));
  Serial.print(", 4-bit PWM value : ");
  Serial.println(map(sensorVal, 0, 1023, 0, 15));

  delay(5);
}

Notes and Warnings
If you set the analogWriteResolution() value to a value higher than your board’s capabilities, the Arduino will discard the extra bits. For example: using the Due with analogWriteResolution(16) on a 12-bit DAC pin, only the first 12 bits of the values passed to analogWrite() will be used and the last 4 bits will be discarded.

If you set the analogWriteResolution() value to a value lower than your board’s capabilities, the missing bits will be padded with zeros to fill the hardware required size. For example: using the Due with analogWriteResolution(8) on a 12-bit DAC pin, the Arduino will add 4 zero bits to the 8-bit value used in analogWrite() to obtain the 12 bits required.




4 Advanced I/O


 noTone() 


 pulseIn()


 pulseInLong()


 shiftIn()


 shiftOut()


 tone()






5 Time



 delay() 

 delayMicroseconds() 

 micros() 

 millis() 


6 Math


  abs() 

 constrain() 


 map() 


 max() 


 min() 


 pow() 


 sq() 


 sqrt() 




7 Trigonometry


 cos() 

 sin() 

 tan() 



8 Characters


 isAlpha() 

 isAlphaNumeric() 

 isAscii() 

 isControl() 

 isDigit() 

 isGraph() 

 isHexadecimalDigit() 

 isLowerCase() 

 isPrintable() 

 isPunct()

 isSpace() 

 isUpperCase() 

 isWhitespace() 



9 Random Numbers


 random() 

 randomSeed() 



10 Bits and Bytes



 bit() 

 bitClear() 

 bitRead() 

 bitSet()

 bitWrite() 

 highByte() 

 lowByte() 



11 External Interrupts



 attachInterrupt() 

 detachInterrupt() 



12 Interrupts


 interrupts() 

 noInterrupts() 



13 Communication



 Serial 

 Stream 




14 USB



 Keyboard 

 Mouse 





 2 Variable




   ↪ 1 Constants
         --  Floating Point Constants
         --  Integer Constants
         --  HIGH | LOW
         --  INPUT | OUTPUT | INPUT_PULLUP
         --  LED_BUILTIN
         --  true | false
   ↪ 2 Conversion
         --  (unsigned int)
         --  (unsigned long)
         --  byte()
         --  char()
         --  float()
         --  int()
         --  long()
         --  word()
   ↪ 3 Data Types
         --  String()
         --  array
         --  bool
         --  boolean
         --  byte
         --  char
         --  double
         --  float
         --  int
         --  long
         --  short
         --  size_t
         --  string
         --  unsigned char
         --  unsigned int
         --  unsigned long
         --  void
         --  word
   ↪ 4 Variable Scope & Qualifiers
         --  const
         --  scope
         --  static
         --  volatile
   ↪ 5 Utilities
         --  PROGMEM
         --  sizeof()





1 Constants


 Floating Point Constants 

 Integer Constants 

 HIGH | LOW 

 INPUT | OUTPUT | INPUT_PULLUP 

 LED_BUILTIN 

 true | false 



2 Conversion


 (unsigned int) 

 (unsigned long) 

 byte() 

 char() 

 float() 

 int() 

 long() 

 word() 



3 Data Types


 String() 

 array 

 bool 

 boolean  

 byte 

 char 

 double 

 float 

 int 

 long 

 short 

 size_t 

 string 

 unsigned char 

 unsigned int 

 unsigned long 

 void 

 word 



4 Variable Scope & Qualifiers


 const 

 scope 

 static 

 volatile 



5 Utilities


 PROGMEM 

 sizeof()







 3 Structure





   ↪ 1 Sketch
         --  loop()
         --  setup()
   ↪ 2 Control Structure
         --  break
         --  continue
         --  do...while
         --  else
         --  for
         --  goto
         --  if
         --  return
         --  switch...case
         --  while
   ↪ 3 Further Syntax
         --  #define (define)
         --  #include (include)
         --  /* */ (block comment)
         --  // (single line comment)
         --  ; (semicolon)
         --  {} (curly braces)
   ↪ 4 Arithmetic Operators
         --  % (remainder)
         --  * (multiplication)
         --  + (addition)
         --  - (subtraction)
         --  / (division)
         --  = (assignment operator)
   ↪ 5 Comparison Operators
         --  != (not equal to)
         --  < (less than)
         --  <= (less than or equal to)
         --  == (equal to)
         --  > (greater than)
         --  >= (greater than or equal to)
   ↪ 6 Boolean Operators
         --  ! (logical not)
         --  && (logical and)
         --  || (logical or)
   ↪ 7 Pointer Access Operators
         --  & (reference operator)
         --  * (dereference operator)
   ↪ 8 Bitwise Operators
         --  & (bitwise and)
         --  << (bitshift left)
         --  >> (bitshift right)
         --  ^ (bitwise xor)
         --  | (bitwise or)
         --  ~ (bitwise not)
   ↪ 9 Compound Operators
         --  %= (compound remainder)
         --  &= (compound bitwise and)
         --  *= (compound multiplication)
         --  ++ (increment)
         --  += (compound addition)
         --  -- (decrement)
         --  -= (compound subtraction)
         --  /= (compound division)
         --  ^= (compound bitwise xor)
         --  |= (compound bitwise or)





1 Sketch


 loop() 

 setup() 




2 Control Structure


 break 

continue 

 do...while 

 else 

 for 

 goto 

 if 

 return 

 switch...case 

 while 



3 Further Syntax


 #define (define) 

 #include (include) 

 /* */ (block comment) 

 // (single line comment) 

 ; (semicolon) 

 {} (curly braces) 







4 Arithmetic Operators


 % (remainder) 

 * (multiplication) 

 + (addition) 

 - (subtraction) 

 / (division) 

 = (assignment operator) 







5 Comparison Operators



 != (not equal to) 

 < (less than) 

 <= (less than or equal to) 

 == (equal to) 

 > (greater than) 

 >= (greater than or equal to) 




6 Boolean Operators



 ! (logical not) 

 && (logical and) 

 || (logical or) 




7 Pointer Access Operators



 & (reference operator) 

 * (dereference operator)




8 Bitwise Operators


  & (bitwise and) 

 << (bitshift left)


 >> (bitshift right)


 ^ (bitwise xor) 

 | (bitwise or)

 ~ (bitwise not)






9 Compound Operators



 %= (compound remainder)


&= (compound bitwise and)


 *= (compound multiplication)


 ++ (increment)


 += (compound addition)


 -- (decrement)


 -= (compound subtraction)


 /= (compound division)


 ^= (compound bitwise xor)


 |= (compound bitwise or)


















Sumber

  ➤  https://www.arduino.cc/reference/en/ 
  ➤
  ➤
  ➤ 




Disqus comments