Challenge Name
Off and On lights
Author
Joshua Mac
Credit
Aron Graca, Kyle Chan, Carl Villamor
Difficulty Level (1-5)
4
Time to Complete
30 mins
Challenge Description
Have a light sensor turn on 2 Leds
Answer
int lightPin = 0;
int ledPin = 9;
int ledPin2 = 8;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
int lightLevel = analogRead(lightPin);
lightLevel = map(lightLevel, 0, 900, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
analogWrite(ledPin, lightLevel);
analogWrite(ledPin2, lightLevel);
}
Parts list and photo?
ReplyDelete