Download presentation
Presentation is loading. Please wait.
Published byStewart Barton Modified over 9 years ago
1
Beginning Arduino Session 2 AN INTRODUCTION TO HACKING THE WORLD’S MOST POPULAR MICROCONTROLLER PLATFORM http://scn.sap.com/community/developer-center/hana/blog/2014/12/08/iot-with-sap-hana-dev
2
2.0 – Welcome and Introduction 2.1 – Components used in this Project. 2.2 – Exploring a Switch and its effects in a digital system. 2.3 – De-bouncing a switch 2.3.1 – Blink Without Delay 2.4 – Exploring the 4 main uses for a resistor 2.4.1 – Current Limiting 2.4.2 – Voltage Division 2.4.3 – Pull Down 2.4.4 – Pull Up Today’s Agenda
3
2.5 – Exploring Speakers and Piezo Buzzers 2.5.1 – How a speaker works vs a Piezospeaker 2.6 – PWM outputs, what are they? A detailed look into Pulse width Modulation 2.7 – The RGB LED 2.8 – Exploring Libraries. 2.9 – Using Tabs, creating our own Lib 2.10 – Using integer Arrays 2.11 – Bringing it all together: Name That Tune 2.12 – Serial Feedback 2.13 - Shields Today’s Agenda (cont.)
4
TAC Switch x 4 Peizo Buzzer x 1 RGB Breakout x 1 Components used in this Project.
5
Circuit:
6
When a switch is pressed in a circuit it casues the line voltage to “bounce” Bouncing
7
Sample of a switch press
8
When timing is crucial or multiple things need to happen during the void loop(), the delay() command can become a big problem. Open example > Basic > Blink Blink
9
void setup() { pinMode(13,OUTPUT); pinMode(9,OUTPUT); pinMode(2,INPUT); } Modify the Blink Sketch setup
10
void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second if(digitalRead(2) == LOW) digitalWrite(9,HIGH); else digitalWrite(9,LOW); } Modify the Blink Sketch loop
11
Open sketch examples > Digital > Blink without delay Blink Without delay()
12
Modify the sketch in the same way, what happens differently? Modify the sketch
13
Current Limiting Voltage Division Pull Down Pull Up Four Main uses for a Resistor
14
Current Limiting Resistor
15
Voltage Divider
16
Pull-UP
17
void setup() { pinMode(6,OUTPUT); } void loop() { if(digitalRead(2) == LOW) digitalWrite(6,HIGH); else digitalWrite(6,LOW); } Example of INPUT_PULLUP
18
The Piezo Buzzer
19
Pulse Width Modulation Is a DC voltage that is turned ON and OFF at different rates. The voltage has 2 states, 0 and Vcc PWM
21
A Low pass Filter will smooth a PWM signal back to a DC voltage. Low Pass Filter
22
Single Color Bi-Color Tri-Color RGB Types of LEDs
23
The RGB LED provided in your kit is mounted on a Breakout board. A breakout board provides all the nessesary supporting electronics so it can be used easily and quickly for proto typeing. The RGB LED with your Kit
24
void setup() { pinMode(6,OUTPUT); pinMode(9,OUTPUT); pinMode(10,OUTPUT); } void loop() { digitalWrite(9,HIGH); delay(300); digitalWrite(9,LOW); digitalWrite(10,HIGH); delay(300); digitalWrite(10,LOW); digitalWrite(6,HIGH); delay(300); digitalWrite(6,LOW); } RGB LED test
25
Libraries are chunks of code writen for specific, and often repetitive task. # include or # include “Lib_Name” Libraries
26
Go to – https://github.com/shirriff/Arduino-IRremote/releases Download the IRremote.zip file Download and install Libraries.
27
Method 1 Automatic – Go to Sketch > Input Library > Add Library. Navigate to the file just downloaded and select it. Method 2 Manually extract the Library and copy the folder to the Lib folder within the Arduino sketch folder. Two ways to install a Library
28
// Our Lib of Pitches #define NOTE_G1 49 #define NOTE_B2 123 #define NOTE_F3 175 #define NOTE_G4 392 Create a Library
29
An array is a collection of variables that are accessed with an index number. Arrays are Zero indexed. Arrays
30
// Call my Lib #include "pitches.h" // Define my Array int BP[] = {NOTE_G4, NOTE_B2, NOTE_F3, NOTE_G1}; Bringing it all together
31
// Declare my variabls int INDEX = 2; // Start button int redLEDPin = 9; int greenLEDPin = 10; int blueLEDPin = 6; Bringing it all together
32
// Set my pin modes void setup() { pinMode(2,INPUT_PULLUP); pinMode(3,INPUT_PULLUP); pinMode(4,INPUT_PULLUP); pinMode(5,INPUT_PULLUP); pinMode(13,OUTPUT); pinMode(redLEDPin,OUTPUT); pinMode(greenLEDPin,OUTPUT); pinMode(blueLEDPin,OUTPUT); } Bringing it all together
33
// My loop void loop() { if(digitalRead(INDEX) == LOW) { tone(8,BP[INDEX-2]); RGBWrite(random(100),random(100),random(100)) ; while(digitalRead(INDEX) == LOW) { } RGBWrite(0,0,0); noTone(8); } INDEX=INDEX+1; if(INDEX > 5) INDEX = 2; } Bringing it all together
34
Press keys in this order 1 – 2 – 3 – 4 – 2 Name that tune
35
There is 1 UART (universal asynchronous receiver/transmitter) on the Arduino Uno The Serial port uses Pin 0 and 1 Pin 0 = RX or Data Receive Pin 1 = TX or Data Transmit The USB connection uses the same UART Serial Feedback
36
int R = random(100); int G = random(100); int B = random(100); if(digitalRead(INDEX) == LOW) { Serial.print(INDEX); Serial.print("|"); Serial.print(R); Serial.print("|"); Serial.print(G); Serial.print("|"); Serial.println(B); // Serial.println() adds a line feed to the end tone(8,BP[INDEX-2]); RGBWrite(R,G,B) ; Add to the script
37
A Shield is a supportive board that plugs into the Arduino to extend the Arduino’s ability and reduces the amount of bread boarding needed. There’s a Shield for that…
38
http://shieldlist.org/ https://learn.sparkfun.com/tutorials/arduino-shields Shields
39
Challenge #1 – Use a switch-case and make specific colors light up based on the tone being played. Challenge #2 – Team up and use 8 buttons to make a 8 Key Keyboard Challenge #3 Use the Ir Lib to play sounds from your Remote. Challenge
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.