Day 6: (Mon Sep 16) Event Loop Programming¶
Notes for 2019-09-16. See also the Fall 2019 Calendar.
Notes from Day 5¶
Thoughts on demo 2: it is easier to make things more complicated than simple. But I recommend striving for simplicity and ease of implementation.
Agenda¶
Administrative
Small note on cleanup protocols: re-usable solder shouldn’t go in the waste bins. And let’s try to clean up detritus after using the soldering stations.
I’ve received just a couple of clearance documents. If you have them, please forward me scans of your PACA, PATCH, and FBI results. HR/Act 153 will not supply them to me directly, but I will need to give them to the museum.
Assignments
Due today: Demo 2: Single-bit Feedback
Due Mon Sep 23: Demo 3: The Conversation. This will be performed in pairs:
Xiang, Griffin
Quincy, Hagan
Patricia, Sophia
Halanna, Wenqing
Katherine, Omisa
Jai, Caio
Julian, Tushhar
Edward, Spencer
Due Mon Sep 23: read
Investigating Rocks and Sand
In-class
Rapid-fire critique. This time, each person will show their work to the whole class from their table (we’ll all move around), then pose their own unresolved question. We’ll have time for just one or two observations each as feedback. Goal: three minutes per person.
Discussion of event-loop programming.
non-blocking.ino (below)
Brief discussion of state machines.
Brief pair meetings to start thinking about ‘conversation’ ideas and sharing contact information.
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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // 1. Blink the onboard Arduino LED on pin 13.
// 2. Demonstrate a non-blocking event loop.
// 3. Demonstrate micros() and timing calculations.
// 4. Note the absence of delay(). For comparison, see blink.ino.
void setup(void)
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(void)
{
static unsigned long last_update_clock = 0;
unsigned long now = micros();
unsigned long interval = now - last_update_clock;
last_update_clock = now;
static long led_blink_timer = 0;
static bool led_blink_state = false;
const long led_blink_interval = 500000;
led_blink_timer -= interval;
if (led_blink_timer <= 0) {
led_blink_timer += led_blink_interval;
led_blink_state = !led_blink_state;
digitalWrite(LED_BUILTIN, led_blink_state);
}
}
|