Uploaded by Will Anderson

Introduction+to+Arduino+Programming

advertisement
Arduino Programming
Arduino Sketches
• Arduino programs are called Sketches
• C++ syntax
• Every sketch contains at least two functions:
setup and loop
setup()
• Runs once, when the sketch starts
• Used to specify pin assignments, communication
setup, servo attachments, etc.
• Example:
loop()
• Runs over and over again
• Main program, where all the action happens
• Example:
Arduino IDE
• Cross platform development environment
Serial Monitor
Arduino Commands—Digital I/O
pinmode(pin, mode)
• Configures specified pin as input or output
• mode = INPUT or OUTPUT
digitalRead(pin)
• Reads value from specified pin
• Return value is either HIGH or LOW
• e.g., value = digitalRead(pin);
digitalWrite(pin, value)
• Sets specified pin to value (HIGH or LOW)
• If pin is configured as input, HIGH value will enable
internal pull-up resistor
Example—Blink
Example—Button
Example—Blink
Example—Blink Without Delay
Example—Blink Without Delay
Arduino Commands
• https://www.arduino.cc/reference/en/
TinkerCAD
• Arduino simulation environment: tinkercad.com
Download