Arduino Part 1: Topics: Microcontrollers Programming Basics: Structure and Variables Digital Output
Arduino Part 1: Topics: Microcontrollers Programming Basics: Structure and Variables Digital Output
Topics:
Microcontrollers
Programming Basics: structure and variables
Digital Output
What is a Microcontroller
Making-robots-with-arduino.pdf
What is the Arduino
What is Arduino?
todbot.com/blog/bionicarduino
Arduino Integrated Development Environment (IDE)
Parts of the IDE
• Compile –Before the program “code” can be sent to the
board, it needs to be converted into instructions that the
board understands. This process is called compiling.
• Stop - This stops the compilation process.
• Create new Sketch - This opens a new window to create a
new sketch.
• Open Existing Sketch - This loads a sketch from a file on
your computer.
• Save Sketch- This saves the changes to the sketch you are
working on.
• Upload to Board - This compiles and then transmits over
the USB cable to your board.
• Serial Monitor
• Tab Button - This lets you create multiple files in your
sketch.
• Sketch Editor - This is where you write or edit sketches
• Text Console - This shows you what the IDE is currently
doing and is also where error messages display if you make
a mistake in typing your program. (often called a syntax
error)
• Line Number -This shows you what line number your
cursor is on. It is useful since the compiler gives error
messages with a line number
Select Serial Port and Board
Status Messages
Add an External LED to pin 13
www.instructables.com
A Little Bit About Programming
• Code is case
sensitive
• Statements are
commands and
must end with a
semi-colon
Our First Program
// Example 01
/*
Blinking Onboard LED
Turns on the onboard LED on for one second, then off for one second, repeatedly.
*/
// Digital Pin 13 has an LED connected on your Tinkduino.
int LED = 13;
www.mikroe.com/chapters/view/1
pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
digitalRead(pin)
Reads HIGH or LOW from a pin
digitalWrite(pin, value)
Writes HIGH or LOW to a pin
Electronic stuff
Output pins can provide 40 mA of current
Writing HIGH to an input pin installs a 20KΩ pullup
Arduino Timing
• delay(ms)
– Pauses for a few milliseconds
• delayMicroseconds(us)
– Pauses for a few microseconds
Digital? Analog?
• Digital has two values: on and off
• Analog has many (infinite) values
• Computers don’t really do analog, they quantize
• Remember the 6 analog input pins---here’s how
they work
todbot.com/blog/bionicarduino
Bits and Bytes
Variables
www3.ntu.edu.sg
Putting It Together
• Complete the sketch
(program) below.
• What output will be
generated by this program?
• What if the schematic were
changed?
www.ladyada.net/learn/arduino