Assignment 6.3

Post date: Jul 03, 2010 3:51:22 AM

Photoresistor code:

int potPin = 2; // select the input pin for the potentiometer

int ledPin = 13; // select the pin for the LED

int val = 0; // variable to store the value coming from the sensor

void setup() {

pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT

Serial.begin(9600); // begin serial communication at 9600 bps

}

void loop() {

val = analogRead(potPin); // read the value from the sensor

val = map (val, 0, 245, 0, 1023); // adjusts values to get same flash rates range as potentiometer

digitalWrite(ledPin, HIGH); // turn the ledPin on

delay(val); // stop the program for some time

digitalWrite(ledPin, LOW); // turn the ledPin off

delay(val); // stop the program for some time

Serial.println(val); // print whatever value val is

}

Based off the example Mr. Dickie gave us. I modified the code so that it prints the value of val in the serial monitor and the blink rate range of the LED is similar to that of a potentiometer.