Arduino programming part1 - Computer Action...

13
living with the lab Introduc)on to Arduino Programming arduino.cc Gerald Recktenwald Portland State University [email protected]

Transcript of Arduino programming part1 - Computer Action...

living  with  the  lab  

Introduc)on  to    Arduino  Programming  

arduino.cc  

Gerald  Recktenwald  Portland  State  University  [email protected]  

references  these  notes  borrow  from  .  .  .  –  Arduino  web  site  

•  h@p://arduino.cc/en/Guide/Environment  •  h@p://arduino.cc/en/Tutorial/HomePage  

–  Adafruit  tutorial  #1  and  2  •  h@p://www.ladyada.net/learn/arduino/lesson2.html  

–  Leah  Buechley’s  Introduc)on  to  Arduino  •  h@p://web.media.mit.edu/~leah/LilyPad/03_arduino_intro.html  

living  with  the  lab  

2  

wri)ng  and  downloading  code  

living  with  the  lab  

3  

running  Code  while  tethered  

living  with  the  lab  

4  

running  code  stand-­‐alone  

living  with  the  lab  

5  

Arduino  IDE  IDE  =    Integrated                Development                Environment  

http://www.arduino.cc/en/Guide/Environment!

living  with  the  lab  

6  

code  structure:  header  

header  provides  informa)on  and  can  also  contain  code  

living  with  the  lab  

7  

code  structure:  setup  func)on  

setup  func)on  is  executed  only  once  at  the  start  

living  with  the  lab  

8  

code  structure:  loop  func)on  

loop  func)on  is  repeated  indefinitely  

living  with  the  lab  

9  

code  

digital  I/O  func)ons:  •  pinMode  •  digitalWrite  •  digitalRead  

pinMode(13, Output)!prepares  pin  13  for  outputs  of  voltage  

living  with  the  lab  

10  

digitalWrite(13, HIGH)!sets  pin  13  to  a  voltage  that  means  “on”    (five  volts  in  this  case)  

living  with  the  lab  

11  

code  

digital  I/O  func)ons:  •  pinMode  •  digitalWrite  •  digitalRead  

delay(1000);!tells  microcontroller  to  do  nothing  for  1000  ms  =  1  s  

code  

living  with  the  lab  

12  

digital  I/O  func)ons:  •  pinMode  •  digitalWrite  •  digitalRead  

digitalWrite(13, LOW) !sets  pin  13  to  voltage  that  means  “off”  or  zero  volts  

living  with  the  lab  

13  

digital  I/O  func)ons:  •  pinMode  •  digitalWrite  •  digitalRead  

code