thursday week 2: digital input and output theory and practice of...
TRANSCRIPT
![Page 1: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/1.jpg)
Thursday Week 2: Digital Input and Output
1
Theory and Practice of Tangible User Interfaces
Digital Input and OutputRGB LEDs
fade with PWM
week 02
![Page 2: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/2.jpg)
Thursday Week 2: Digital Input and Output
2
Theory and Practice of Tangible User Interfaces
Microcontrollers
Output Transducersactuators (e.g., motors, buzzers)
Input Transducerssensors (e.g., switches, levers, sliders, etc.)
Arduino
Illustration adapted and modified from O’Sullivan and Igoe
![Page 3: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/3.jpg)
Thursday Week 2: Digital Input and Output
3
Theory and Practice of Tangible User Interfaces
Digital vs.
AnalogBinary vs. continuous signals
•
Binary / Digital = “whether or not”•
Continuous / Analog signal = “how much”
or “faster,”
“brighter,”
etc.
![Page 4: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/4.jpg)
Thursday Week 2: Digital Input and Output
4
Theory and Practice of Tangible User Interfaces
Digital vs. AnalogInternally, all microprocessors
compute
binary: 0 or 1 (0V or 5V)
In general, most microprocessors output only binary (0V or 5V)
Specifically, Arduino output pins can
only be LOW
(0V) or
HIGH (5V)
![Page 5: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/5.jpg)
Thursday Week 2: Digital Input and Output
5
Theory and Practice of Tangible User Interfaces
Digital vs. AnalogTwo states
(binary signal) vs.
multiple states
(continuous signal)
Digital Input and Output
Analog Input (next week!)
![Page 6: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/6.jpg)
Thursday Week 2: Digital Input and Output
6
Theory and Practice of Tangible User Interfaces
Digital OutputBlinking LED
![Page 7: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/7.jpg)
Thursday Week 2: Digital Input and Output
7
Theory and Practice of Tangible User Interfaces
Can We Do Analog Out?LED with 23% brightness?
100% brightness 23% brightness
![Page 8: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/8.jpg)
Thursday Week 2: Digital Input and Output
8
Theory and Practice of Tangible User Interfaces
Pulse Width Modulation
(PWM)
Most microprocessors can
only output
binary: LOW (0V)
or HIGH (5V)
So you fake it with PWM, Pulse Width Modulation
It gives you an illusion of analog values, in between LOW and HIGH
![Page 9: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/9.jpg)
Thursday Week 2: Digital Input and Output
9
Theory and Practice of Tangible User Interfaces
PWM
![Page 10: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/10.jpg)
Thursday Week 2: Digital Input and Output
10
Theory and Practice of Tangible User Interfaces
PWM
75% brightness
25% brightness
50% brightness
![Page 11: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/11.jpg)
Thursday Week 2: Digital Input and Output
11
Theory and Practice of Tangible User Interfaces
Pulse Width Modulation
(PWM)
Your Arduino board has built in PWM circuits, on pins 3, 5, 6, 9, 10, and 11
![Page 12: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/12.jpg)
Thursday Week 2: Digital Input and Output
12
Theory and Practice of Tangible User Interfaces
analogWrite(pin, value)The duty cycle: between 0 and 255
analogWrite(11, 191)
analogWrite(11, 127)
analogWrite(11, 64)
75% brightness
50% brightness
25% brightness
![Page 13: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/13.jpg)
Thursday Week 2: Digital Input and Output
13
Theory and Practice of Tangible User Interfaces
In Class ExerciseMake a color mixer with RGB LEDs
Exercise with digital input and output, and PWM
![Page 14: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/14.jpg)
Thursday Week 2: Digital Input and Output
14
Theory and Practice of Tangible User Interfaces
Color Mixer with RGB LEDsMake any colors with Red, Green, and Blue LEDs, except black
![Page 15: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/15.jpg)
Thursday Week 2: Digital Input and Output
15
Theory and Practice of Tangible User Interfaces
1. LED Blink 2. LED Fade 3. Circuit with 3 LEDs
4. RGB LED Fade 5. Serial RGB LED
In Class Exercise
![Page 16: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/16.jpg)
Thursday Week 2: Digital Input and Output
16
Theory and Practice of Tangible User Interfaces
Blinking LED (c.f. homework)
Resistorred, red, brown, gold
LED
![Page 17: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/17.jpg)
Thursday Week 2: Digital Input and Output
17
Theory and Practice of Tangible User Interfaces
1. LED Blink 2. LED Fade 3. Circuit with 3 LEDs
4. RGB LED Fade 5. Serial RGB LED
In Class Exercise
![Page 18: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/18.jpg)
Thursday Week 2: Digital Input and Output
18
Theory and Practice of Tangible User Interfaces
LED Fade
Resistorred, red, brown, gold
LED
![Page 19: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/19.jpg)
Thursday Week 2: Digital Input and Output
19
Theory and Practice of Tangible User Interfaces
1. LED Blink 2. LED Fade 3. Circuit with 3 LEDs
4. RGB LED Fade 5. Serial RGB LED
In Class Exercise
![Page 20: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/20.jpg)
Thursday Week 2: Digital Input and Output
20
Theory and Practice of Tangible User Interfaces
Circuit with 3 LEDsPlug three LEDs, red, green, and blue and make different colors
![Page 21: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/21.jpg)
Thursday Week 2: Digital Input and Output
21
Theory and Practice of Tangible User Interfaces
1. LED Blink 2. LED Fade 3. Circuit with 3 LEDs
4. RGB LED Fade 5. Serial RGB LED
In Class Exercise
![Page 22: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/22.jpg)
Thursday Week 2: Digital Input and Output
22
Theory and Practice of Tangible User Interfaces
RGB LED FadeSlow color fading and mixing
![Page 23: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/23.jpg)
Thursday Week 2: Digital Input and Output
23
Theory and Practice of Tangible User Interfaces
DiffuserTake a few packing peanuts to experiment
![Page 24: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/24.jpg)
Thursday Week 2: Digital Input and Output
24
Theory and Practice of Tangible User Interfaces
1. LED Blink 2. LED Fade 3. Circuit with 3 LEDs
4. RGB LED Fade 5. Serial RGB LED
In Class Exercise
![Page 25: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/25.jpg)
Thursday Week 2: Digital Input and Output
25
Theory and Practice of Tangible User Interfaces
Serial RGB
Tell it to mix 50 red, 100 green, and 20 blue... Etc.
g50
![Page 26: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/26.jpg)
Thursday Week 2: Digital Input and Output
26
Theory and Practice of Tangible User Interfaces
Arduino Board•
USB to serial
![Page 27: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/27.jpg)
Thursday Week 2: Digital Input and Output
27
Theory and Practice of Tangible User Interfaces
Serial Monitor
![Page 28: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/28.jpg)
Thursday Week 2: Digital Input and Output
28
Theory and Practice of Tangible User Interfaces
Serial CommunicationSerial.begin()
e.g., Serial.begin(9600)
Serial.print()
e.g., Serial.print(colorVal)
Serial.read()
![Page 29: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/29.jpg)
Thursday Week 2: Digital Input and Output
29
Theory and Practice of Tangible User Interfaces
Serial RGB
Tell it to mix 50 red, 100 green, and 20 blue... etc.
g50
![Page 30: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/30.jpg)
Thursday Week 2: Digital Input and Output
30
Theory and Practice of Tangible User Interfaces
![Page 31: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/31.jpg)
Thursday Week 2: Digital Input and Output
31
Theory and Practice of Tangible User Interfaces
![Page 32: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/32.jpg)
Thursday Week 2: Digital Input and Output
32
Theory and Practice of Tangible User Interfaces
![Page 33: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/33.jpg)
Thursday Week 2: Digital Input and Output
33
Theory and Practice of Tangible User Interfaces
![Page 34: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/34.jpg)
Thursday Week 2: Digital Input and Output
34
Theory and Practice of Tangible User Interfaces
1. LED Blink 2. LED Fade 3. Circuit with 3 LEDs
4. RGB LED Fade 5. Serial RGB LED
In Class Exercise
![Page 35: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/35.jpg)
Thursday Week 2: Digital Input and Output
35
Theory and Practice of Tangible User Interfaces
Homework (due next Thursday, Sep 13)
Part I: Design a good diffuser for your RGB LEDs
e.g., ping pong ball, styrofoam, mylar, cottons, icecream
cone?
Part II: Modify the Serial RGB code for new keyboard input:
•
Basic: Control the RGB values with multiple key presses (e.g., instead of typing “r127”
to set the Red LED to 50% brightness, count how many times the characters “r”
“g”
“b”
were pressed. E.g., press “r”
5 times to get it to 50%, 8 times for 80%, 10 times for 100%, 11 times to go back to 0%, etc.)
•
Advanced: Find new ways of controlling the colors of LEDs
using the keyboard
Post both parts on the course website (photo, descriptions, code)
![Page 36: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/36.jpg)
Thursday Week 2: Digital Input and Output
36
Theory and Practice of Tangible User Interfaces
Supplement ReadingsMore on PWM and LED fading: Chapter 6 (p. 112-114) of O’Sullivan and Igoe
More on microcontroller in general: Chapter 4 (p.49-63)
![Page 37: Thursday Week 2: Digital Input and Output Theory and Practice of …courses.ischool.berkeley.edu/i290-13/07readings/tangible... · 2008. 8. 27. · Pulse Width Modulation (PWM) Most](https://reader036.vdocument.in/reader036/viewer/2022071301/609dbfd61e6a6546f22b9057/html5/thumbnails/37.jpg)
Thursday Week 2: Digital Input and Output
37
Theory and Practice of Tangible User Interfaces
Next Thursday: Analog InputTwo states
(binary signal) vs.
multiple states
(continuous signal)
Digital Input and Output
Analog Input (next week!)