This week we studied analog inputs. In lab, I created a circuit using the Arduino to translate analog reads from a potentiometer (switch) into the brightness of an LED.
int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // Value read from the pot
int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
void setup() {
// Initialize serial communications at 9600 bps
Serial.begin(9600);
}
void loop() {
potValue = analogRead(potPin); // read teh pot value
analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte
Serial.println(potValue); // Print the pot value back to the debugger pane
delay(10);
}
Physical Computing – Week 2 Lab
This week we studied analog inputs. In lab, I created a circuit using the Arduino to translate analog reads from a potentiometer (switch) into the brightness of an LED.
int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // Value read from the pot
int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
void setup() {
// Initialize serial communications at 9600 bps
Serial.begin(9600);
}
void loop() {
potValue = analogRead(potPin); // read teh pot value
analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte
Serial.println(potValue); // Print the pot value back to the debugger pane
delay(10);
}
PComp-Wk2-Lab from Steve Aquillano on Vimeo.