SlideShare a Scribd company logo
Re-programming the Simon Says
with Arduino
Linz Craig, Brian Huang
Agenda
• About us / Introductions
• Software Installation
• What can it do? Who cares?
• Blink Sketch  Disco Lights
• Using Variables
• If() statement  reading buttonPress
• Analog Sensors  Fading
• Making Sound
About Us
SparkFun Electronics is all about creation,
innovation and sharing information. We
want to get you excited about cutting edge
electronics technology with our hands on
educational kits.
Arduino Board
“Strong Friend” Created in Ivrea, Italy
in 2005 by Massimo Banzi & David Cuartielles
Open Source Hardware
Atmel Processor
Coding is accessible (C++, Processing, ModKit and MiniBloq)
Arduino Software Installation
Open Source
Free
Available on-line with resources at:
www.arduino.cc
What can it do?
•Great for prototyping ideas
•Access to multiple I/O
•Drive motors, turn on lights,
trigger controls.
•Low Power requirements
•Flexible / Open-source
Who cares?
Hackers / Makers
Engineers
Artists
Musicians
Kids!
Teachers!!
You!!!
Setup Board Type
Tools → Board → Arduino Uno
Setup Serial COM Port
Tools → Serial Port →
Notes:
PC –
Highest COM #
Mac –
/dev/tty.usbserial-A####xxx
Analog and Digital
• All Arduino signals are either Analog or
Digital
• All computers including Arduino, only
understand Digital
• It is important to understand the difference
between Analog and Digital signals since
Analog signals require an Analog to Digital
conversion
Input vs. Output
Everything is referenced from the perspective of the
microcontroller.
Inputs is a signal going into the board.
Output is any signal exiting an electrical system
• Almost all systems that use physical computing will
have some form of output
• Often – Outputs include LEDs, a motor, a servo, a
piezo element, a relay and an RGB LED
Basic Program
Two required routines /
methods / functions:
void setup()
{
// runs once
}
void loop()
{
// repeats forever!!!
}
upload
Let’s get to hacking…
Project #1 – Blink
“Hello World” of Physical Computing
Psuedo-code – how should this work?
Turn
LED ON
Wait
Turn
LED
OFF
Wait
Rinse &
Repeat
Three commands to know…
pinMode(pin, INPUT/OUTPUT);
ex: pinMode(13, OUTPUT);
digitalWrite(pin, HIGH/LOW);
ex: digitalWrite(13, HIGH);
delay(time_ms);
ex: delay(2500);
LED1 = ~3;
LED2 = ~5;
LED3 = ~10;
LED4 = 13;
Can you figure out which LED is tied to
which pin? Write down a few notes in your
notebook!
3
5
13
LED Pin Configurations
10
Output is always Digital
To output a signal that pretends to be Analog
use this code:
analogWrite (pinNumber, value );
Where pin is one of the analog output pins: 3,
5, 6, 9, 10, 11
Where value is a number ranging from: 0 –
255.
Output is always Digital
(ON or OFF)
Using a Digital signal that pretends to be an Analog
signal is called Pulse Width Modulation (PWM)
By varying the duty cycle, we can “fake” an analog
signal output.
PWM is available on Arduino pins # 3, 5, 6, 9, 10, and
11
P.W.M. Signal @ 25% P.W.M. Signal @ 75% P.W.M. Signal rising
SIMON_2b_BLINK
Using Variables
To clean-up code, for read-ability, and flexibility
– we can create placeholders in code.
Example:
int ledPin = 3;
void setup(){
pinMode(ledPin, OUTPUT);
}
void loop(){
digitalWrite(ledPin, HIGH);
}
Digital Input
int button_state = digitalRead(ButtonPin);
Value will be either: HIGH or LOW
Reading a button press
Button Input is normally
HIGH – when you press
it, you pull it LOW.
The Code:
int buttonPress = digitalRead(2);
Activating the Internal Pull-up
Resistor
pinMode(pin, INPUT_PULLUP);
ex: pinMode(2, INPUT_PULLUP);
Notes:
BUTTON1 = 2;
BUTTON2 = 6;
BUTTON3 = 9;
BUTTON4 = 12;
BUTTON1 = 2;
BUTTON2 = 6;
BUTTON3 = 9;
BUTTON4 = 12;
Can you figure out which Button is tied to
which pin? Write down a few notes in your
notebook!
2
6
12
Button Pin Configurations
9
Conditional Statements
If…
General Use
if(condition)
{
// do this
}
Example
if(button_State==HIGH)
{
digitalWrite(ledPin,
HIGH);
delay(300);
digitalWrite(ledPin,
LOW);
delay(300);
}
Digital Input
• To connect digital input to your Arduino use Digital
Pins # 0 – 13 (Although pins # 0 & 1 are also used
for serial)
• Digital Input needs a pinMode command:
pinMode ( pinNumber, INPUT );
Make sure to use caps for INPUT
• To get a digital reading: digitalRead ( pinNumber );
• Digital Input values are only HIGH (On) or LOW (Off)
Last bit… the buzzer
SIMON_3_BUZZER
Final command to know:
tone(pin, freq, duration);
pin – the OUTPUT pin the buzzer is
connected to.
freq – unsigned int (0 … 65,535)
duration – unsigned long (0 … 2^32 - 1)
Buzzer Pins
The Buzzer is connected between pins D4
and D7.
You must set both pins as OUTPUTs –
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
Use tone(4, 440); to generate a 440 Hz
sound.
Musical Notes / Frequencies
Note Frequency (Hz)
C4 261
C#
4/Db
4 277
D4 293
D#
4/Eb
4 311
E4 329
F4 349
F#
4/Gb
4 369
G4 392
G#
4/Ab
4 415
A4 440
A#
4/Bb
4 466
B4 493
Note Frequency (Hz)
C5 523
C#
5/Db
5 554
D5 587
D#
5/Eb
5 622
E5 659
F5 698
F#
5/Gb
5 739
G5 783
G#
5/Ab
5 830
A5 880
A#
5/Bb
5 932
B5 987
Simon DiscoMode
• Array variables
• custom functions
• buzz(tone_id);
• change_led();
Questions?
www.sparkfun.com
6175 Longbow Drive, Suite 200
Boulder, Colorado 80301

