int latchPin = 12; int clockPin = 11; int dataPin = 13; byte leds1 = 0; byte leds2 = 0; byte leds3 = 0; int piekpin = 8; int sensorPin = A0; int sensorValue = 0; int sensorGrens = 40; //When the LDR sensorvalue is above this value, the pattern changes int count = 0; byte ledpatroon[][4]= { //This is the pattern array. You can change it to your likings. // shiftReg1, shiftReg2, shiftReg3, top // 7 --- 0 7 --- 0 7 --- 0 {0b00000000, 0b00000000, 0b00000000,0}, {0b00000000, 0b00000000, 0b00000000,1}, {0b00000000, 0b00000000, 0b00000011,1}, {0b00000000, 0b00000000, 0b00011111,1}, {0b00000000, 0b00000001, 0b11111111,0}, {0b00000000, 0b00111111, 0b11111100,0}, {0b00001111, 0b11111111, 0b11100000,0}, {0b00111111, 0b11111110, 0b00000000,0}, {0b11111111, 0b11000000, 0b00000000,0}, {0b11110000, 0b00000000, 0b00000000,0}, {0b11000000, 0b00000000, 0b00000000,0}, {0b00000000, 0b00000000, 0b00000000,0}, {0b00000000, 0b00000000, 0b00000000,0}, {0b00000000, 0b00000000, 0b00000000,1}, {0b00000000, 0b00000000, 0b00000011,1}, {0b00000000, 0b00000000, 0b00011111,1}, {0b00000000, 0b00000001, 0b11111111,0}, {0b00000000, 0b00111111, 0b11111100,0}, {0b00001111, 0b11111111, 0b11100000,0}, {0b00111111, 0b11111110, 0b00000000,0}, {0b11111111, 0b11000000, 0b00000000,0}, {0b11110000, 0b00000000, 0b00000000,0}, {0b11000000, 0b00000000, 0b00000000,0}, {0b00000000, 0b00000000, 0b00000000,0}, {0b11111111, 0b11111111, 0b11111111,1}, {0b00000000, 0b00000000, 0b00000000,0}, {0b11111111, 0b11111111, 0b11111111,1}, {0b00000000, 0b00000000, 0b00000000,0}, }; void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(8, OUTPUT); } void loop() { leds1 = 0; leds2 = 0; leds3 = 0; sensorValue = analogRead(sensorPin); if (sensorValue >= sensorGrens) { //Sensor value above threshold: count up if (count < sizeof(ledpatroon)/sizeof(ledpatroon[0])-1) { count++; } else { count = 0; } } else //Now the sensor value is below threshold: the count goes down. Which changes the direction of the pattern { if (count > 0) { count--; } else { count = sizeof(ledpatroon)/sizeof(ledpatroon[0])-1; } } //end if sensorValue digitalWrite(latchPin, LOW); //shift the values from the pattern array in the shift registers, using count as index //we have 3 shiftregisters so we need 3 shift out commands. shiftOut(dataPin, clockPin, MSBFIRST, ledpatroon[count][0]);//leds1); shiftOut(dataPin, clockPin, MSBFIRST, ledpatroon[count][1]);//leds2); shiftOut(dataPin, clockPin, MSBFIRST, ledpatroon[count][2]);//leds3); //the piekpin is done seperately, because we have only 24 shift bits. Buying another shift register for one LED is a bit useless ;-) digitalWrite(piekpin, ledpatroon[count][3]); digitalWrite(latchPin, HIGH); delay(200); }