Day 4: (Mon Jul 8) Trip Review, Brainstorming, Arduino Introduction

Notes for 2019-07-08. See also the Calendar.

Agenda

  1. Administrative
    1. possible interviews with visitor today
  2. Assignments
    1. Due today: Game Concept Brainstorm. Ten game concepts, one game sketch (11x17 paper preferred).
    2. Due today: field trip observation form.
  3. In-class
    1. Brief review of field trip.
    2. Brainstorming session:
      1. silent concept review
      2. drawing presentations/concept pitches
    3. Introduction to the Arduino.
      1. Arduino slides
      2. Pinball Arduino Uno Shield
      3. Pinball Arduino Mega Shield
      4. Arduino IDE (related: Exercise: Arduino Introduction)
      5. blinking a light (related Exercise: Coding, Compiling, Deploying)
      6. tone speaker circuit

Lecture code samples

Tones

Note: assumes a speaker is attached to pin 5.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
// 1. generate tones on a speaker on pin 5
// 2. demonstrate tone(), noTone()

void setup()
{
  tone(5, 440);
}

void loop()
{
  delay(1000);
  noTone(5);

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

  delay(1000);
  tone(5, 440);
}

Chromatic Scale

Note: assumes a speaker is attached to pin 5.

 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);
}

Serial Port and Clocks

 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
26
27
28
// Demonstrate:
// 1. the firmware clocks
// 2. long variables (32-bit integers)
// 3. time differencing
// 4. debugging on the serial port

void setup()
{
  Serial.begin(115200);
}

long last_time = 0;

void loop()
{
  long micro_now = micros();
  long milli_now = millis();
  
  Serial.print(micro_now);
  Serial.print(" ");  

  Serial.print(milli_now)
  Serial.print(" ");

  Serial.println(micro_now - last_time);

  last_time = micro_now;
}