Day 1: (Aug 27) Welcome and Arduino Introduction

Notes for 2018-08-27. See also the Fall 2018 Calendar.

Agenda

  1. Welcome.
  2. Administrative
  3. Assignments
  4. In-class
    1. Brief introduction to the Arduino (in 16-223 slides Drive folder)
    2. Each person pick up an Arduino, USB cable, cluster laptop, breadboard, speaker, IRF540, and a few jumper wires.
    3. Crash course in Arduino basics.
    4. Write an Arduino sketch to play tones in sequence to create a siren. For now, it is easiest to use tone() and delay() inside loop().
    5. Related exercises: Exercise: Arduino Introduction, Exercise: Coding, Compiling, Deploying, Exercise: Unipolar Drivers
    6. If time permits: rewrite your sketch without using delay(), then add a simultaneous fast-blink on the LED. For ideas, see Exercise: Event-Loop Programming
    7. At the end of class, please return the Arduinos and other components.

Lecture code samples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
// generate tones on a speaker on pin 5
void setup()
{
  tone(5, 440);
}
void loop()
{
  delay(1000);
  noTone(5);

  delay(1000);
  tone(5, 660);

  delay(1000);
  tone(5, 440);
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void setup()
{ 
  pinMode(5, OUTPUT);
}
void loop()
{
  long now = micros();
  bool square1 = (now % 2274) < 1136;
  bool square2 = (now % 1516) < 758;
  digitalWrite(5, square1 ^ square2);
}