230 likes | 628 Views
AAR Workshop 1 Arduino Programming. ubcomechatronics@gmail.com. Objective. Program an arduino to control some LED's. Arduino. Source: http://www.arduino.cc/ http://www.raspberrypi.org/. The Arduino. Arduino Programming Interface.
E N D
AAR Workshop1 Arduino Programming ubcomechatronics@gmail.com
Objective Program an arduino to control some LED's Arduino Source: http://www.arduino.cc/ http://www.raspberrypi.org/
Arduino Programming Interface • Download and unzip from (~85 Mb): http://arduino.cc/en/Main/Software • Stand-alone application
Setting up Communication Select your Board type "Arduino Nano" Select where which port you connect the Arduino on
Quick Programming Intro • Variable Types: int, char, double, float • function structure: void setup() { Code here } void loop() { Code here }
Structure of an Arduino Program Declare and Initialize variables The Setup() function runs once, when the arduino is turned on, Select and Initialize the pinMode as either an Input pin or an output pin the loop() function loops repeatedly.
Important functions pinMode(int PinNumber, [INPUT|OUTPUT]) • Assigns an arduino pin as an input or output digitalWrite(int PinNumber, [LOW|HIGH]) • Sets a pin low or high analogWrite(int PinNumber, int Value [0-255]) • Sets the duty cycle for a pin
Pulse Width Modulation on Arduino PWM capable pins designated by tilde "~" - #11, 10,9, 6,5,3 on the uno - #3,5,6,9,10,11 on the nano
Your Basic Blink LED Example Loads of examples to get you started.
Programming Tasks 1) Blink LED 2) 2 LED Blink 4) 4 LED Sweep 5) 4 LED Progressive Brightness Tips: - Make separate functions to control speeds of blinking - Remember to make meaningful variable names!