Make an interactive light show using a proximity sensor, and a bunsh of shift registers and LEDs.
int distance = analogRead(sensor_pin); int scaled = map(distance, min_in, max_in, num_registers*8, 0 ); scaled = constrain(scaled, 0, num_registers*8);Then we call the function light_leds(scaled) and give it the scaled value as input. This function Lights up scaled LEDs connected to the shift registers, or if you have connected the LEDs in the opposite polarity this function will light up num_registers*8 - scaled LEDs. See the entire Arduino sketch below:
/* LucidTronix Light Conductor * For instructions, details and schematic, See: * http://www.lucidtronix.com/tutorials/11 */int clockPin = 8;int latchPin = 9;int dataPin = 10 ;const int num_registers = 6;int sensor_pin = 2;int max_in = 600; // adjust these for different supply voltagesint min_in = 3;boolean on = true;unsigned long last_press = 0;void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT);}void loop() { if(on){ int distance = analogRead(sensor_pin); int scaled = map(distance, min_in, max_in, num_registers*8, 0 ); scaled = constrain(scaled, 0, num_registers*8); light_leds(scaled); } if(digitalRead(0) && millis() - last_press > 400){ on = !on; last_press = millis(); } else if(digitalRead(1) && millis() - last_press > 400){ on = !on; light_leds(255); last_press = millis(); }}/* Individual control fro all the LEDs attached to * daisy-chained shift registers * Scaled is how many LEDs to light up depending on how you wire the LEDs * 0 is either all on or all off 8*num_registers is the opposite */void light_leds(int scaled){ digitalWrite(latchPin, LOW); for (int i = 0; i < num_registers; i++){ // three cases: all on, all off or a mix.. if(i*8 > scaled){ shiftOut(dataPin, clockPin, MSBFIRST, 255); } else if ((i+1)*8 > scaled){ int mod_8 = scaled % 8; byte pow_2_light = 255 >> mod_8; shiftOut(dataPin, clockPin, MSBFIRST, pow_2_light); } else { shiftOut(dataPin, clockPin, MSBFIRST, 0); } } digitalWrite(latchPin, HIGH); delay(60);}
| Title | Description | # | Cost | Link | Picture |
| Sonar Range Finder | Maxbotix Sonar range finder | 1 | $24.95 | Link |
|
| PCB Multi-Shift out | Controls 3 different set of shift registers from analog input(s) | 1 | $7.0 | Link |
|
| Shift Register | IC SHIFT REGISTER 8BIT 16-SOP Tri-State Serial to ParallelValue:74HC | 1 | $0.65 | Link |
|
| LED SMD | LED 3X1.5MM 568NM Green Clear SMDValue:2.2V Green | 8 | $0.18 | Link |
|
Comments: