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.

pcomp-wk2-1of2

pcomp-wk2-2of2

pcompwk2-1024pcompwk2-512pcompwk2-0

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.

This entry was posted in ITP, Physical Computing and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Tags

  • Twitter

    • Gathering sticks to improve the nest...