Go Down

Topic: 72 led shiftregister (Read 6325 times) previous topic - next topic

peertje

I made a 72 bit shiftregister with 12 595's.
http://www.youtube.com/watch?v=qLuZGgLERa4

I do not use the shiftout function. Sometimes is don't want to shift out a byte, but just 3 bits (RGB). Therefore I made my function for shifting out the bits.

Code: [Select]
const int latchPin = 11; //Pin connected to latch pin (ST_CP) of 74HC595
const int clockPin = 10; //Pin connected to clock pin (SH_CP) of 74HC595
const int dataPin = 9; //Pin connected to Data in (DS) of 74HC595
boolean aan[] = {
 true};
boolean uit[] = {
 false};
boolean groen[] = {
 0,1,0};
boolean rood[] = {
 0,0,1};
boolean blauw[] = {
 1,0,0};
boolean violet[] = {
 1,0,1};
boolean turk[] = {
 1,1,0};
boolean oranje[] = {
 0,1,1};
boolean wit[] = {
 1,1,1};
boolean zwart[] = {
 0,0,0};

int pauze = 70;
int mode = 0;
long lasttime = 0;
const int lengte = 72;

boolean bar[lengte +1] = {
 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};



void setup() {
 //set pins to output because they are addressed in the main loop
 pinMode(latchPin, OUTPUT);
 pinMode(dataPin, OUTPUT);  
 pinMode(clockPin, OUTPUT);
 shiftdata(lengte, bar);

 Serial.begin(9600);
 Serial.println("start, debug");
}

void loop() {

 switch (mode){
 case 0:
 drop();
 break;
 case 1:
 sinnu1();
 break;
 case 2:
   willekeurig();
   break;
 case 3:
   sinnu3();
   break;
 case 4:
   sinnu4();
   break;
 default:
   mode = 0;
 }
if (millis() >= lasttime + 10000){
 mode ++;
 lasttime = millis();
}


}

void shiftdata(int lengte, boolean data[]){
 digitalWrite(latchPin, LOW);

 for (int i=0; i<lengte; i++){
   digitalWrite(dataPin, data[i]);//bit klaarzetten
   digitalWrite(clockPin, HIGH);//bit shiften
   digitalWrite(clockPin, LOW);
 }
 digitalWrite(latchPin, HIGH);// toon data
}

void sinnu1(){
 int positie = 36 * sin(millis()/250.0) + 36;
 int positie2 = 36 * cos(millis()/250.0) + 36;
 for (int j=0; j<=lengte; j++){
   if (((j <= positie) && (j >= positie2)) || ((j >= positie) && (j <= positie2))){
     bar[j] = 1;
   }
   else
   {
     bar[j] = 0;
   }
 }
 shiftdata(lengte, bar);
}

void sinnu3(){
 int positie = 3*int(12 * sin(millis()/250.0) + 12);
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
   else
   {
     bar[j] = 0;
   }
 }

 positie = 3*int(12 * sin(millis()/250.0 + 0.2) + 12)+1;
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
 }

 positie = 3*int(12 * sin(millis()/250.0 + 0.4) + 12)+2;
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
 }
 shiftdata(lengte, bar);
}



void sinnu4(){
 int positie = 36 * sin(millis()/200.0) + 36;
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
   else
   {
     bar[j] = 0;
   }
 }
 shiftdata(lengte, bar);

 positie = 36 * sin(millis()/225.0) + 36;
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
 }
 shiftdata(lengte, bar);

 positie = 36 * sin(millis()/250.0) + 36;
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
 }
 shiftdata(lengte, bar);

 positie = 36 * sin(millis()/275.0) + 36;
 for (int j=0; j<=lengte; j++){
   if (j== positie){
     bar[j] = 1;
   }
 }
 shiftdata(lengte, bar);
}



void willekeurig(){
 bar[random(lengte+1)] = random(2);
 shiftdata(lengte, bar);
 //delay(pauze);
}



void drop(){
 int kleur = random(3);
 switch (kleur){
 case 0:
   shiftdata(3,rood);

   delay(pauze);
   shiftdata(3,rood);
   break;
 case 1:
   shiftdata(3,groen);

   delay(pauze);
   shiftdata(3,groen);
   break;
 case 2:
   shiftdata(3,blauw);

   delay(pauze);
   shiftdata(3,blauw);
   break;
 default:
   shiftdata(3,zwart);
 }
 delay(pauze);
}





Go Up