1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.

Slides:



Advertisements
Similar presentations
Khaled A. Al-Utaibi Interfacing an LED The Light Emitting Diode (LED) Applications DC Characteristics & Operation Interfacing to.
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Electrical team Arduino tutorial I BY: JOSHUA arduini
Lab7: Introduction to Arduino
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Embedded Sumo 1T4 – 1T5 UTRA.
Vex Robotics Introduction to Sensors. introduction to sensors Sensors assist robots in seeing and feeling the physical world through which they travel.
Using the Arduino to Make an LED Flash Work in teams of two! living with the lab digital I/O pins (I/O = input / output) USB cable plug power pins.
Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will.
Living with the lab Introduction to Arduino Programming arduino.cc Gerald Recktenwald Portland State University
Method exercises Without IF. Setup Create one new project to hold all of these. In that project, create an empty class called WorkIt to hold all of your.
Analog and Digital Measurements living with the lab 14 digital input / output pins 6 analog input pins © 2011 LWTL faculty team.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Embedded Programming and Robotics
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
chipKit Sense Switch & Control LED
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Introduction to the Arduino
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Code The Arduino Environment.
Microcontroller Hands-on Workshop #2 Ahmad Manshad New Mexico State University Institute of Electrical and Electronics Engineers October 31, 2009.
Microcontrollers, Microcomputers, and Microprocessors
Arduino libraries Datatekniker Udvidet hardware/software.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Microcontroller basics Embedded systems for mortals.
1 Introduction to Haptics Introduction to the Hapkit board Allison M. Okamura Stanford University.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Robotics Grant Agreement No LLP UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning in Mechatronics Technology.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Arduino Training For You! Learn Programming at Your Own Pace! Chapter 1 A course developed from the text book: “Introduction to Arduino A Piece of Cake!”
:Blink Blink: Er. Sahil Khanna
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
ME 120: Arduino Programming Arduino Programming Part 1 ME 120 Mechanical and Materials Engineering Portland State University
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Using a SparkFun™ serial LCD with an Arduino
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Val Manes Department of Math & Computer Science
Microcontroller basics
Arduino Programming Part II
An Arduino Workshop A Microcontroller.
Welcome to Arduino A Microcontroller.
UCD ElecSoc Robotics Club 2017/2018
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
Arduino.
Introduction to Arduino Microcontrollers
Introduction to Arduino Microcontrollers
ARDUINO     What is an Arduino? Features 14 Digital I/O pins 6 Analogue inputs 6 PWM pins USB serial 16MHz Clock speed 32KB Flash memory 2KB SRAM.
Arduino 101 Credit(s):
using the Arduino to make LEDs flash
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Welcome to Digital Electronics using the Arduino Board
Arduino Part #3 Variables
Programming 2: The Arduino IDE & First Sketches
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Aeroponic Engineering and Vertical Farming
Lab #1: Getting Started.
Arduino Uno circuit basics
Setting up a basic program with Arduino
Introduction to Arduinos
SAURABH GINGADE.
Arduino程式範例.
Introduction to Arduino IDE and Software
Downloading to the NXT requires the correct hardware setup
Presentation transcript:

1 Introduction to Coding

2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than being created from scratch

3 Blink A simple code used to blink an LED plugged into pin 13 The following slides will go through the ‘blink’ code in detail, line by line

4 Comments The first lines of code are displayed in gray This indicates that they are comments for humans to read and not part of the actual code

5 Comments There are 2 ways to incorporate a comment into a code // - Single line comment /* */ - Multiline comment where everything between the two asterisks is part of the comment

6 Variables The next line of code introduces a variable called ‘led’ and sets it equal to 13 The name of the variable is chosen by the programmer In this case ‘x = 13’ or ‘table = 13’ would all suffice It is common to choose a variable name that correlates to what it is being used for In this case 13 will represent the pin the LED is plugged into

7 Variables The word ‘int’ preceding the variable name is used to tell the Arduino what we plan on storing in the variable ‘led’ A variable of the ‘int’ type can store any integer between 32,768 and -32,768. It cannot store a fraction or decimal A variable of the ‘long’ type has a range of -2,147,483,648 to 2,147,483,648. However, it uses up more memory In this case, in order to declare the variable ‘led’ as a ‘long’ type we would have written long led = 13; A variable of the ‘float’ type has a range of E+38 and E+38. It can contain decimals (float led = 13; )

8 Routines Each Arduino program is called a SKETCH and has two required functions, called ROUTINES. One is the ‘setup’ and one is the ‘loop’ Each routine is preceded by the word ‘void’ and followed with a set of parentheses ‘( )’ and curly braces ‘{ }’ void setup ( ) { } - All of the code within the curly braces is part of the setup and runs once when the program begins. void loop ( ) { } - This function is run AFTER the setup has finished. All of the code within the curly braces will be run repeatedly until power is removed.

9 pinMode In this routine there is only one line of code, ‘pinMode’ Each digital pin 0 – 13 can act as either an Input or an Output to your system, and needs to be declared as either This is because fundamentally Inputs and Outputs behave as opposites. An Input is ready to absorb energy sent into it by a sensor, while an Output contains higher amounts of energy waiting to be spit out and turn something on In this case pin 13 is an Output since we have an LED plugged in there. We can use the variable ‘led’ in place of the number thirteen since we already declared led = 13;

10 digitalWrite The next piece of code is the ‘void loop’ routine of the sketch Once a pin is set to output it can be set to either HIGH (5 Volts) or LOW(0 volts). This essentially means turn ON or OFF. There are two pieces of information in the line of code: the pin we want to control and whether is should be on or off We have declared led= 13 so we can write ‘led’ as the pin # HIGH means to turn on the pin, or send out 5V through pin 13

11 delay The next line of code is the ‘delay ’ function This is used when we want the Arduino to pause and not perform any action The delay is measured in microseconds, so 1000 = 1 second In this ‘loop’ the first line turns on a led plugged into pin 13, and the second line tells the controller to wait for 1 second

12 Run To compile your sketch, click the checkmark. Make sure your Arduino is plugged into an available USB port. Click the arrow to download the program to Arduino. If everything is attached correctly. The LED should blink.