Components and supplies
Resistor 10k ohm
Tactile Switch, Top Actuated
Photo resistor
WS2812B Digital RGB LED Flexi-Strip 144 LED - 1 Meter
IoT Training Controller Light Sound Sensor Action
Arduino Nano R3
Real Time Clock (RTC)
Tools and machines
Soldering iron (generic)
Solder Wire, Lead Free
3D Printer (generic)
Project description
Code
ClockAndParty
c_cpp
This is the code that makes it all work toghter. This could be uptimized but it works.
1//program lavet af Paw Johnsen 2 3//include the libraries 4#include <DS3231_Simple.h> //clock librarie 5#include <FastLED.h> //LED librarie 6 7DS3231_Simple Clock; 8 9//defining things 10#define DATA_PIN 7 //data pin for LED 11#define NUM_LEDS 120 //number of LED 12#define BRIGHTNESS 100 //brightness 13#define LENG 100 //lenght of an array to determin the brightness 14#define RES A0 //light sensor pin 15#define SOUNDINPUT A1 //microphone Pin 16#define SWITCH 2 //button Pin 17 18CRGBPalette16 currentPalette; 19TBlendType currentBlending; 20 21extern CRGBPalette16 myRedWhiteBluePalette; 22extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; 23 24CRGB leds[NUM_LEDS]; 25 26/* 27 this array is containing bolcks of the segment[7] and the LED pr. 28 blocks[4]. this will later be filled with LED numbers. 29*/ 30int sectionArray[7][4]; 31 32/* this is arrays that contain the blocks that needs to be lit to show the number. 33*/ 34int min1[2] = {0, 4}; 35int min2[5] = {0, 1, 3, 5, 6}; 36int min3[5] = {0, 1, 3, 4, 5}; 37int min4[4] = {0, 2, 3, 4}; 38int min5[5] = {1, 2, 3, 4, 5}; 39int min6[6] = {1, 2, 3, 4, 5, 6}; 40int min7[3] = {0, 1, 4}; 41int min8[7] = {0, 1, 2, 3, 4, 5, 6}; 42int min9[6] = {0, 1, 2, 3, 4, 5}; 43int min0[6] = {0, 1, 2, 4, 5, 6}; 44 45/* This struct will be used to calculate what LEDs that should turn on. 46 for instants, if block 0 is going to be lit, than that is LED number 0,1,2 and 3, that should be lit. 47*/ 48struct calculatedArr { 49 int arrLeng = 0; 50 int holderArr[][4]; 51} calArr; 52 53 54// defines what minut it is 55int minuteFirst; 56int minuteSecound; 57 58//defines what hours it is 59int hourFirst; 60int hourSecound; 61 62/*for this array to work it needed to be pre determint befor the program startet, therefor its difined here. 63*/ 64int arr[LENG] = { 65 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 66 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 67 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 68 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 69 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 70}; 71 72// the average value of the photoresistor 73int gennemsnit = 0; 74 75 76/* soundInput er den variable der skal holde hvad lydstyrke der bliver læst 77 soundZero er den værdi som der bliver opfanget når der er stille. 78 Dette er fordi den læser imellem 0 og 1028 når der er 5v sat til. 79 soundBuffer er en tolerance værdi, som bruges så det nemmere at justere mikrofonen i virkeligheden. 80*/ 81int soundInput = 0; 82int soundZero = 512; 83int soundBuffer = 3; 84int soundArr[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 85 86/*The next 4 values are for a debouncer, if ClockOrRock = true, then "PartyModen" is running. 87*/ 88int buttonPos = LOW; 89int lastButtonPos = LOW; 90 91unsigned long lastDebounceTimer = 0; 92unsigned long debounceDelay = 50; 93 94bool clockOrRock = false; 95 96void setup() { 97 delay( 3000 ); // safety delay 98 99 FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); //STarts the LEDs 100 FastLED.setBrightness( BRIGHTNESS ); //stes the brightness of the LEDs 101 FastLED.show(); //turn on LEDs 102 103 Serial.begin(9600); 104 Clock.begin(); 105 106 pinMode(SWITCH, INPUT); 107 108 delay(100); //safety delay agian 109 110 //update the which LEDs belongs the what "block" in the segment 111 updateSections(); 112} 113 114void loop() { 115 116 Debouncer(); // test if what ClockOrRock is 117 118 //if true clock will be showen 119 if (clockOrRock == true) { 120 findTimeAndShowTime(); //finds the time to be showen 121 fadeLight(); //finds the brightness of the clock 122 } 123 else { 124 // else partyMode Activate 125 CalculateSoundLevel(); 126 } 127} 128 129void Debouncer() { 130 int reading = digitalRead(SWITCH); //what pos is the button 131 132 if (reading != lastButtonPos) { //if not the same as last time 133 lastDebounceTimer = millis(); //than the old time is set to now 134 } 135 // test if there have past more than the debouncedelay 136 if ((millis() - lastDebounceTimer) > debounceDelay) { 137 if (reading != buttonPos) { //test if the button pos have changed 138 buttonPos = reading; //change the "old" pos to the "new" pos 139 140 if (buttonPos == HIGH) { //test if button is down 141 FastLED.clear(); //clear LEDs 142 delay(500); 143 if (clockOrRock == false) { 144 clockOrRock = true; 145 } else 146 clockOrRock = false; 147 } 148 } 149 } 150 lastButtonPos = reading; 151} 152 153//CalculateSoundLevel(), calculates the light level(LEDs to be light) 154void CalculateSoundLevel() { 155 int tempVal; 156 int bigVal = 0; 157 int smallVal = 1000; 158 soundInput = analogRead(SOUNDINPUT); 159 160 for (int i = 0; i < 19; i++) { 161 tempVal = i + 1; 162 soundArr[i] = soundArr[tempVal]; 163 } 164 soundArr[19] = analogRead(SOUNDINPUT); 165 166 for (int i = 0; i < 19; i++) { 167 if (bigVal < soundArr[i]) { 168 bigVal = soundArr[i]; 169 } 170 171 if (smallVal > soundArr[i]) { 172 smallVal = soundArr[i]; 173 } 174 } 175 176 177 178 if (soundInput >= 2) { //the light will only be lit if the sound is bigger than 1. 179 PartyMode(bigVal - smallVal); //turn Party Light on here. 180 } 181 else PartyMode(0); // turn lights off 182} 183 184// PartyMode fuction determins what lights should be lit. 185 186void PartyMode(int soundLevel) { 187 int rightSectionsToSee[2] = {1, 5}; //1,5 is the top and bottom block in a segment. witch is what should be lit. 188 189 fadeToBlackBy(leds, NUM_LEDS, 30); //turn lights off. smaller number faster turn off. 190 191 int ledsShow[2][4]; //holds the LEDs to be lit 192 193 for (int i = 0; i < 2; i++) { 194 for (int j = 0; j < 4; j++) { 195 ledsShow[i][j] = sectionArray[rightSectionsToSee[i]][j]; 196 } 197 } 198 199 //this determins what color and what leds to be lit 200 for (int i = 0; i < soundLevel - soundBuffer; i++) { 201 if (i <= 3) { //first segment is green 202 leds[ledsShow[0][i]] = CRGB(100, 0, 0); 203 leds[ledsShow[1][i]] = CRGB(100, 0, 0); 204 } 205 else if (i >= 4 && i <= 7) {//next segment is yellowish 206 leds[ledsShow[0][i - 4] + 28] = CRGB(100, 100, 0); 207 leds[ledsShow[1][i - 4] + 28] = CRGB(100, 100, 0); 208 209 } 210 else if (i >= 8 && i <= 11) {//next segment is yellowish 211 leds[ledsShow[0][i - 8] + 56] = CRGB(100, 100, 0); 212 leds[ledsShow[1][i - 8] + 56] = CRGB(100, 100, 0); 213 } 214 else if (i >= 12 && i <= 15) {//last segment is red 215 leds[ledsShow[0][i - 12] + 84] = CRGB(0, 100, 0); 216 leds[ledsShow[1][i - 12] + 84] = CRGB(0, 100, 0); 217 } 218 } 219 FastLED.setBrightness(254); 220 FastLED.show(); 221} 222 223 //finds the time and then shows it 224 225void findTimeAndShowTime() { 226 DateTime MyDateAndTime; 227 228 //finds the time 229 MyDateAndTime = Clock.read(); 230 231 //calculates the time in 4 vals. 232 minuteFirst = MyDateAndTime.Minute / 10; 233 minuteSecound = MyDateAndTime.Minute % 10; 234 235 hourFirst = MyDateAndTime.Hour / 10; 236 hourSecound = MyDateAndTime.Hour % 10; 237 238 //turns of all LEDs 239 FastLED.clear(); 240 findNumber(minuteSecound , 0 , CRGB(0, 0, 250)); 241 findNumber(minuteFirst , 28 , CRGB(0, 0, 250)); 242 findNumber(hourSecound , 56 , CRGB(0, 0, 250)); 243 findNumber(hourFirst , 84 , CRGB(0, 0, 250)); 244 245 //turns them on with new vals. 246 FastLED.show(); 247} 248 249 250//findes the number to be shown on the clock 251void findNumber(int digitToDisplay, int offset, CRGB color) { 252 switch (digitToDisplay) { 253 254 case 0: 255 showNumber(min0, sizeof(min0) / sizeof(min0[0]), offset, color); 256 break; 257 258 case 1: 259 showNumber(min1, sizeof(min1) / sizeof(min1[0]), offset, color); 260 break; 261 262 case 2: 263 showNumber(min2, sizeof(min2) / sizeof(min2[0]), offset, color); 264 break; 265 266 case 3: 267 showNumber(min3, sizeof(min3) / sizeof(min3[0]), offset, color); 268 break; 269 270 case 4: 271 showNumber(min4, sizeof(min4) / sizeof(min4[0]), offset, color); 272 break; 273 274 case 5: 275 showNumber(min5, sizeof(min5) / sizeof(min5[0]), offset, color); 276 break; 277 278 case 6: 279 showNumber(min6, sizeof(min6) / sizeof(min6[0]), offset, color); 280 break; 281 282 case 7: 283 showNumber(min7, sizeof(min7) / sizeof(min7[0]), offset, color); 284 break; 285 286 case 8: 287 showNumber(min8, sizeof(min8) / sizeof(min8[0]), offset, color); 288 break; 289 290 case 9: 291 showNumber(min9, sizeof(min9) / sizeof(min9[0]), offset, color); 292 break; 293 294 default: 295 break; 296 } 297} 298 299 //This funciton handles the LEDs, and will show what we want. 300void showNumber(int numArr[], int sizeArr, int offsetPos, CRGB colorToUse) { 301 calArr = whatNr(calArr, numArr, sizeArr); 302 // the struct is equal to the LEDs that will be shown, and the size of arr 303 304 //here we set the color of the diffrent LEDs that later will be lit. 305 for (int x = 0; x < calArr.arrLeng; x++) { 306 for (int y = 0; y < 4; y++) { 307 leds[calArr.holderArr[x][y] + offsetPos] = colorToUse; 308 } 309 } 310} 311 312/*this function will calculate wich LEDs in the segment that should be lit. It makes it easier to modify too for example show letters or other things. 313*/ 314struct calculatedArr whatNr(struct calculatedArr & cATemp, int whatNumber[], int sizeOfArray) { 315 316 cATemp.arrLeng = sizeOfArray; 317 318 cATemp.holderArr[sizeOfArray][4]; 319 320 //Finds LEDs to show given from whatNumber[] 321 for (int i = 0; i < sizeOfArray; i++) { 322 for (int j = 0; j < 4; j++) { 323 cATemp.holderArr[i][j] = sectionArray[whatNumber[i]][j]; 324 } 325 } 326 return cATemp; //it returns the calculated leds. 327} 328 329//fading the lights to the room light 330void fadeLight() { 331 int temp = 0; 332 333// claculates the avrage(gennemsnit) from the photoresistor 334 for (int i = 0; i < LENG; i++) { 335 gennemsnit = gennemsnit + arr[i]; 336 temp = i + 1; 337 arr[i] = arr[temp]; 338 } 339 arr[LENG] = analogRead(RES); 340 341 gennemsnit = gennemsnit / LENG; 342 343 /*here we can change the brightness of the leds. this is what I need the for my room, change it to youre light level in the room 344 */ 345 if (gennemsnit >= 101) { 346 gennemsnit *= 2; 347 } 348 else if (gennemsnit >= 51 && gennemsnit <= 100) { 349 gennemsnit *= 2.5; 350 } 351 else if (gennemsnit >= 21 && gennemsnit <= 50) { 352 gennemsnit *= 3; 353 } 354 else if (gennemsnit >= 5 && gennemsnit <= 20) { 355 gennemsnit *= 4; 356 } 357 else if (gennemsnit < 4) { 358 gennemsnit = 0; 359 } 360 if (gennemsnit > 255 ) { 361 gennemsnit = 255; 362 } 363 364 FastLED.setBrightness(gennemsnit); 365 366 //restes the avrage to 0. 367 gennemsnit = 0; 368} 369 370/* 371this tells the program where all the LEDs are placed, in wich block in segment, it works, but is alittle complicated 372*/ 373void updateSections() { 374 for (int i = 0; i < 7; i++) { 375 for (int j = 0; j < 4; j++) { 376 if (i == 0) { 377 sectionArray[i][j] = j; 378 } 379 if (i > 0 && j == 0) { 380 sectionArray[i][j] = sectionArray[i - 1][j + 3] + 1; 381 } else if (i > 0 && j != 0) { 382 sectionArray[i][j] = sectionArray[i][j - 1] + 1; 383 } 384 } 385 } 386}
ClockAndParty
c_cpp
This is the code that makes it all work toghter. This could be uptimized but it works.
1//program lavet af Paw Johnsen 2 3//include the libraries 4#include <DS3231_Simple.h> //clock librarie 5#include <FastLED.h> //LED librarie 6 7DS3231_Simple Clock; 8 9//defining things 10#define DATA_PIN 7 //data pin for LED 11#define NUM_LEDS 120 //number of LED 12#define BRIGHTNESS 100 //brightness 13#define LENG 100 //lenght of an array to determin the brightness 14#define RES A0 //light sensor pin 15#define SOUNDINPUT A1 //microphone Pin 16#define SWITCH 2 //button Pin 17 18CRGBPalette16 currentPalette; 19TBlendType currentBlending; 20 21extern CRGBPalette16 myRedWhiteBluePalette; 22extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; 23 24CRGB leds[NUM_LEDS]; 25 26/* 27 this array is containing bolcks of the segment[7] and the LED pr. 28 blocks[4]. this will later be filled with LED numbers. 29*/ 30int sectionArray[7][4]; 31 32/* this is arrays that contain the blocks that needs to be lit to show the number. 33*/ 34int min1[2] = {0, 4}; 35int min2[5] = {0, 1, 3, 5, 6}; 36int min3[5] = {0, 1, 3, 4, 5}; 37int min4[4] = {0, 2, 3, 4}; 38int min5[5] = {1, 2, 3, 4, 5}; 39int min6[6] = {1, 2, 3, 4, 5, 6}; 40int min7[3] = {0, 1, 4}; 41int min8[7] = {0, 1, 2, 3, 4, 5, 6}; 42int min9[6] = {0, 1, 2, 3, 4, 5}; 43int min0[6] = {0, 1, 2, 4, 5, 6}; 44 45/* This struct will be used to calculate what LEDs that should turn on. 46 for instants, if block 0 is going to be lit, than that is LED number 0,1,2 and 3, that should be lit. 47*/ 48struct calculatedArr { 49 int arrLeng = 0; 50 int holderArr[][4]; 51} calArr; 52 53 54// defines what minut it is 55int minuteFirst; 56int minuteSecound; 57 58//defines what hours it is 59int hourFirst; 60int hourSecound; 61 62/*for this array to work it needed to be pre determint befor the program startet, therefor its difined here. 63*/ 64int arr[LENG] = { 65 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 66 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 67 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 68 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 69 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 70}; 71 72// the average value of the photoresistor 73int gennemsnit = 0; 74 75 76/* soundInput er den variable der skal holde hvad lydstyrke der bliver læst 77 soundZero er den værdi som der bliver opfanget når der er stille. 78 Dette er fordi den læser imellem 0 og 1028 når der er 5v sat til. 79 soundBuffer er en tolerance værdi, som bruges så det nemmere at justere mikrofonen i virkeligheden. 80*/ 81int soundInput = 0; 82int soundZero = 512; 83int soundBuffer = 3; 84int soundArr[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 85 86/*The next 4 values are for a debouncer, if ClockOrRock = true, then "PartyModen" is running. 87*/ 88int buttonPos = LOW; 89int lastButtonPos = LOW; 90 91unsigned long lastDebounceTimer = 0; 92unsigned long debounceDelay = 50; 93 94bool clockOrRock = false; 95 96void setup() { 97 delay( 3000 ); // safety delay 98 99 FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); //STarts the LEDs 100 FastLED.setBrightness( BRIGHTNESS ); //stes the brightness of the LEDs 101 FastLED.show(); //turn on LEDs 102 103 Serial.begin(9600); 104 Clock.begin(); 105 106 pinMode(SWITCH, INPUT); 107 108 delay(100); //safety delay agian 109 110 //update the which LEDs belongs the what "block" in the segment 111 updateSections(); 112} 113 114void loop() { 115 116 Debouncer(); // test if what ClockOrRock is 117 118 //if true clock will be showen 119 if (clockOrRock == true) { 120 findTimeAndShowTime(); //finds the time to be showen 121 fadeLight(); //finds the brightness of the clock 122 } 123 else { 124 // else partyMode Activate 125 CalculateSoundLevel(); 126 } 127} 128 129void Debouncer() { 130 int reading = digitalRead(SWITCH); //what pos is the button 131 132 if (reading != lastButtonPos) { //if not the same as last time 133 lastDebounceTimer = millis(); //than the old time is set to now 134 } 135 // test if there have past more than the debouncedelay 136 if ((millis() - lastDebounceTimer) > debounceDelay) { 137 if (reading != buttonPos) { //test if the button pos have changed 138 buttonPos = reading; //change the "old" pos to the "new" pos 139 140 if (buttonPos == HIGH) { //test if button is down 141 FastLED.clear(); //clear LEDs 142 delay(500); 143 if (clockOrRock == false) { 144 clockOrRock = true; 145 } else 146 clockOrRock = false; 147 } 148 } 149 } 150 lastButtonPos = reading; 151} 152 153//CalculateSoundLevel(), calculates the light level(LEDs to be light) 154void CalculateSoundLevel() { 155 int tempVal; 156 int bigVal = 0; 157 int smallVal = 1000; 158 soundInput = analogRead(SOUNDINPUT); 159 160 for (int i = 0; i < 19; i++) { 161 tempVal = i + 1; 162 soundArr[i] = soundArr[tempVal]; 163 } 164 soundArr[19] = analogRead(SOUNDINPUT); 165 166 for (int i = 0; i < 19; i++) { 167 if (bigVal < soundArr[i]) { 168 bigVal = soundArr[i]; 169 } 170 171 if (smallVal > soundArr[i]) { 172 smallVal = soundArr[i]; 173 } 174 } 175 176 177 178 if (soundInput >= 2) { //the light will only be lit if the sound is bigger than 1. 179 PartyMode(bigVal - smallVal); //turn Party Light on here. 180 } 181 else PartyMode(0); // turn lights off 182} 183 184// PartyMode fuction determins what lights should be lit. 185 186void PartyMode(int soundLevel) { 187 int rightSectionsToSee[2] = {1, 5}; //1,5 is the top and bottom block in a segment. witch is what should be lit. 188 189 fadeToBlackBy(leds, NUM_LEDS, 30); //turn lights off. smaller number faster turn off. 190 191 int ledsShow[2][4]; //holds the LEDs to be lit 192 193 for (int i = 0; i < 2; i++) { 194 for (int j = 0; j < 4; j++) { 195 ledsShow[i][j] = sectionArray[rightSectionsToSee[i]][j]; 196 } 197 } 198 199 //this determins what color and what leds to be lit 200 for (int i = 0; i < soundLevel - soundBuffer; i++) { 201 if (i <= 3) { //first segment is green 202 leds[ledsShow[0][i]] = CRGB(100, 0, 0); 203 leds[ledsShow[1][i]] = CRGB(100, 0, 0); 204 } 205 else if (i >= 4 && i <= 7) {//next segment is yellowish 206 leds[ledsShow[0][i - 4] + 28] = CRGB(100, 100, 0); 207 leds[ledsShow[1][i - 4] + 28] = CRGB(100, 100, 0); 208 209 } 210 else if (i >= 8 && i <= 11) {//next segment is yellowish 211 leds[ledsShow[0][i - 8] + 56] = CRGB(100, 100, 0); 212 leds[ledsShow[1][i - 8] + 56] = CRGB(100, 100, 0); 213 } 214 else if (i >= 12 && i <= 15) {//last segment is red 215 leds[ledsShow[0][i - 12] + 84] = CRGB(0, 100, 0); 216 leds[ledsShow[1][i - 12] + 84] = CRGB(0, 100, 0); 217 } 218 } 219 FastLED.setBrightness(254); 220 FastLED.show(); 221} 222 223 //finds the time and then shows it 224 225void findTimeAndShowTime() { 226 DateTime MyDateAndTime; 227 228 //finds the time 229 MyDateAndTime = Clock.read(); 230 231 //calculates the time in 4 vals. 232 minuteFirst = MyDateAndTime.Minute / 10; 233 minuteSecound = MyDateAndTime.Minute % 10; 234 235 hourFirst = MyDateAndTime.Hour / 10; 236 hourSecound = MyDateAndTime.Hour % 10; 237 238 //turns of all LEDs 239 FastLED.clear(); 240 findNumber(minuteSecound , 0 , CRGB(0, 0, 250)); 241 findNumber(minuteFirst , 28 , CRGB(0, 0, 250)); 242 findNumber(hourSecound , 56 , CRGB(0, 0, 250)); 243 findNumber(hourFirst , 84 , CRGB(0, 0, 250)); 244 245 //turns them on with new vals. 246 FastLED.show(); 247} 248 249 250//findes the number to be shown on the clock 251void findNumber(int digitToDisplay, int offset, CRGB color) { 252 switch (digitToDisplay) { 253 254 case 0: 255 showNumber(min0, sizeof(min0) / sizeof(min0[0]), offset, color); 256 break; 257 258 case 1: 259 showNumber(min1, sizeof(min1) / sizeof(min1[0]), offset, color); 260 break; 261 262 case 2: 263 showNumber(min2, sizeof(min2) / sizeof(min2[0]), offset, color); 264 break; 265 266 case 3: 267 showNumber(min3, sizeof(min3) / sizeof(min3[0]), offset, color); 268 break; 269 270 case 4: 271 showNumber(min4, sizeof(min4) / sizeof(min4[0]), offset, color); 272 break; 273 274 case 5: 275 showNumber(min5, sizeof(min5) / sizeof(min5[0]), offset, color); 276 break; 277 278 case 6: 279 showNumber(min6, sizeof(min6) / sizeof(min6[0]), offset, color); 280 break; 281 282 case 7: 283 showNumber(min7, sizeof(min7) / sizeof(min7[0]), offset, color); 284 break; 285 286 case 8: 287 showNumber(min8, sizeof(min8) / sizeof(min8[0]), offset, color); 288 break; 289 290 case 9: 291 showNumber(min9, sizeof(min9) / sizeof(min9[0]), offset, color); 292 break; 293 294 default: 295 break; 296 } 297} 298 299 //This funciton handles the LEDs, and will show what we want. 300void showNumber(int numArr[], int sizeArr, int offsetPos, CRGB colorToUse) { 301 calArr = whatNr(calArr, numArr, sizeArr); 302 // the struct is equal to the LEDs that will be shown, and the size of arr 303 304 //here we set the color of the diffrent LEDs that later will be lit. 305 for (int x = 0; x < calArr.arrLeng; x++) { 306 for (int y = 0; y < 4; y++) { 307 leds[calArr.holderArr[x][y] + offsetPos] = colorToUse; 308 } 309 } 310} 311 312/*this function will calculate wich LEDs in the segment that should be lit. It makes it easier to modify too for example show letters or other things. 313*/ 314struct calculatedArr whatNr(struct calculatedArr & cATemp, int whatNumber[], int sizeOfArray) { 315 316 cATemp.arrLeng = sizeOfArray; 317 318 cATemp.holderArr[sizeOfArray][4]; 319 320 //Finds LEDs to show given from whatNumber[] 321 for (int i = 0; i < sizeOfArray; i++) { 322 for (int j = 0; j < 4; j++) { 323 cATemp.holderArr[i][j] = sectionArray[whatNumber[i]][j]; 324 } 325 } 326 return cATemp; //it returns the calculated leds. 327} 328 329//fading the lights to the room light 330void fadeLight() { 331 int temp = 0; 332 333// claculates the avrage(gennemsnit) from the photoresistor 334 for (int i = 0; i < LENG; i++) { 335 gennemsnit = gennemsnit + arr[i]; 336 temp = i + 1; 337 arr[i] = arr[temp]; 338 } 339 arr[LENG] = analogRead(RES); 340 341 gennemsnit = gennemsnit / LENG; 342 343 /*here we can change the brightness of the leds. this is what I need the for my room, change it to youre light level in the room 344 */ 345 if (gennemsnit >= 101) { 346 gennemsnit *= 2; 347 } 348 else if (gennemsnit >= 51 && gennemsnit <= 100) { 349 gennemsnit *= 2.5; 350 } 351 else if (gennemsnit >= 21 && gennemsnit <= 50) { 352 gennemsnit *= 3; 353 } 354 else if (gennemsnit >= 5 && gennemsnit <= 20) { 355 gennemsnit *= 4; 356 } 357 else if (gennemsnit < 4) { 358 gennemsnit = 0; 359 } 360 if (gennemsnit > 255 ) { 361 gennemsnit = 255; 362 } 363 364 FastLED.setBrightness(gennemsnit); 365 366 //restes the avrage to 0. 367 gennemsnit = 0; 368} 369 370/* 371this tells the program where all the LEDs are placed, in wich block in segment, it works, but is alittle complicated 372*/ 373void updateSections() { 374 for (int i = 0; i < 7; i++) { 375 for (int j = 0; j < 4; j++) { 376 if (i == 0) { 377 sectionArray[i][j] = j; 378 } 379 if (i > 0 && j == 0) { 380 sectionArray[i][j] = sectionArray[i - 1][j + 3] + 1; 381 } else if (i > 0 && j != 0) { 382 sectionArray[i][j] = sectionArray[i][j - 1] + 1; 383 } 384 } 385 } 386}
Downloadable files
Arduino clock connections
This Is how I connected every component. Note That the Microphone should be able to output analog signal. Agian I used "sound sensor module" can be found on google or in most arduino starter kits. The 3 Pins that are connected to D7 and the battery, is the LED strip.
Arduino clock connections
Comments
Only logged in users can leave comments
majo18
2 years ago
Hi! Is there any chance for me to see the video, currently is not available and I would love to see the dimming lights and the party mode. Would be great help, thanks
Anonymous user
3 years ago
Wow! This is a really cool project!! Could you also share it with our Seeed Discord community? We have a #projects channel to host all amazing projects from the community: https://discord.gg/mjRZ4kA7pD
20122280
5 months ago
For next room