Finish your programs from last week STOPLIGHT CIRCUIT! You may need … – int – void setup() – void loop() – pinMode – digitalWrite – delay.

Slides:



Advertisements
Similar presentations
Wireless Cue Light Project
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Lab7: Introduction to Arduino
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
ELCT 201 week 13 Analog ON/OFF control system conversion to Digital ON/OFF control system.
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.
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.
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.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 2 Topics: Serial Communication Programming Constructs: functions, loops and conditionals Digital Input.
chipKit Sense Switch & Control LED
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Introduction to the Arduino
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Cascade switching of an LED EAS 199B Winter 2013.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
Code The Arduino Environment.
Programming, Serial and Virtual Prototyping. Code if ( You like semicolons ) { Stay here for intro to Arduino code } else { Join the MODKit group for.
Arduino libraries Datatekniker Udvidet hardware/software.
Photoresistor resistance changes dramatically with light level living with the lab Using Photoresistors with an Arduino © 2011 LWTL faculty team.
Microcontroller basics Embedded systems for mortals.
Week 5: Microcontrollers & Flow Control Bryan Burlingame 2 March 2016.
Microcontroller basics Embedded systems for mortals.
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?
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
:Blink Blink: Er. Sahil Khanna
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Hacking on Arduino George Patterson
Introduction to Physical Computing
Assist. Prof. Rassim Suliyev - SDU 2017
More on LED’s with Arduino
Val Manes Department of Math & Computer Science
Microcontroller basics
Wireless Cue Light Project
Cascade switching of an LED
Welcome to Arduino A Microcontroller.
Get Your Project Started with Arduino
European Robotic LABoratory
UCD ElecSoc Robotics Club 2017/2018
INC 161 , CPE 100 Computer Programming
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Continuing with LED’s and Arduino
IoT Programming the Particle Photon.
Programming, Serial and Virtual Prototyping
Servos and Stepper Motors
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Welcome to Digital Electronics using the Arduino Board
Topics: Programming Constructs: loops & conditionals Digital Input
Arduino Part #3 Variables
Programming 2: The Arduino IDE & First Sketches
Arduino Part 4 Let there be more light.
Arduino Uno circuit basics
Setting up a basic program with Arduino
SAURABH GINGADE.
Arduino程式範例.
Interrupts.
Arduino Programming: “if” statements
Presentation transcript:

Finish your programs from last week STOPLIGHT CIRCUIT! You may need … – int – void setup() – void loop() – pinMode – digitalWrite – delay

A Game The rules: We will present a scenario and it is your job to figure out what happened. You can ask questions that can be answered with a true or a false.

What Happened? Mr. Brown was spending the night in a hotel in a strange city. He had never been there before and didn't know anyone in the hotel or the city. He had great difficulty getting to sleep. No matter what, he couldn’t fall asleep. He had a busy day ahead and wanted to have a good night of sleep. He made one local telephone call and shortly thereafter he fell into peaceful slumber. Why?

Solution He couldn't go to sleep because the man next door was having a party. Brown called the night clerk, who went to end the party. When the noise stopped, Mr. Brown had no trouble in dozing off. Computer programming is like this game because we are limited to asking the computer yes/no questions.

If Statement (Conditional Statement) Allows you to make something happen or not depending on whether a given condition is true or not. – Example: Every Friday I nap for 2 hours. – What is the true/false question here? if (day == Friday) { naptime = 2; } What is the difference between = and == ? apples = 5; // ASSIGNS the value 5 to the variable // called apples apples == 5; // LOGICAL statement. Asks, “is the value of // apples 5?” if it is, apples == 5 is TRUE. What will apples == 4 return?

IF-ELSE On Fridays I nap for 2 hours, but every other day I nap for 1 hour. if (day==Friday) { naptime = 2; } else { naptime = 1; } Why are some of the equal signs double (==) and some of them just single (=)?

IF -ELSE-IF On Fridays I nap for 2 hours. On Saturdays, I don’t nap at all. Every other day I nap for 1 hour. if (day == Friday) { naptime = 2; } else if (day == Saturday) { naptime = 0; } else { naptime = 1; }

Recap IF (SOME CONDITION IS TRUE) { //do something } ELSE IF (SOME OTHER CONDITION IS TRUE) { //do something else! } ELSE { //do some other stuff } CONDITIONAL OPERATORS x == y (x is equal to y) x != y (x is not equal to y) x < y (x is less than y) x > y (x is greater than y) x <= y (x is less than or equal to y) x >= y (x is greater than or equal to y)

Let’s Practice So far we’ve only used digitalWrite – to OUTPUT a value on a digital pin. Now we want to read a value. We’ll connect a button to a pin What values can the button have? – HIGH or LOW 5V Arduino Digital pin

Program Outline What happens when we push the button? if (button_value == LOW) { //turn light OFF } else if (button_value == HIGH) { // turn light on! }

Let’s Write the Program! Open a new sketch What three parts does your program need? – Define variables – Run setup – Run loop

“Vocabulary” What functions do we know already? – digitalWrite – pinMode – delay Today we’ll add: – digitalRead – if/else (not a function, but a control statement)

int ledPin = 13; // LED connected to digital pin 13 int buttonPin = 7; // pushbutton connected to // digital pin 7 int buttonState = 0; // variable to store the read value void setup() { // set the digital pin 13 as output pinMode(ledPin, OUTPUT); // set the digital pin 7 as input pinMode(buttonPin, INPUT); }

void loop() { // read the input pin buttonState = digitalRead(buttonPin); // Determine if we should turn on the LED if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }

Recap IF (SOME CONDITION IS TRUE) { //do something } ELSE IF (SOME OTHER CONDITION IS TRUE) { //do something else! } ELSE { //do some other stuff } CONDITIONAL OPERATORS x == y (x is equal to y) x != y (x is not equal to y) x < y (x is less than y) x > y (x is greater than y) x <= y (x is less than or equal to y) x >= y (x is greater than or equal to y)