September 20, 2019
Material
From Arduino Kit:1 * Arduino Uno |
From cart:2 * arcade buttons |
Circuit 1: Fade (tutorial)
*The schematic, diagram and description are from https://www.arduino.cc/en/Tutorial/Fade.
*The code is Arduino>File>Examples>03.Analog>Fading
Description:
This example demonstrates the use of the analogWrite() function in fading an LED off and on. AnalogWrite uses pulse width modulation (PWM), turning a digital pin on and off very quickly with different ratio between on and off, to create a fading effect.
Reflection:
This circuit isn’t complex. The dimming effect was obvious once we ran the code in Arduino. The concept of PWM is new to me. And analogWrite’s working principle is based on PWM. As explained in the tutorial on Arduino’s official website, “brightness” is a variable used in the code. AnalogWrite() can change the PWM very fast, so at the end of the code delay is written to control the speed of the fading effect.
Fade Schematic
Fade Circuit |
int led = 9; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by// the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: pinMode(led, OUTPUT); }// the loop routine runs over and over again forever: void loop() { // set the brightness of pin 9: analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect delay(30); } ↑ Fade Arduino Code |
Circuit 2: toneMelody (tutorial)
*The schematic, diagram and code are from https://www.arduino.cc/en/Tutorial/toneMelody.
*The code is Arduino>File>Examples>02.Digital>toneMelody.
Description:
“This example shows how to use the tone()
command to generate notes. It plays a little melody you may have heard before.”
“The code below uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. This note table was originally written by Brett Hagman, on whose work the tone() command was based. You may find it useful whenever you want to make musical notes.”
Reflection:
The full name for the buzzer is “piezo buzzer”. The circuit only needs two hookup wires and doesn’t require any resistor. On Arduino official website, it says “Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED and resistor attached to it that are soldered to the board on most boards” (https://wp.nyu.edu/shanghai-ima-interaction-lab/category/recitations/). But obviously in the circuit, the buzzer is connected to Digital pin 8, so the internal resistor is not here to account for that. A Question remains to be solved !!!
toneMelody Schematic
toneMelody Circuit toneMelody Arduino Code→ |
#include “pitches.h”
// notes in the melody: // note durations: 4 = quarter note, 8 = eighth note, etc.: void setup() { // to calculate the note duration, take one second divided by the note type. // to distinguish the notes, set a minimum time between them. void loop() { |
Circuit 3: Speed Game (tutorial)
*The diagram and code are from https://www.tinkercad.com/things/6MzvN5rlZlr-race-the-led-spring19
Description & Reflection:
This circuit is a 2-person game. It wasn’t really difficult to build the circuit. But it was very easy to mess it up since there were 16 hook-up wires. So I needed to be careful and check which two points one wire was supposed to connect. At first, I missed one wire, so when the code was running, only “player 1” was recorded. Later the problem was solved.
Speed Game Circuit
|
Speed Game Schematic |
Speed Game Arduino Code (read from left to right)↓
int buzzerPin = 8; int button1 = 11; int button2 = 10; int led1 = 3; int led2 = 2;int goal = 10; int buttonState1 = LOW; int previousState1 = LOW; int buttonState2 = LOW; int previousState2 = LOW;int counter1 = 0; int counter2 = 0; boolean winner1 = false; boolean winner2 = false;// the follow variables are long’s because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long time = 0; // the last time the output pin was toggled long debounce = 200; // the debounce time, increase if the output flickersvoid setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(buzzerPin, OUTPUT); pinMode(button1, INPUT); pinMode(button2, INPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); Serial.println(“******************* RACE THE LED *******************”); delay(1000); Serial.println(“READY”); delay(1000); Serial.println(“SET”); delay(1500); Serial.println(“GO!!!!!!!!!!!!!!!!”);}void loop() { // put your main code here, to run repeatedly: buttonState1 = digitalRead(button1); buttonState2 = digitalRead(button2); //Serial.println(buttonState1);//this checks the times player 01 has pressed the button if (counter1 < goal && winner2 == false) { if (buttonState1 != previousState1 && millis() – time > debounce) { if (buttonState1 == HIGH) { counter1++; Serial.print(“player 01: “); Serial.println(counter1); time = millis(); } } previousState1 = buttonState1; if (counter1 == goal && winner2 == false) { winner1 = true; digitalWrite(led1, HIGH); Serial.println(“PLAYER 01 WINS”); playMelody(); } } |
//this checks the times player 02 has pressed the button
if (counter2 < goal && winner1 == false) { } void playFreq(double freqHz, int durationMs) { //store start time //(millis() – startTime) is elapsed play time void playMelody() { playFreq(262, 100); } |
Question 1:
Reflect how you use technology in your daily life and on the circuits you just built. Use the text Physical Computing and your own observations to define interaction.
I get so used to technology in my daily life that only when I went away from the urban circle and hid in the forest, would I notice the difference and realize how dependent I had been on technology. The word “manipulation”(sounds quite negative) came to my mind. Technology has been critical in terms of being the object (either tangible or intangible, visible or invisible) that serves human beings as the subject. Voice control lamp, water heater, central air conditioning – undoubtedly, it brings convenience. But on the other hand, my dependence on these items and the way my life has been changing and orienting around them are also the evidence for the conversation that happened the other way around. These changes can be positive, negative or rather neutral/ balanced of both sides. Therefore, rather than the word “manipulation”, “interaction” would be a better fit to describe this phenomenon between technology and human beings.
I like the word ‘relationship’ in the text Physical Computing. When giving an explanation about “Intelligence Amplification”, it says “Rather than trying to imitate the autonomy of human beings, we want to support it”. and supports a human being’s autonomy by capturing and conveying a person’s expression. It counts on human beings to make the most interesting relationships and supports a human being’s autonomy by capturing and conveying a person’s expression (p. xviii, “Introduction”). In a particular situation like a smartphone, ideas from designers are communicated to the user through the smartphone. Relationships are built between technology and human beings. More importantly, relationships are built between human beings through technology. “Interaction” is the concrete content of these relationships. It varies in forms (such as “listening, thinking and speaking”) and is actually composed of these variations (or put in other words, an interactive process is composed of these variations) (p. xx).
A better definition of “interaction” then consists of two parts – its process/forms and its purpose. In Physical Computing, Chris Crawford’s definition is concise and emphasizes on the process and its actors. To me, moreover, “interaction” is the process that conveys ideas. Eventually, it is the relationship between human beings rather than technology and human beings.
Question 2:
Why did we use the 10K resistor with the push button?
To regulate the current in the circuit and avoid blowing the push button. But I don’t know why we don’t use 220 ohm. Another question!
Question 3:
If you have 100,000 LEDs of any brightness and color at your disposal, what would you make and where would you put it?
(1)I will make an interactive painting made of LEDs. Square shape, approximately 30×30 cm. Over the LED-matrix is a piece of transparent flesh-color material. It reacts to the distance between the piece and the watcher and changes color and brightness so as to form different pictures.
(2)A very simple piece of stagecraft. I will install it for theatrical productions.
(3)A huge LED-assembled bulb. Put in the neighborhoods in the arctic circle, it will change its brightness and color according to time and need.
References
Fade tutorial https://www.arduino.cc/en/Tutorial/Fade
toneMelody tutorial https://www.arduino.cc/en/Tutorial/toneMelody
Speed game tutorial https://www.tinkercad.com/things/6MzvN5rlZlr-race-the-led-spring19
Introduction in Physical Computing by Igoe and O’Sullivan
One Reply to “Recitation 2: Arduino Basics by Haiyan Zhang”