LAB 3: MICROCONTROLLERS Goals - Basic microcontroller understanding - Basic knowledge of the Arduino board in relation to other platforms Small Computers vs. Big Computers - Speed, memory, cost Microcontrollers - Different from a microprocessor - Memory - Microcontroller boards in education (past and present)? - Often programmed in Assembly, C, BASIC - Arduino vs. Wiring Arduino - Board variations - What's on the board . Power select, regulator, options . Analog In . Digital Out (be careful with pin 0,1) . PWM Out (explain PWM) . USB chip . Oscillator - Programming . C . Differences between Processing and Wiring language . loop() . variable declaration . pin definition . etc. Exercises - Build the "knight_rider_3" example (included with the Arduino software). Modify the code to alter the blinking pattern based on another idea. (Reminder, you need to use a resistor with each LEDs, see Igoe p. 99) Reading to complete for next class - Physical Computing (pp. 249 - 283) // Example 1: Analog IN 1. Range of potentiometer with Multimeter. 2. Find corresponding resistor (same value of max resistance) or use... http://people.clarkson.edu/~svoboda/eta/designLab/VoltageDividerDesign.html 3. Build the circuit on breadboard (Igoe, p. 105) 4. Code: int resistorPin = 0; // Select the input pin for the potentiometer int val; // Store value here void setup() { Serial.begin(9600); // Open the serial port at 9600 bps: } void loop() { val = analogRead(resistorPin); // Read the value from the sensor Serial.println(val); // Print as an ASCII-encoded decimal delay(10); } 5. Watch the values, record min and max // Example 2: Analog OUT 1. Solder 8 Ohm speaker 2. Build circuit 3. Code: int outPin = 10; void setup() { } void loop() { analogWrite(outPin, 60); } // Example 3: Analog IN > OUT 1. Build circuit 3. Code: int outPin = 10; // Speaker connected to digital pin 10 int analogPin = 0; // Potentiometer connected to analog pin 0 int val = 0; // Variable to store the read value void setup() { } void loop() { val = analogRead(analogPin); // Read the input pin // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 analogWrite(outPin, val / 4); }