nsta 2013 denver - ardublock and arduino
DESCRIPTION
Updated slides and presentation materials around using ArduBlock with the SparkFun Lilypad Arduino Development Board.TRANSCRIPT
![Page 1: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/1.jpg)
Brian Huang
Education Engineer
Email: [email protected]
Twitter: @bri_huang
#sparkfun
Engineering the
Engineering: Connecting
the Why to the How
Unleashing Your Students'
Inner Inventor—Robots,
Video Games, and DIY!
![Page 2: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/2.jpg)
Brian Huang
Education Engineer
@bri_huang
#sparkfun
Engineering the
Engineering: Connecting
the Why to the How
![Page 3: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/3.jpg)
Write this down…
http://bit.ly/SparkFunNSTADenver2013
![Page 4: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/4.jpg)
A little background (Ignite style)
Ignite presentation format: (a.k.a. Pecha
Kucha)
• 20 Slides
• 15 seconds per slide
• Slides are on auto-advance
• Total Time: 5 minutes
![Page 5: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/5.jpg)
![Page 6: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/6.jpg)
![Page 7: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/7.jpg)
About us...
Founded in 2003 by Nathan Seidle.
At SparkFun, our focus is all about creation, innovation,
and sharing information.
Open Source Hardware is at the core of our business. We
emphasize researching, re-mixing, adapting, making
improvements, and sharing with the world!
![Page 8: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/8.jpg)
![Page 9: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/9.jpg)
![Page 10: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/10.jpg)
Today
You will use a microcontroller &
ArduBlock to design, develop, and
build interactivity and “intelligence”
with digital electronics, LEDs, and
sensors.
![Page 11: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/11.jpg)
![Page 12: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/12.jpg)
Consumers
Creators / Makers
Engineers / Inventors
![Page 13: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/13.jpg)
Maker Culture
Make to Learn
![Page 14: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/14.jpg)
Seymour Papert &
Constructionism
![Page 15: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/15.jpg)
I want ________ to ________.
![Page 16: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/16.jpg)
Introducing Arduino…
(circa 2005) Small, low-cost micro-controller (mini-computer).
Describes both the hardware (board) and the programming language.
Developed off the Atmel ATMega328 chip.
Designed with Artists, Students, and Non-Engineers in mind…
![Page 17: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/17.jpg)
But, really… what is this “arduino?”
![Page 18: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/18.jpg)
In science???
• Data logging / collection
• Control of motors, LEDs, experiments
• Design of atmospheric and Space-based
experiments and apparatus
• Inventions!
• Making Art!!!
![Page 19: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/19.jpg)
A few project ideas
![Page 20: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/20.jpg)
And, a couple more...
![Page 21: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/21.jpg)
And, a couple more...
![Page 22: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/22.jpg)
![Page 23: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/23.jpg)
Whew!
Questions?
![Page 24: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/24.jpg)
Let’s Start!
![Page 25: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/25.jpg)
First thing you need is…
Download Arduino from:
www.arduino.cc/download
Follow their directions on installation.
![Page 26: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/26.jpg)
![Page 27: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/27.jpg)
![Page 28: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/28.jpg)
Installation Process
ArduBlock is a run-time Java script that must be
saved to a specific location on your computer.
The file ardublock-xxxx.jar must be inside the
following file structure within your Arduino
sketchbook:
\Arduino\tools\ArduBlockTool\tool
Note: Folder names are case sensitive
![Page 29: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/29.jpg)
A little short-cut…
Unzip this file to your Arduino
sketchbook folder.
![Page 30: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/30.jpg)
General Rules
• Raise your hand if you have a question.
• Be respectful.
• When I raise my hand…
• Share your findings with the people near
you.
• Poke around, experiment, and have fun…
• Imagine, create, and play!!!
![Page 31: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/31.jpg)
![Page 32: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/32.jpg)
What is all this stuff???
Components
Buzzer /
Speaker
Light
Sensor
Temp.
Sensor
the Brain
ATmega328
(16 MHz clock)
![Page 33: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/33.jpg)
What is all this stuff??? Silk Screen & Pins
Actual Pins
on Atmega328
![Page 34: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/34.jpg)
Startup Arduino IDE
Double-click on either
the Arduino Icon or
wherever you
installed (saved) the
Arduino program.
![Page 35: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/35.jpg)
Plug it in
![Page 36: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/36.jpg)
Lesson #0a – Setting up Arduino
1.Setup Board
(LilyPad Arduino w/ ATmega328)
2.Setup COM Port
PC – Highest COM #
Mac – /dev/tty.usbserial-A####xXx
![Page 37: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/37.jpg)
Tools Board Setup Board
![Page 38: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/38.jpg)
Tools Serial Port Setup COM Port
PC –
Highest COM #
Mac –
/dev/tty.usbserial-
A####xxx
![Page 39: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/39.jpg)
Other Board Types
![Page 40: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/40.jpg)
Tools ArduBlock Load ArduBlock
![Page 41: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/41.jpg)
Programming
Area
Zoomed out
View
Programming
Blocks Palate
![Page 42: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/42.jpg)
What is ArduBlock?
• Graphical Introduction to Programming
• Scratch-like interface
• Clear transition to text-based coding
• Generates real Arduino code in the
background.
![Page 43: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/43.jpg)
Block Organization
Manipulating or modifying the program
flow or behavior.
Serial and I2C communication:
transferring data between devices & PC
Special utilities: Tone, servo, and
ultrasonic sensors
Creating, assigning, or using constants,
variables, or arrays.
Simple and complex math operations.
Boolean logic operations and
comparisons.
Reading or setting values (voltages) to
pins on the microcontroller.
![Page 44: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/44.jpg)
Block Organization
Control Manipulating or modifying the program
flow or behavior.
![Page 45: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/45.jpg)
Example #1
![Page 46: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/46.jpg)
Click back to the Arduino window to
check for status messages
![Page 47: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/47.jpg)
Example #1 - debrief
What is the difference between setup() and
loop()?
When you add multiple blink blocks, describe
the behavior of the LEDs?
What new feature might you want to create?
![Page 48: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/48.jpg)
![Page 49: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/49.jpg)
Example #2 See if you can come up with the steps needed
to make an LED blink.
![Page 50: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/50.jpg)
What other LEDs can we play
with?
16 18 17
![Page 51: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/51.jpg)
Pins with an A are Analog INPUT pins –
but they’re really identified as…
Digital Pins are numbered 0 to 13.
Analog Input Pins are A0 to A5. but, actually…
Analog Pin Digital I/O ID
A0 14
A1 15
A2 16
A3 17
A4 18
A5 19
An
alo
g P
in
M
ap
pin
g
![Page 52: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/52.jpg)
Example #2 - debrief
1) Can you write a program that blinks on and off with a 1 second
delay in between? What is the period of this pattern?
2) Can you write a program that blinks 10 times per second? What
delay time did you use? What about 50 times per second? What
delay time did you use?
3) Creative: Modify your program to create a heartbeat pattern.
4) Extension: Add extra LEDs to create an LED chaser or Larson
Scanner. Use as many of the LEDs on the Lilypad Development
Board as you like. How fast do you want it to run?
![Page 53: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/53.jpg)
set digital pin
Any number… except,
Pin# is limited to a
range of:
Allows the control of the pins on the Atmega328
chip – turning them on or off (like the light
switch)
or
Different shapes?
Digital Constant Block Numeric Constant Block
to ON OFF
![Page 54: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/54.jpg)
Example #3 - What’s next?
![Page 55: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/55.jpg)
set analog pin
Because of certain hardware
settings, set analog pin only
works with pins 3, 5, 6, 9, 10,
& 11.
Allows the control of the pins on the Atmega328
chip – turning them partially on or partially off
(like a dimmer switch)
Analog Output Values
to
Rather than having just HIGH
and LOW, you can set the
pin to any value from 0 to
255.
![Page 56: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/56.jpg)
Concept: Analog vs. Digital
To create an analog signal, the
microcontroller uses a technique called
PWM.
Pulse Width Modulation (PWM)
Pins 3, 5, 6, 9, 10, 11 are capable of producing an
Analog Output
![Page 57: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/57.jpg)
Example 4 - What about sensors?
![Page 58: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/58.jpg)
Example #4 - debrief
What was the maximum value you saw from the light
sensor?
What was the maximum value you saw from the temp
sensor?
Analog sensors are read by a 10-bit Analog to Digital
(A\D) converter. It “quantizes” a voltage at the input
pin into 1023 “bins.” 5 V = 1023 and 0 V = 0.
![Page 59: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/59.jpg)
Example #5 – if statements
![Page 60: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/60.jpg)
Example #6 – making sounds
(er… music)
![Page 61: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/61.jpg)
Options, options, options…
Questions
?
![Page 62: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/62.jpg)
Preview of Digital SandBox
Slider / Potentiometer Switch
Motor /
Speaker Out
Push Button
Microphone Light Sensor
Temp Sensor
LED Array
RGB LED
Arduino
![Page 63: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/63.jpg)
Extension Project
Create a musical and interactive lighting
display.
Plan out what you want the project to do,
first! Use an outline, flow-chart, or thinking
map to accomplish this.
![Page 64: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/64.jpg)
Getting started with Arduino
![Page 65: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/65.jpg)
SparkFun Inventor’s Kit
KIT-12001
Circuit 1: Blinking an LED
Circuit 2: Reading a Potentiometer
Circuit 3: Driving and RGB LED
Circuit 4: Driving Multiple LEDs
Circuit 5: Push Buttons
Circuit 6: Reading a Photo Resistor
Circuit 7: Reading a Temperature Sensor
Circuit 8: Driving a Servo Motor
Circuit 9: Using a Flex Sensor
Circuit 10: Reading a Soft Potentiometer
Circuit 11: Using a Buzzer
Circuit 12: Driving a Motor
Circuit 13: Using Relays
Circuit 14: Using a Shift Register
Circuit 15: Using an LCD
![Page 66: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/66.jpg)
Data Collection with Vernier
![Page 67: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/67.jpg)
Discount / Promo Code
Promo Code: EDUNSTA2013
25% Discount – orders > $30
E-mail: [email protected] to create
an educator account.
Twitter: @bri_huang, #sparkfun, #nsta2013
![Page 68: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/68.jpg)
Before leaving, please fill out a quick survey
so that I can get your e-mail and a little
info about your familiarity with Arduino /
SparkFun.
Thanks!
http://www.sparkfun.com/WorkshopFeedback
Thank you!
![Page 69: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/69.jpg)
Alright? Let’s blink!
Challenge 1a – Blink to mimic a heartbeat
Challenge 1b – Blink multiple LEDs
First -- plan out a pattern on paper – then
start coding
Challenge 1c – Multiple LEDS – Knight
Rider (Cylon)-esque
![Page 70: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/70.jpg)
![Page 71: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/71.jpg)
Save your Project
• Save early, Save
often!
• Enumerate your
iterations – (e.g.
blink_10.adp,
blink_11.adp,
blink_12.adp…)
![Page 72: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/72.jpg)
Speeding up and Slowing
Down…
What if we wanted to create a pattern that starts off
with a slow blink and gets faster and faster?
What part do we need to be able to change?
constant
![Page 73: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/73.jpg)
Programming Concepts:
Using Variables
Variables placeholders / reminder for
counting
![Page 74: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/74.jpg)
Using Variables in ArduBlock
Numbers/Constants
Variable is just a
placeholder for a
value.
This placeholder can
be manipulated
within the code.
![Page 75: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/75.jpg)
Start by setting a variable called
delayTime in the setup
![Page 76: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/76.jpg)
Now… replace the “1000” in each
delay with the variable name
![Page 77: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/77.jpg)
Decrement delayTime each loop
– using Math Operators
![Page 78: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/78.jpg)
Example: Did you come up with
something like this?
![Page 79: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/79.jpg)
What happens when you reach zero?
Let’s find out!
![Page 80: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/80.jpg)
Debugging – how can we see what’s going on?
Serial Monitor
Serial print
command
Any
message
“glue”
Data
![Page 81: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/81.jpg)
Add this block… so that we can
watch the variable value
![Page 82: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/82.jpg)
Upload & Click back to Arduino Open the Serial Monitor
![Page 83: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/83.jpg)
How do we fix / prevent this from
happening?
If this is TRUE…
Do this.
Otherwise,
do this.
Conditional Logic: If(), If() – else…
![Page 84: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/84.jpg)
Logical Operators Comparisons / Conditionals
Greater than
Less than
Equal to
Greater than or equal to
Less than or equal to
Not equal to
![Page 85: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/85.jpg)
If delayTime <= 0… reset
![Page 86: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/86.jpg)
Advanced… Combinations of inequalities
Combine multiple conditions together using
or and and
Example:
![Page 87: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/87.jpg)
Other than just turning an LED on
and off…
What else might we want to do / control?
![Page 88: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/88.jpg)
Concept: Analog vs. Digital
Micro-controllers are digital devices – ON or OFF.
An Analog signal is anything that can be a full
range of values. xWhat are some examples?
Think of like a ramp or a hill.
![Page 89: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/89.jpg)
Concept: Analog vs. Digital
To create an analog signal, the
microcontroller uses a technique called
PWM.
Pulse Width Modulation (PWM)
Pins 3, 5, 6, 9, 10, 11 are capable of producing an
Analog Output
![Page 90: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/90.jpg)
Color Mixing with 3 LEDs
RGB LED
LED PINS
RED = 9
GREEN = 11
BLUE = 10
Change either of these
values… See what happens!
![Page 91: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/91.jpg)
Color Mixing with 3 LEDs
Tri-color LED
The RGB LED is a Common-Anode (means the
positive side of the LED is all tied to Vcc).
The signal line is connected to the bottom of each
LED.
Don’t worry - it’s just a different method of
completing a circuit!
Pin
9
Pin
11
Pin
10
5 V
Value = 0 (LOW) LED is ON
Value = 255 (HIGH) LED is OFF
![Page 92: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/92.jpg)
Color Mixing with 3 LEDs
Challenge 2b:
Experiment with different values of Red, Green, and Blue
to create a couple different colors.
Write down the values you used. Check these values
with www.colorpicker.com
Challenge 2c:
Create a unique lighting display that blinks, fades, or
switches colors. Be prepared to have a name for your art
piece and show this to the rest of the class.
![Page 93: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/93.jpg)
![Page 94: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/94.jpg)
Save your Project #2
![Page 95: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/95.jpg)
New Challenge
Handling Inputs
![Page 96: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/96.jpg)
A Simple Example
Try this bit of code.
What do you think will happen? Test it
and write down your observations.
DIG
INPUT 2
![Page 97: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/97.jpg)
digital Inputs
Buttons / Slide Switches
INPUT A5
INPUT A5
(a.k.a. 19)
What about
this??
Analog Pin Digital I/O ID
A0 14
A1 15
A2 16
A3 17
A4 18
A5 19
An
alo
g P
in
M
ap
pin
g
![Page 98: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/98.jpg)
digital Inputs
Buttons / Slide Switches
Challenge 3a:
Re-arrange the blocks or add new ones to:
• Blink LED quickly when the button is pressed.
• Otherwise blink slow
Same as
Pin A5
![Page 99: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/99.jpg)
digital Inputs
Buttons / Slide Switches
Challenge 3b:
Now, using the button / switch – to start a disco/light changing
pattern
Challenge 3c:
Now, using the button / switch – to turn on and off the VIBE
motor.
![Page 100: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/100.jpg)
Reading the
Light Sensor?
What is the biggest and smallest value the analog pin will
“measure”? [Hint: open your serial monitor to find out!]
![Page 101: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/101.jpg)
Challenge
Use the light sensor input to affect the blink
rate of the LEDs.
Use the light sensor input to affect the speed
of a “knight-rider” or cylon display.
Use the light sensor to ___________.
![Page 102: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/102.jpg)
Save your Project #3
Sensors
![Page 103: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/103.jpg)
Making Music
Setting up the Speaker
Three simple blocks to play with…
![Page 104: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/104.jpg)
Making Music
Let’s Play a song…
Twinkle-Twinkle:
CC GG AA G FF EE DD C GG
Happy Birthday:
G G A G C B G G A G D C G G G E C C B A
Hot Cross Buns:
B A G <> B A G <> G G G G <> A A A A B A G
Mary Had A Little Lamb:
B A G A BB B <> AA A <> BB B <>
B A G A BBBB AAA BAG.
![Page 105: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/105.jpg)
Musical Notes / Frequencies
Note Frequency (Hz)
C4 261
C#4/D
b4 277
D4 293
D#4/E
b4 311
E4 329
F4 349
F#4/G
b4 369
G4 392
G#4/A
b4 415
A4 440
A#4/B
b4 466
B4 493
Note Frequency (Hz)
C5 523
C#5/D
b5 554
D5 587
D#5/E
b5 622
E5 659
F5 698
F#5/G
b5 739
G5 783
G#5/A
b5 830
A5 880
A#5/B
b5 932
B5 987
![Page 106: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/106.jpg)
Save your Project #4
Tone
![Page 107: NSTA 2013 Denver - ArduBlock and Arduino](https://reader033.vdocument.in/reader033/viewer/2022042522/559bffbb1a28ab36468b45ea/html5/thumbnails/107.jpg)