Warmup – 16FEB2012 This one is for practice. I have paper if you need it. Suppose there are eight, single-pole, single-throw (SPST) switches connected.

Slides:



Advertisements
Similar presentations
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Advertisements

Lab7: Introduction to Arduino
Embedded Sumo 1T4 – 1T5 UTRA.
Programming Microcontrollers B. Furman 19MAR2011.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Digital Outputs 7-Segment Display
Analog and Digital Measurements living with the lab 14 digital input / output pins 6 analog input pins © 2011 LWTL faculty team.
Lecture – 7 Basic input and output
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
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.
Basic Circuits – Lab 2 Arduino and Sensors
Bit Masking To access or affect only the bits we want, we need to construct a byte with bits set in the locations of interest – This byte is called a ‘bit.
Microprocessors Tutorial 1: Arduino Basics
CHAPTER Wiring Schematics and Circuit Testing 9 Copyright © 2016 by Pearson Education, Inc. All Rights Reserved Automotive Electrical and Engine Performance,
Lab 1 - Microcontrollers Complete the program template below being sure to select the correct parameters to meet the requirements (see the Microcontroller.
Cascade switching of an LED EAS 199B Winter 2013.
Engineering 1040: Mechanisms & Electric Circuits Winter 2015 Interfacing Light-Emitting Diodes (LEDs) & Push Buttons to Microcontrollers.
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
Microprocessors Tutorial 1: Arduino Basics
1 - Remove LED from 13 and GND - Bring out your breadboard from HW#4 Arduino Overview:
ECE Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
MAKE: AN ELECTRONICS WORKSHOP
Arduino libraries Datatekniker Udvidet hardware/software.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
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.
Single pole Double throw (SPDT) Switch By: Engr.Irshad Rahim Memon.
Microcontroller basics Embedded systems for mortals.
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?
LAB1 TYWU. Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode.
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Arduino DC Motor Motion Control Instructor: Dr Matthew Khin Yi Kyaw.
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
: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 Transistor. 2 Transistors are used to turn components on and off They come in all different shapes and sizes.
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.
IOT Design: An Embedded System Overview MicroControllers
Switches Electronics 1 CVHS.
Microcontroller basics
Embedded Systems Programming Examples and Comparison
Microcontroller basics
JC Technology Components.
Cascade switching of an LED
Get Your Project Started with Arduino
European Robotic LABoratory
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Arduino.
Roller Coaster Design Project
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.
Week 6: Microcontrollers II
Continuing with LED’s and Arduino
using the Arduino to make LEDs flash
I/O Ports in AVR Sepehr Naimi
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
I/O Ports in AVR Sepehr Naimi
ADC and DAC Programming in AVR
Programming 2: The Arduino IDE & First Sketches
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Multiplexing seven-segment displays
Arduino Uno circuit basics
Setting up a basic program with Arduino
SAURABH GINGADE.
Arduino程式範例.
Interrupts.
Presentation transcript:

Warmup – 16FEB2012 This one is for practice. I have paper if you need it. Suppose there are eight, single-pole, single-throw (SPST) switches connected between the PORTD pins on the Arduino and ground. Write code (pseudocode first) to test and see if any one of the switches is closed. If any one of the switches is closed, turn on an LED on PB0. Single-pole/ single-throw (SPST) PoleThrow Single-pole/ double-throw (SPDT) Pole Throws Double-pole/ single-throw (DPST) Double-pole/ double-throw (DPDT) Poles:the number of separate circuits that can be controlled by the switch Throws: the number of separate connections that can be made by the movable switch element Arduino PD0 PD7 PB0

Solution – Arduino Style #include “me106.h” #define LED PIN_D8 // PB0 #define ON HIGH #define OFF LOW #define N_COUNT 1 void setup() { for (int i = 0; i <= 7; i++) { pinMode(i, INPUT); digitalWrite(i, HIGH); } pinMode(LED, OUTPUT); } void loop() { byte n_low = 0; for (int i = 0; i <= 7; i++) { if ( digitalRead(i) == LOW) { n_low++; } If ( n_low >= N_COUNT ) { digitalWrite( LED, ON); n_low = 0; } else { digitalWrite( LED, OFF); n_low = 0; } Arduino PD0 PD7 PB0 Setup pins: PD0 – PD7 make INPUTS Turn on pullup resistors for PD0-PD7 Setup pin PB0 as OUTPUT Loop forever for all eight pins (PD0-PD7) if pin i is LOW increment n_low counter end if end for loop if n_low value >= n_count Turn on LED reset n_low counter else Turn off LED reset n_low counter end if Pseudocode

Solution – PORT Style #include “me106.h” #define LED PIN_D8 // PB0 void setup() { DDRD = 0x00; PORTD | = 0xFF; DDRB | = ( 1 << 0 ); PORTB & = ( ~ (1 << 0 ) ); } void loop() { int current_state = PIND; if ( ( ~ current_state) & 0xFF ) ) { PORTB | = ( 1 << 0 ); } else { PORTB & = ~( 1 << 0 ); } Arduino PD0 PD7 PB0 Setup pins: PD0 – PD7 make INPUTS Setup pin PB0 as OUTPUT Loop forever get current state of PD0-PD7 if any of bits are zero turn on LED else Turn off LED end if Pseudocode

Add blinking LED Suppose there are eight, single-pole, single-throw (SPST) switches connected between the PORTD pins on the Arduino and ground. Write code (pseudocode first) to test and see if any one of the switches is closed. If any one of the switches is closed, blink an LED on PB0 at a rate of 1 Hz. Arduino PD0 PD7 PB0