More Related Content

Similar to arduinoSimon.ppt

Powerful Electronics with Arduino
Powerful Electronics with ArduinoPowerful Electronics with Arduino
Powerful Electronics with Arduino
Abdallah Hodieb
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Luki B. Subekti
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
sdcharle
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
mkarlin14
 
Aurdino presentation
Aurdino presentationAurdino presentation
Aurdino presentation
C.Vamsi Krishna
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
tomtobback
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and Arduino
Brian Huang
 
Arduino course
Arduino courseArduino course
Arduino course
Ahmed Shelbaya
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Green Moon Solutions
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
ethannguyen1618
 
Arduino and Circuits.docx
Arduino and Circuits.docxArduino and Circuits.docx
Arduino and Circuits.docx
Ajay578679
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
 
IOTC08 The Arduino Platform
IOTC08 The Arduino PlatformIOTC08 The Arduino Platform
IOTC08 The Arduino Platform
Eoin Brazil
 
Arduino
ArduinoArduino
Arduino
Apu Ghosh
 
IOT WORKSHEET 1.4.pdf
IOT WORKSHEET 1.4.pdfIOT WORKSHEET 1.4.pdf
IOT WORKSHEET 1.4.pdf
MayuRana1
 
Lab 2_ Programming an Arduino.pdf
Lab 2_ Programming an Arduino.pdfLab 2_ Programming an Arduino.pdf
Lab 2_ Programming an Arduino.pdf
ssuser0e9cc4
 
Arduino
ArduinoArduino
Arduino
Jerin John
 

Similar to arduinoSimon.ppt (20)

Powerful Electronics with Arduino
Powerful Electronics with ArduinoPowerful Electronics with Arduino
Powerful Electronics with Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
 
Aurdino presentation
Aurdino presentationAurdino presentation
Aurdino presentation
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and Arduino
 
Arduino course
Arduino courseArduino course
Arduino course
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Arduino and Circuits.docx
Arduino and Circuits.docxArduino and Circuits.docx
Arduino and Circuits.docx
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
IOTC08 The Arduino Platform
IOTC08 The Arduino PlatformIOTC08 The Arduino Platform
IOTC08 The Arduino Platform
 
Programming arduino makeymakey
Programming arduino makeymakeyProgramming arduino makeymakey
Programming arduino makeymakey
 
Arduino
ArduinoArduino
Arduino
 
IOT WORKSHEET 1.4.pdf
IOT WORKSHEET 1.4.pdfIOT WORKSHEET 1.4.pdf
IOT WORKSHEET 1.4.pdf
 
Lab 2_ Programming an Arduino.pdf
Lab 2_ Programming an Arduino.pdfLab 2_ Programming an Arduino.pdf
Lab 2_ Programming an Arduino.pdf
 
Arduino
ArduinoArduino
Arduino
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

