const int NbrLEDs = 8; int latchPin = 5; int clockPin = 6; int dataPin = 4; const int photocellPin = A0; int ledLevel = 0; byte states[8] = {B10000000,B11000000,B11100000,B11110000,B11111000,B11111100,B11111110,B11111111}; int sensorValue = 0; void updateShiftRegister(byte leds){ digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, leds); digitalWrite(latchPin, HIGH); } void setup() { pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(latchPin, OUTPUT); digitalWrite(latchPin, HIGH); } void loop() { sensorValue = analogRead(photocellPin); ledLevel = map(sensorValue, 0, 1023, 0, NbrLEDs); updateShiftRegister(states[ledLevel]); }