Name: Kyle Chan
Credit: i referenced the code of newinnovators.ca
Difficulty Level: 4
Time to complete: 7 minutes
Challenge description: One led turns on when the sensor is covered and another turns on when it is not
Hint:
Answer:
int lightPin = 0;
int ledPin = 9;
int ledPin1 = 10;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(lightPin, INPUT);
}
void loop()
{
int lightLevel = analogRead(lightPin);
lightLevel = map(lightLevel, 0, 900, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
if (lightLevel < 900);
{
digitalWrite (ledPin, HIGH);
digitalWrite (ledPin1, LOW);
}
else if (lightLevel > 900);
{
digitalWrite (ledPin1, HIGH);
digitalWrite (ledPin, LOW);
}
}
No comments:
Post a Comment