arduinoSimon.ppt

  • 1. Re-programming the Simon Says with Arduino Linz Craig, Brian Huang
  • 2.
  • 3. Agenda • About us / Introductions • Software Installation • What can it do? Who cares? • Blink Sketch  Disco Lights • Using Variables • If() statement  reading buttonPress • Analog Sensors  Fading • Making Sound
  • 4. About Us SparkFun Electronics is all about creation, innovation and sharing information. We want to get you excited about cutting edge electronics technology with our hands on educational kits.
  • 5. Arduino Board “Strong Friend” Created in Ivrea, Italy in 2005 by Massimo Banzi & David Cuartielles Open Source Hardware Atmel Processor Coding is accessible (C++, Processing, ModKit and MiniBloq)
  • 6. Arduino Software Installation Open Source Free Available on-line with resources at: www.arduino.cc
  • 7. What can it do? •Great for prototyping ideas •Access to multiple I/O •Drive motors, turn on lights, trigger controls. •Low Power requirements •Flexible / Open-source
  • 8. Who cares? Hackers / Makers Engineers Artists Musicians Kids! Teachers!! You!!!
  • 9. Setup Board Type Tools → Board → Arduino Uno
  • 10. Setup Serial COM Port Tools → Serial Port → Notes: PC – Highest COM # Mac – /dev/tty.usbserial-A####xxx
  • 11. Analog and Digital • All Arduino signals are either Analog or Digital • All computers including Arduino, only understand Digital • It is important to understand the difference between Analog and Digital signals since Analog signals require an Analog to Digital conversion
  • 12. Input vs. Output Everything is referenced from the perspective of the microcontroller. Inputs is a signal going into the board. Output is any signal exiting an electrical system • Almost all systems that use physical computing will have some form of output • Often – Outputs include LEDs, a motor, a servo, a piezo element, a relay and an RGB LED
  • 13. Basic Program Two required routines / methods / functions: void setup() { // runs once } void loop() { // repeats forever!!! } upload
  • 14. Let’s get to hacking… Project #1 – Blink “Hello World” of Physical Computing Psuedo-code – how should this work? Turn LED ON Wait Turn LED OFF Wait Rinse & Repeat
  • 15. Three commands to know… pinMode(pin, INPUT/OUTPUT); ex: pinMode(13, OUTPUT); digitalWrite(pin, HIGH/LOW); ex: digitalWrite(13, HIGH); delay(time_ms); ex: delay(2500);
  • 16. LED1 = ~3; LED2 = ~5; LED3 = ~10; LED4 = 13; Can you figure out which LED is tied to which pin? Write down a few notes in your notebook! 3 5 13 LED Pin Configurations 10
  • 17. Output is always Digital To output a signal that pretends to be Analog use this code: analogWrite (pinNumber, value ); Where pin is one of the analog output pins: 3, 5, 6, 9, 10, 11 Where value is a number ranging from: 0 – 255.
  • 18. Output is always Digital (ON or OFF) Using a Digital signal that pretends to be an Analog signal is called Pulse Width Modulation (PWM) By varying the duty cycle, we can “fake” an analog signal output. PWM is available on Arduino pins # 3, 5, 6, 9, 10, and 11 P.W.M. Signal @ 25% P.W.M. Signal @ 75% P.W.M. Signal rising SIMON_2b_BLINK
  • 19. Using Variables To clean-up code, for read-ability, and flexibility – we can create placeholders in code. Example: int ledPin = 3; void setup(){ pinMode(ledPin, OUTPUT); } void loop(){ digitalWrite(ledPin, HIGH); }
  • 20. Digital Input int button_state = digitalRead(ButtonPin); Value will be either: HIGH or LOW
  • 21. Reading a button press Button Input is normally HIGH – when you press it, you pull it LOW. The Code: int buttonPress = digitalRead(2);
  • 22. Activating the Internal Pull-up Resistor pinMode(pin, INPUT_PULLUP); ex: pinMode(2, INPUT_PULLUP); Notes: BUTTON1 = 2; BUTTON2 = 6; BUTTON3 = 9; BUTTON4 = 12;
  • 23. BUTTON1 = 2; BUTTON2 = 6; BUTTON3 = 9; BUTTON4 = 12; Can you figure out which Button is tied to which pin? Write down a few notes in your notebook! 2 6 12 Button Pin Configurations 9
  • 24. Conditional Statements If… General Use if(condition) { // do this } Example if(button_State==HIGH) { digitalWrite(ledPin, HIGH); delay(300); digitalWrite(ledPin, LOW); delay(300); }
  • 25. Digital Input • To connect digital input to your Arduino use Digital Pins # 0 – 13 (Although pins # 0 & 1 are also used for serial) • Digital Input needs a pinMode command: pinMode ( pinNumber, INPUT ); Make sure to use caps for INPUT • To get a digital reading: digitalRead ( pinNumber ); • Digital Input values are only HIGH (On) or LOW (Off)
  • 26. Last bit… the buzzer SIMON_3_BUZZER Final command to know: tone(pin, freq, duration); pin – the OUTPUT pin the buzzer is connected to. freq – unsigned int (0 … 65,535) duration – unsigned long (0 … 2^32 - 1)
  • 27. Buzzer Pins The Buzzer is connected between pins D4 and D7. You must set both pins as OUTPUTs – pinMode(4, OUTPUT); pinMode(7, OUTPUT); Use tone(4, 440); to generate a 440 Hz sound.
  • 28. Musical Notes / Frequencies Note Frequency (Hz) C4 261 C# 4/Db 4 277 D4 293 D# 4/Eb 4 311 E4 329 F4 349 F# 4/Gb 4 369 G4 392 G# 4/Ab 4 415 A4 440 A# 4/Bb 4 466 B4 493 Note Frequency (Hz) C5 523 C# 5/Db 5 554 D5 587 D# 5/Eb 5 622 E5 659 F5 698 F# 5/Gb 5 739 G5 783 G# 5/Ab 5 830 A5 880 A# 5/Bb 5 932 B5 987
  • 29. Simon DiscoMode • Array variables • custom functions • buzz(tone_id); • change_led();
  • 31. www.sparkfun.com 6175 Longbow Drive, Suite 200 Boulder, Colorado 80301