Copy and paste the code below into a new Arduino sketch. Then, compile and upload it to your metro.
// CIRC09 - Light int lightPin = A0; int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); } void loop() { int lightLevel = analogRead(lightPin); lightLevel = map(lightLevel, 0, 700, 0, 255); analogWrite(ledPin, lightLevel); }
This is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist.
Given that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check its in the right place.
Text editor powered by tinymce.