Make the light turn on and off using the light sensor
Equipment:
Light sensor (x1)
resistor (10k Ohm) (x1)
LED
resistor (330 Ohm) (x1)
wire (x6)
Program Details:
I used the one off newinnovators.ca
Time to Program and Complete:
5 minutes
Results:
N/A
Photo/Video Proof:
Program:
int lightPin = 0;
//sets a value for lightPin
int ledPin = 9;
//sets a value for ledPin
void setup()
//declares a setup
{
pinMode(ledPin, OUTPUT);
//sets ledPin as an output
}
void loop()
//declares a setup
{
//start of loop
int lightLevel = analogRead(lightPin);
//introduces a new variable; lightLevel
lightLevel = map(lightLevel, 0, 900, 0, 255);
//lightLevel is equal to...
lightLevel = constrain(lightLevel, 0, 255);
//sets a new value for lightLevel
analogWrite(ledPin, lightLevel);
//turns on ledPin for a value of lightLevel
}
//end of loop
N/A
Helpful Tips:
References:
newinnovators.ca
No comments:
Post a Comment