Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <ShiftOutX.h>
- #include <ShiftPinNo.h>
- /*
- * LED driver
- * Use 4 595 SR with ShiftOutX
- * on pin 8, 11, 12
- * plus one 33rd LED driven by
- * Arduino pin 13.
- *
- * */
- shiftOutX shiftRegisters(8, 11, 12, MSBFIRST, 4);
- void setLed(int led, boolean state){
- if(led>0 && led<33){
- if(state){
- shiftRegisters.pinOn(led);
- }else{
- shiftRegisters.pinOff(led);
- }
- }
- if(led==33){
- digitalWrite(13, state);
- }
- }
- /*
- * Default Sound reactive Pattern
- *
- * */
- // 2 level array to store pixels of each level
- int srd_levels[][5] = {{ 1, 0, 0, 0, 0}
- , { 2, 0, 0, 0, 0}
- , { 3, 6, 14, 0, 0}
- , { 4, 7, 15, 0, 0}
- , { 5, 8, 10, 16, 21}
- , { 9, 11, 17, 22, 0}
- , {12, 18, 23, 28, 0}
- , {13, 19, 24, 29, 0}
- , {20, 25, 30, 0, 0}
- , {26, 31, 0, 0, 0}
- , {27, 32, 0, 0, 0}
- , {33, 0, 0, 0, 0}};
- void loopSoundReactDiagonal()
- {
- // read input fro pin 0
- int sound = analogRead(0);
- // read the potentiometer value
- // be sure to have a value between 0 and 2
- float p = analogRead(5)/1024.0F*2;
- // by multiplying sound by p
- // the potentiometer can adjust the level
- // of sensibility
- sound = sound * p;
- int i = 0;
- int j = 1;
- // let's scan the 12 levels of sensibility
- while(i<=11)
- {
- int cnt=0;
- // is the sound value higher than the
- // current level (i) sensibility
- boolean isok = sound>256/31*j;
- // scan the current level pixels and
- // set them on or off
- while(cnt<=4){
- setLed(srd_levels[i][cnt], isOk)
- cnt++;
- }
- i++;
- j++;
- }
- // small delay
- delay(10);
- }
- /*
- * Arduino functions
- *
- * */
- void setup(){
- pinMode( 8, OUTPUT); // SR latch
- pinMode(11, OUTPUT); // SR data
- pinMode(12, OUTPUT); // SR clock
- pinMode(13, OUTPUT); // pixel #33
- }
- void loop(){
- loopSoundReactDiagonal() ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement