You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
675 B
36 lines
675 B
//www.elegoo.com
|
|
//2016.12.9
|
|
|
|
int lightPin = 0;
|
|
int latchPin = 11;
|
|
int clockPin = 9;
|
|
int dataPin = 12;
|
|
|
|
int leds = 0;
|
|
|
|
void setup()
|
|
{
|
|
pinMode(latchPin, OUTPUT);
|
|
pinMode(dataPin, OUTPUT);
|
|
pinMode(clockPin, OUTPUT);
|
|
}
|
|
void updateShiftRegister()
|
|
{
|
|
digitalWrite(latchPin, LOW);
|
|
shiftOut(dataPin, clockPin, LSBFIRST, leds);
|
|
digitalWrite(latchPin, HIGH);
|
|
}
|
|
void loop()
|
|
{
|
|
int reading = analogRead(lightPin);
|
|
int numLEDSLit = reading / 57; //1023 / 9 / 2
|
|
if (numLEDSLit > 8) numLEDSLit = 8;
|
|
leds = 0; // no LEDs lit to start
|
|
for (int i = 0; i < numLEDSLit; i++)
|
|
{
|
|
leds = leds + (1 << i); // sets the i'th bit
|
|
}
|
|
updateShiftRegister();
|
|
}
|
|
|
|
|
|
|