Class log
Note: “codebook” entries below are verbatim pasting of all of the code we used in class. It’s possible they may not compile (i.e. may have errors) if we left things unresolved, or were writing pseudocode, etc.
- Tuesday, Aug. 30th: Intro
- Thursday, Sep. 1st: Technical learning
- Tuesday, Sep. 6th: Technical learning, Project 1 assigned
- Thursday, Sep. 8th: Project 1 discussion
- Tuesday, Sep, 13th: Variable types and event loop programming
- Thursday, Sep. 15th: Debugging techniques
- Tuesday, Sep. 20: Project 1 work day
- Thursday, Sep. 22: Project 1 presentations
Tuesday, Aug. 30th: Intro
- Welcome to class!
- Quick introductions: students in random pairs each answer a few questions about each other:
- Their name and pronouns
- What they’re studying and what year they’re in
- What brings them to this class
- Something fun/interesting/exciting/great/awful they did over summer
- Review course Canvas site briefly
- Review main course site (the one you’re reading this on) briefly, going over the various sections listed in the navigation bar on the left
- Quick IDeATe walking tour
- Phys Comp Lab tour
- Handing out individual Arduini, and beginning of board tour
- Homework 1 assigned
Thursday, Sep. 1st: Technical learning
- Going over technical questions asked on the asynchronous lecture discussion board
- Homework 2 assigned
Tuesday, Sep. 6th: Technical learning, Project 1 assigned
- Addressing a variety of asynch discussion board questions
- Using our custom version of draw.io for making functional block diagrams
- Student teams each diagram out one of these different devices:
- airplane
- microwave
- car
- traffic signal with pedestrian button
- refrigerator
- How to search for parts in the Phys Comp Lab: use the Phys Comp Lab inventory page, wait for it to load, and do a regular browser text search to find what you’re looking for
- Project 1: A Double Transducer assigned
- Homework 3: Finishing Asynch Lectures assigned
codebook: a bad way of building a toggle switch out of a button
// make a variable to hold the maintained state
int switchState;
const int LEDPIN = 6;
void setup() {
pinMode(LEDPIN, OUTPUT);
}
void loop() {
// if button is pressed right now
if (digitalRead(BUTTONPIN) == HIGH) {
switchState = !switchState;
}
digitalWrite(LEDPIN, switchState);
}
Thursday, Sep. 8th: Project 1 discussion
- Asynchronous questions addressed during class
const int
is preferred for naming variables that won’t change, like pin assignment numbers- See codebook below for some fiddling-around we did looking at the
#define
command, which is a “preprocessor directive” - Most of class is spent talking with Project 1 groups about their ideation submissions
codebook: #define
vs. const int
, among other things
Note: this was left super incomplete! In class we discussed how our in-class style prefers using const int
for naming pin numbers
#define ANOTHERVARIABLE 4.3
int thingToChange = 8;
const int THINGTHATWONTCHANGE = 4;
void setup() {
int newOne = ANOTHERVARIABLE;
thingToChange = 10;
// THINGTHATWONTCHANGE = 15;
}
codebook: finding the position of a servo motor (but not actually)
This code includes the command doorMotor.read()
, which looks like it might talk to the servo motor, find what its current position is, and report that back to the Arduino. Actually, that’s not what it does—it simply reports back whever the servo motor was last told to go. It doesn’t know if it’s gotten there yet!
int value = 1082;
Servo doorMotor;
void setup() {
// put your setup code here, to run once:
}
void loop() {
doorMotor.write(180);
int position = doorMotor.read(); // this probably doesn't do what you think!
}
Tuesday, Sep, 13th: Variable types and event loop programming
- Different data types for variables in the Arduino environment:
bool
:true
orfalse
int
: whole number in range –32,268 to 32,767unsigned int
: the same number of values asint
, but starting at 0, so: range is 0 to 65,535long
: whole number in range approximately –2.1 billion to 2.1 billionunsigned long
: the same number of values aslong
, but starting at 0, so: range is 0 to about 4.3 billionfloat
: “floating point” number, meaning something with a decimal in it like 1.543 or –10493.25, but with limits (afloat
has 6 or 7 digits of precision, so it wouldn’t store 9872.19886757275). Range is about –3.4 × 1038 to 3.4 × 1038char
: short for “character,” things likea
,Q
,?
, or even8
(as a character, not the value 8)String
: a “string” of characters put together, like"Abracadabra!" she yelled.
or735
(that last one is not a number—it’s aString
so it has no numerical value)- Read lots more details at this section of the main Arduino reference page
- How to juggle multiple events on different timers, without using
delay()
: the event-loop programming model (see below) - Remainder of day is a work session
codebook: basic outline of event loop programming
This software structure will allow you to juggle a variety of different events on different schedules, so that you can run more complicated sketches without needing long delay()
s (which are almost always the wrong way to do things).
For a more complete example and further explanation, see the “Blink Without Blocking” section of the Code Bytes page.
unsigned long eventTimer = 0;
unsigned long LCDtimer = 0;
void setup() {
// put your setup code here, to run once:
}
void loop() {
find the pos. of the pot.
// event-loop programming
if (millis() - eventTimer >= 333) {
turn the LED on or off;
// reset the timer!
eventTimer = millis();
}
if (millis() - LCDtimer >= 100) {
send info. back to the user
LCDtimer = millis();
}
}
Thursday, Sep. 15th: Debugging techniques
- Handed out and briefly demonstrated: multimeter
- measure voltages to make sure things are getting or sending power
- measure resistance to confirm correct resistance between points in your circuit
- measure continuity to make sure that things are connected as you expect
- Reading resistor color codes to know their values
- Code notes (fixing a piece of sample code with problems)
- General recommended code structure—in your loop:
- find information about the world
- process that information however you’d like
- change/drive/actuate outputs
- report information back to the user
- Remainder of class is work time
- Project 1 is due in one week
- Reminder: take pictures as you go!
codebook: faulty sketch that we fixed
const int POTPIN = A1;
int potVal = -10;
const int led_pin = A3;
bool LEDVal = false;
void setup() {
Serial.begin(9600);
pinMode(led_pin, OUTPUT);
}
void loop() {
//1. read data
potVal = analogRead(POTPIN);
//2. calculate or make decisions
if (potVal > 100) {
LEDVal = true;
}
else {
LEDVal = false;
}
//3.
digitalWrite(led_pin, LEDVal);
//4.
Serial.println((String)"potVal = " + potVal
+ "; LEDVal = " + LEDVal);
delay(100);
}
Tuesday, Sep. 20: Project 1 work day
- Debugging by functional unit-level analysis—get known-working subsystems and put them together to make your bigger system piece by piece
- Remember to take pictures as you go!
Thursday, Sep. 22: Project 1 presentations
- Teams present in transduction-chain order for ~10 minutes (with Q&A)
- A glorious and somewhat-successful assembly of the final transducer at the end!