Day 1: (Mon Aug 26) Welcome, Arduino Introduction¶
Notes for 2019-08-26. See also the Fall 2019 Calendar.
Agenda¶
Welcome.
What is IDeATe?
What is Physical Computing? What is a kinetic system?
Project focus: Pittsburgh Children’s Museum. Note that several Friday morning trips are mandatory.
Unspoken prerequisites.
16-223 is a good portal for the
IDeATe Physical Computing Minor
Administrative
Enrollment and waitlist.
Course site: https://courses.ideate.cmu.edu/16-223
Daily log pages (like this one): Daily Agenda Logbook
Calendar: Fall 2019 Calendar
Weekend trips and child clearances.
Laser cutter policies: these have changed for F19.
Laser cutter safety training courses: see IDeATe Laser Cutter Policy
New buddy system: don’t ever cut alone. Lasers will be available 10AM-10PM (no more middle of the night).
New mandatory IDeATe training, even for previous users: 4:30PM on Sep 4, 5, 6, 9, 10, 11.
Fire Extinguisher training. Sign up via BioRaft, convenient sessions will be in HL A5 on Sep 3 at 4:30, 5:00, 5:30, 6:00.
Attendance and tardiness policies.
Resources
Card access.
Physical Computing Lab use and abuse.
We are sharing the room with six other classes (see IDeATe PhysComp Lab Calendar).
IDeATe Computing Virtual Cluster.
Office hours: TBD
Name tags and photos.
Assignments
Prepare for PA child clearances. See Child Clearances and
the clearance authorization form
If you already have clearances, please come on time and I’ll take you aside for personal tutorial.
In-class
Brief introduction to the Arduino.
Each person pick up an Arduino, USB cable, cluster laptop, breadboard, speaker, dropping resistor, and a few jumper wires.
Crash course in Arduino basics.
Write an Arduino sketch to play tones in sequence to create a siren. For now, it is easiest to use
tone()
anddelay()
insideloop()
.Face photos.
Related exercises: Exercise: Arduino Introduction, Exercise: Coding, Compiling, Deploying, Exercise: Unipolar Drivers
If time permits: rewrite your sketch without using
delay()
, then add a simultaneous fast-blink on the LED. For ideas, see Exercise: Event-Loop ProgrammingAt the end of class, please return the Arduinos and other components.
Lecture code samples¶
(See also Lecture Sample Code).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // 1. blink the onboard Arduino LED on pin 13.
// 2. demonstrate setup(), loop()
// 3. demonstrate pinMode(), digitalWrite(), delay()
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // 1. generate tones on a speaker on pin 5
// 2. demonstrate tone(), noTone(), delay()
void setup()
{
// empty body, tone() configures a pin for output
}
void loop()
{
tone(5, 440);
delay(1000);
noTone(5);
delay(1000);
tone(5, 660);
delay(1000);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // 1. generate chromatic tones on a speaker on pin 5
// 2. demonstrate for loops, int and float variables
void setup()
{
}
void loop()
{
float freq = 440.0;
for (int i = 0; i < 24; i = i + 1) {
tone(5, freq);
delay(200);
freq = freq * 1.0595;
}
noTone(5);
delay(1000);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // 1. measure execution time
// 2. demonstrate the firmware clock
// 3. demonstrate debugging on the serial port
void setup()
{
Serial.begin(115200);
}
long last_time = 0;
void loop()
{
long now = micros();
Serial.print(millis());
Serial.print(" ");
Serial.print(micros());
Serial.print(" ");
Serial.println(now - last_time);
last_time = now;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // 1. generate complex waveform on a speaker on pin 5
// 2. demonstrate execution speed, firmware clocks, bit-banging logic
void setup()
{
pinMode(5, OUTPUT);
}
void loop()
{
long now = micros();
bool square1 = (now % 2274) < 1136;
bool square2 = (now % 1516) < 758;
digitalWrite(5, square1 ^ square2);
}
|