more fun with shift registers:
adding a potentiometer to control the led being lit up.
feel free to subscribe:
the code:
int dataPin = 11;
int latchPin = 8;
int clockPin = 12;
long unsigned binary[]= {1 , 2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,
32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608};// 24 values since there are 24 leds
// 1 , 10 ,100 , 1000 , 10000 ....... in binary
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
long unsigned bin=1;
int pot = analogRead(A0);
int mymap=map(pot,0,1014,1,24);//map the range of the values from led 1 to led 24
bin=binary[mymap-1];//gets into bin the correct value to turn it on from the array
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, bin);
shiftOut(dataPin, clockPin, MSBFIRST,bin>>8);
shiftOut(dataPin, clockPin, MSBFIRST,bin>>16);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
}