Components and supplies
Pushbutton switch 12mm
Arduino UNO
Shift Register- Serial to Parallel
5 mm LED: Red
Male/Male Jumper Wires
5 mm LED: Green
Resistor 221 ohm
Apps and platforms
Arduino IDE
Project description
Code
Diwali lights
arduino
1/* 2 * Author: ***** *** <rohroexperiment@gmail.com> 3 * File: diwali_lights.ino 4 * Description: Diwali lights 5*/ 6/* 7 * Pin connections: 8 * 74HC595 9 * Pins 1-7 -> LED(of your choice) 10 * Pin 8 -> GND 11 * Pin 9 -> N/C 12 * Pin 10 -> VCC 13 * Pin 11 -> Arduino pin 3 14 * Pin 12 -> Arduino pin 4 15 * Pin 13 -> GND 16 * Pin 14 -> Arduino pin 5 17 * Pin 15 -> LED(of your choice) 18 * Pin 16 -> VCC 19 * Other: 20 * Push button 21 * One side to arduino pin 2 22 * Other side to GND 23*/ 24#define MAXANIMATIONS 6 25int data = 5; 26int clock = 3; 27int latch = 4; 28int brightness = 200; 29int animation = 1; 30//Used for single LED manipulation 31int ledState = 0; 32const int ON = HIGH; 33const int OFF = LOW; 34byte pattern[] = 35{ 36 B00000001, 37 B00000010, 38 B00000100, 39 B00001000, 40 B00010000, 41 B00100000, 42 B01000000, 43 B10000000, 44 B01000000, 45 B00100000, 46 B00010000, 47 B00001000, 48 B00000100, 49 B00000010 50}; 51byte pattern2[] { 129, 66, 36, 24, 36, 66}; 52byte pattern3[] {B10000000, B00100000, B00001000, B00000010, B00000001, B00000100, B00010000, B01000000}; 53void setup() 54{ 55 pinMode(2, INPUT_PULLUP); 56 attachInterrupt(0, nextAnimation, FALLING); 57 pinMode(data, OUTPUT); 58 pinMode(clock, OUTPUT); 59 pinMode(latch, OUTPUT); 60 Serial.begin(9600); 61 62} 63void nextAnimation () { 64 if (digitalRead(2) == LOW) { 65 delayMicroseconds(10000); 66 if (digitalRead(2) == LOW) { 67 if (animation == MAXANIMATIONS) animation = 1; 68 else animation++; 69 } 70 while (digitalRead(2) == LOW); 71 } 72} 73/* 74 loop() - this function will start after setup finishes and then repeat 75 we set which LEDs we want on then call a routine which sends the states to the 74HC595 76*/ 77void loop() // run over and over again 78{ 79 80 81 82 if (animation == 1) animation1(); 83 else if (animation == 2) animation2(); 84 else if (animation == 3) animation3(); 85 else if (animation == 4) animation4(); 86 else if (animation == 5) animation5(); 87 else if (animation == 6) animation6(); 88} 89void animation1 () { 90 91 updateLEDs(0x55); 92 delay(1000); 93 updateLEDs(B10101010); 94 delay(1000); 95 96} 97void animation2 () { 98 99 for (int i = 0; i < sizeof(pattern); i++) { 100 updateLEDs(pattern[i]); 101 delay(250); 102 103 } 104} 105void animation3() { 106 107 randomSeed(analogRead(A1)); 108 updateLEDs(random(255)); 109 delay(1000); 110 111} 112void animation4() { 113 updateLEDs(0xff); 114 delay(100); 115 updateLEDs(0); 116 delay(100); 117} 118void animation5() { 119 for (int i = 0; i < sizeof(pattern2); i++) { 120 updateLEDs(pattern2[i]); 121 delay(250); 122 } 123} 124void animation6() { 125 for (int i = 0; i < sizeof(pattern3); i++) { 126 updateLEDs(pattern3[i]); 127 delay(250); 128 } 129} 130/* 131 updateLEDs() - sends the LED states set in ledStates to the 74HC595 132 sequence 133*/ 134void updateLEDs(int value) { 135 //digitalWrite(latch, LOW); //Pulls the chips latch low 136 //shiftOut(data, clock, LSBFIRST, value); //Shifts out the 8 bits to the shift register 137 //digitalWrite(latch, HIGH); //Pulls the latch high displaying the data 138 digitalWrite(latch, LOW); //Pulls the chips latch low 139 for (int i = 0; i < 8; i++) { //Will repeat 8 times (once for each bit) 140 int bit = value & B10000000; //We use a "bitmask" to select only the eighth 141 //bit in our number (the one we are addressing this time through 142 value = value << 1; //we move our number up one bit value so next time bit 7 will be 143 //bit 8 and we will do our math on it 144 if (bit == 128) { 145 digitalWrite(data, HIGH); //if bit 8 is set then set our data pin high 146 } 147 else { 148 digitalWrite(data, LOW); 149 } 150 //if bit 8 is unset then set the data pin low 151 digitalWrite(clock, HIGH); //the next three lines pulse the clock pin 152 delay(1); 153 digitalWrite(clock, LOW); 154 } 155 digitalWrite(latch, HIGH); 156} 157 158 159 160
Diwali lights
arduino
1/* 2 * Author: ***** *** <rohroexperiment@gmail.com> 3 * File: diwali_lights.ino 4 5 * Description: Diwali lights 6*/ 7/* 8 * Pin connections: 9 * 74HC595 10 11 * Pins 1-7 -> LED(of your choice) 12 * Pin 8 -> GND 13 * Pin 9 14 -> N/C 15 * Pin 10 -> VCC 16 * Pin 11 -> Arduino pin 3 17 * Pin 18 12 -> Arduino pin 4 19 * Pin 13 -> GND 20 * Pin 14 -> Arduino pin 5 21 22 * Pin 15 -> LED(of your choice) 23 * Pin 16 -> VCC 24 * Other: 25 26 * Push button 27 * One side to arduino pin 2 28 * Other side to 29 GND 30*/ 31#define MAXANIMATIONS 6 32int data = 5; 33int clock = 3; 34int latch 35 = 4; 36int brightness = 200; 37int animation = 1; 38//Used for single LED manipulation 39int 40 ledState = 0; 41const int ON = HIGH; 42const int OFF = LOW; 43byte pattern[] 44 = 45{ 46 B00000001, 47 B00000010, 48 B00000100, 49 B00001000, 50 B00010000, 51 52 B00100000, 53 B01000000, 54 B10000000, 55 B01000000, 56 B00100000, 57 58 B00010000, 59 B00001000, 60 B00000100, 61 B00000010 62}; 63byte pattern2[] 64 { 129, 66, 36, 24, 36, 66}; 65byte pattern3[] {B10000000, B00100000, B00001000, 66 B00000010, B00000001, B00000100, B00010000, B01000000}; 67void setup() 68{ 69 70 pinMode(2, INPUT_PULLUP); 71 attachInterrupt(0, nextAnimation, FALLING); 72 73 pinMode(data, OUTPUT); 74 pinMode(clock, OUTPUT); 75 pinMode(latch, OUTPUT); 76 77 Serial.begin(9600); 78 79} 80void nextAnimation () { 81 if (digitalRead(2) 82 == LOW) { 83 delayMicroseconds(10000); 84 if (digitalRead(2) == LOW) { 85 86 if (animation == MAXANIMATIONS) animation = 1; 87 else animation++; 88 89 } 90 while (digitalRead(2) == LOW); 91 } 92} 93/* 94 loop() - this 95 function will start after setup finishes and then repeat 96 we set which LEDs 97 we want on then call a routine which sends the states to the 74HC595 98*/ 99void 100 loop() // run over and over again 101{ 102 103 104 105 if (animation 106 == 1) animation1(); 107 else if (animation == 2) animation2(); 108 else if (animation 109 == 3) animation3(); 110 else if (animation == 4) animation4(); 111 else if (animation 112 == 5) animation5(); 113 else if (animation == 6) animation6(); 114} 115void animation1 116 () { 117 118 updateLEDs(0x55); 119 delay(1000); 120 updateLEDs(B10101010); 121 122 delay(1000); 123 124} 125void animation2 () { 126 127 for (int i = 0; i < sizeof(pattern); 128 i++) { 129 updateLEDs(pattern[i]); 130 delay(250); 131 132 } 133} 134void 135 animation3() { 136 137 randomSeed(analogRead(A1)); 138 updateLEDs(random(255)); 139 140 delay(1000); 141 142} 143void animation4() { 144 updateLEDs(0xff); 145 delay(100); 146 147 updateLEDs(0); 148 delay(100); 149} 150void animation5() { 151 for (int i = 152 0; i < sizeof(pattern2); i++) { 153 updateLEDs(pattern2[i]); 154 delay(250); 155 156 } 157} 158void animation6() { 159 for (int i = 0; i < sizeof(pattern3); i++) 160 { 161 updateLEDs(pattern3[i]); 162 delay(250); 163 } 164} 165/* 166 updateLEDs() 167 - sends the LED states set in ledStates to the 74HC595 168 sequence 169*/ 170void 171 updateLEDs(int value) { 172 //digitalWrite(latch, LOW); //Pulls the chips latch 173 low 174 //shiftOut(data, clock, LSBFIRST, value); //Shifts out the 8 bits to the 175 shift register 176 //digitalWrite(latch, HIGH); //Pulls the latch high displaying 177 the data 178 digitalWrite(latch, LOW); //Pulls the chips latch low 179 for 180 (int i = 0; i < 8; i++) { //Will repeat 8 times (once for each bit) 181 int bit 182 = value & B10000000; //We use a "bitmask" to select only the eighth 183 //bit 184 in our number (the one we are addressing this time through 185 value = value 186 << 1; //we move our number up one bit value so next time bit 7 will be 187 188 //bit 8 and we will do our math on it 189 if (bit == 128) { 190 digitalWrite(data, 191 HIGH); //if bit 8 is set then set our data pin high 192 } 193 else { 194 digitalWrite(data, 195 LOW); 196 } 197 //if bit 8 is unset then set the data pin low 198 digitalWrite(clock, 199 HIGH); //the next three lines pulse the clock pin 200 delay(1); 201 202 digitalWrite(clock, LOW); 203 } 204 digitalWrite(latch, HIGH); 205} 206 207 208 209
Downloadable files
PCB
PCB
PCB
PCB
Schematic + Breadboard
(No PCB)
Schematic + Breadboard
Comments
Only logged in users can leave comments