Lecture 2-2: Arduino Programming Dr. Kyung Eun Park Summer 2017 Arduino Language Reference: https://www.arduino.cc/en/Reference/HomePage
Arduino Programming Environment
Board Type Setting https://www.arduino.cc/en/Main/Software
Serial Port / COM Port
Arduino IDE Components
Parts of the Sketch
Operators Assignment Operator Equal Sign = : used to assign a value == : used to compare values if (a == 5)
Boolean Operators AND OR NOT && if ((a == 5) && (b == 10)) || ! if (!isCompleted)
Variable Declaration Syntax: Example: type variable_identifier; type variable_identifier = value; Example: int num; int sum = 0; int i = j = 0; int count = 0; double avg = sum/count ; char ch; char chSep = ','; boolean flag = false;
Arduino Function: setup() This setup() function comes before the loop function Need for all Arduino sketches Syntax: void setup() { … }
Arduino Function: pinMode(13,OUTPUT) Digital pins can be used as INPUT, INPUT_PULLUP, or OUTPUT Outputs are declared in setup(). Pin 13 is specified to behave as an output Syntax: pinMode(13, OUTPUT); Declares digital pin #13 as an output
Arduino Function: Serial.begin(9600) Serial communication begins in setup() Syntax: Serial.begin(9600); Declares Serial communication at a baud (bit per second) rate of 9600.
Digital I/O Function: digitalWrite(12,HIGH) Write a HIGH or a LOW value to a digital pin 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW Syntax: digitalWrite(12, HIGH); Sets pin #12 to HIGH
LED Program Sets pin 13 to HIGH, makes a one-second-long delay, and sets the pin back to LOW
Use Examples_Basics_Blink
Blink Example: verify and upload
Arduino MEGA Board with Blink Example https://www.facebook.com/noonmooltree/videos/1544160562295757/
Digital I/O Function: digitalRead(inPin) Reads the value from a specified digital pin, either HIGH or LOW Sets pin #13 to the same value as pin #7, declared as an input