Analog Input Lab 3

September 25, 2007

I thought I had it all figured out until… things just up and stopped working. For one, LED with a value of 0 is all the way on, while 255 is LED off. I thought this was completely opposite the way things were. Is it possible that maybe i reversed a component in my circuit to cause this? I dunno…. code as it is:

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:

void loop() {
potValue = analogRead(potPin); // read the pot value
if(potValue/4 <= 150){
analogWrite(led, 255);
analogWrite(led, potValue/4);
Serial.println(potValue/4); // print the pot value back to the debugger pane
delay(10); // wait 10 milliseconds before the next loop

The LED is illuminated, when potValue decreases towards 150, the light gets BRIGHTER, before shutting completely off when my finger is placed over the photoresistor.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s