Amazing Light Effects With LED Chaser
Hello friends, this is 64 LED chaser also night led light effects. Here i used 4 nos shift resistor and one Arduino to control 64 led with 32 channel means two led works as a single led.
Diagram:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
int latchPin = 11; int clockPin = 12; int dataPin = 10; int numOfRegisters = 2; byte* registerState; long effectId = 0; long prevEffect = 0; long effectRepeat = 0; long effectSpeed = 30; void setup() { //Initialize array registerState = new byte[numOfRegisters]; for (size_t i = 0; i < numOfRegisters; i++) { registerState[i] = 0; } //set pins to output so you can control the shift register pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { do{ effectId = random(6); } while (effectId == prevEffect); prevEffect = effectId; switch (effectId) { case 0: effectRepeat = random(1, 2); break; case 1: effectRepeat = random(1, 2); break; case 3: effectRepeat = random(1, 5); break; case 4: effectRepeat = random(1, 2); break; case 5: effectRepeat = random(1, 2); break; } for (int i = 0; i < effectRepeat; i++) { effectSpeed = random(10, 90); switch (effectId) { case 0: effectA(effectSpeed); break; case 1: effectB(effectSpeed); break; case 3: effectC(effectSpeed); break; case 4: effectD(effectSpeed); break; case 6: effectE(effectSpeed); break; } } } void effectA(int speed){ for (int i = 0; i < 16; i++){ for (int k = i; k < 16; k++){ regWrite(k, HIGH); delay(speed); regWrite(k, LOW); } regWrite(i, HIGH); } } void effectB(int speed){ for (int i = 15; i >= 0; i--){ for (int k = 0; k < i; k++){ regWrite(k, HIGH); delay(speed); regWrite(k, LOW); } regWrite(i, HIGH); } } void effectC(int speed){ int prevI = 0; for (int i = 0; i < 16; i++){ regWrite(prevI, LOW); regWrite(i, HIGH); prevI = i; delay(speed); } for (int i = 15; i >= 0; i--){ regWrite(prevI, LOW); regWrite(i, HIGH); prevI = i; delay(speed); } } void effectD(int speed){ for (int i = 0; i < 8; i++){ for (int k = i; k < 8; k++) { regWrite(k, HIGH); regWrite(15 - k, HIGH); delay(speed); regWrite(k, LOW); regWrite(15 - k, LOW); } regWrite(i, HIGH); regWrite(15 - i, HIGH); } } void effectE(int speed){ for (int i = 7; i >= 0; i--){ for (int k = 0; k <= i; k++) { regWrite(k, HIGH); regWrite(15 - k, HIGH); delay(speed); regWrite(k, LOW); regWrite(15 - k, LOW); } regWrite(i, HIGH); regWrite(15 - i, HIGH); } } void regWrite(int pin, bool state){ //Determines register int reg = pin / 8; //Determines pin for actual register int actualPin = pin - (8 * reg); //Begin session digitalWrite(latchPin, LOW); for (int i = 0; i < numOfRegisters; i++){ //Get actual states for register byte* states = ®isterState[i]; //Update state if (i == reg){ bitWrite(*states, actualPin, state); } //Write shiftOut(dataPin, clockPin, MSBFIRST, *states); } //End session digitalWrite(latchPin, HIGH); } |