Last active
April 2, 2019 20:19
-
-
Save warengonzaga/4212962283020adc17d5692b0634324e to your computer and use it in GitHub Desktop.
Waren's L.E.D Music Visualizer (The Project W.L.E.D.M.V)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Waren's LED Music Visualizer (Project W.L.E.D.M.V) | |
* by Waren Gonzaga | |
* Version: 1.0.1 | |
* | |
* An Arduino project that translates the sound into lights. | |
* Check this project on Instructables.com | |
* Link: https://www.instructables.com/id/Warens-LED-Music-Visualizer | |
* | |
* Contribute to improve this project on gist! | |
* Link: https://gist.github.com/WarenGonzaga/4212962283020adc17d5692b0634324e | |
* | |
* This project is made possible by the following. | |
* Hive Electronics | |
* Connected Cities | |
* | |
* Having Trouble? | |
* Please email me here: warengonzaga.dev@gmail.com | |
* or Just send a quick message to my facebook page. | |
* Link: https://facebook.com/warengonzagaofficialpage | |
* Follow me on twitter: @waren_gonzaga | |
* Visit my website: https://warengonzaga.com/ | |
* | |
* Licensed under Creative Commons BY-NC-SA | |
* Copyright © 2017 Waren Gonzaga | |
*/ | |
//=== Pin Assignment ===// | |
const int DO = 2; // Digital PIN 2 of Arduino | |
const int DA = A0; // Analog PIN 0 of Arduino | |
// Digital PIN 3 to 11 of Arduino | |
const int led_01 = 3; | |
const int led_02 = 4; | |
const int led_03 = 5; | |
const int led_04 = 6; | |
const int led_05 = 7; | |
const int led_06 = 8; | |
const int led_07 = 9; | |
const int led_08 = 10; | |
const int led_09 = 11; | |
/** | |
* Corresponding Sensor Values (Sensor Threshold) | |
* The values has 4 gap values, you can make how many gaps you like. | |
*/ | |
int sVal_01 = 500; // Initial Threshold | |
int sVal_02 = 504; | |
int sVal_03 = 508; | |
int sVal_04 = 508; | |
int sVal_05 = 512; | |
int sVal_06 = 516; | |
int sVal_07 = 520; | |
int sVal_08 = 524; | |
int sVal_09 = 528; | |
int lastPin = 11; // last digital PIN number | |
int totalLED = 9; // total LEDs | |
/** | |
* Additional Settings | |
*/ | |
int debugSwitch = true; // Switch for Debugging: true or false (ctrl+shift+M or ctrl+shift+L) | |
int ledTest = true; // If true it will test the LEDs first before use (you can press reset to check LEDs if running correctly | |
/** | |
* Please keep out don't modify the codes below. | |
* Just edit the variables above, thanks! | |
*/ | |
int sensorvalue = 0; // storage for recording sensor values | |
void setup() { | |
Serial.begin(9600); | |
for (int i = 3; i <= lastPin; i++) { | |
pinMode(i, OUTPUT); | |
} | |
if (ledTest == true) { | |
initTest(); // Initial testing for LED's | |
} | |
} | |
void loop() { | |
sensorvalue = analogRead(DA); // getting sensor values from analog A0 | |
if (debugSwitch == true) { | |
debug(); | |
} else { | |
Serial.println("The debugging mode is set to false!"); | |
} | |
// Lights Animation | |
warenLights(); | |
} | |
void debug() { | |
Serial.print("Sound Value: "); | |
if (sensorvalue >= sVal_01) { | |
Serial.print(sensorvalue); | |
Serial.println(" - LED ON!"); | |
} else { | |
Serial.println(sensorvalue); | |
} | |
} | |
void initTest() { | |
digitalWrite(led_05, HIGH); | |
delay(1000); | |
digitalWrite(led_04, HIGH); | |
digitalWrite(led_06, HIGH); | |
delay(1000); | |
digitalWrite(led_03, HIGH); | |
digitalWrite(led_07, HIGH); | |
delay(1000); | |
digitalWrite(led_02, HIGH); | |
digitalWrite(led_08, HIGH); | |
delay(1000); | |
digitalWrite(led_01, HIGH); | |
digitalWrite(led_09, HIGH); | |
delay(2000); | |
digitalWrite(led_01, LOW); | |
digitalWrite(led_09, LOW); | |
delay(500); | |
digitalWrite(led_02, LOW); | |
digitalWrite(led_08, LOW); | |
delay(500); | |
digitalWrite(led_03, LOW); | |
digitalWrite(led_07, LOW); | |
delay(500); | |
digitalWrite(led_04, LOW); | |
digitalWrite(led_06, LOW); | |
delay(500); | |
digitalWrite(led_05, LOW); | |
} | |
void warenLights() { | |
// Basically the LED will turn on if the sensorvalue reach the threshold | |
if(sensorvalue >= sVal_01) { | |
digitalWrite(led_05, HIGH); | |
} else { | |
digitalWrite(led_05, LOW); | |
} | |
if(sensorvalue >= sVal_02) { | |
digitalWrite(led_04, HIGH); | |
} else { | |
digitalWrite(led_04, LOW); | |
} | |
if(sensorvalue >= sVal_03) { | |
digitalWrite(led_06, HIGH); | |
} else { | |
digitalWrite(led_06, LOW); | |
} | |
if(sensorvalue >= sVal_04) { | |
digitalWrite(led_03, HIGH); | |
} else { | |
digitalWrite(led_03, LOW); | |
} | |
if(sensorvalue >= sVal_05) { | |
digitalWrite(led_07, HIGH); | |
} else { | |
digitalWrite(led_07, LOW); | |
} | |
if(sensorvalue >= sVal_06) { | |
digitalWrite(led_02, HIGH); | |
} else { | |
digitalWrite(led_02, LOW); | |
} | |
if(sensorvalue >= sVal_07) { | |
digitalWrite(led_08, HIGH); | |
} else { | |
digitalWrite(led_08, LOW); | |
} | |
if(sensorvalue >= sVal_08) { | |
digitalWrite(led_01, HIGH); | |
} else { | |
digitalWrite(led_01, LOW); | |
} | |
if(sensorvalue >= sVal_09) { | |
digitalWrite(led_09, HIGH); | |
} else { | |
digitalWrite(led_09, LOW); | |
} | |
} |
You can improve the code for the better just make changes and make a pull request.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should use conditional compiling (#define, #ifdef and so on) instead of some bools that you never change at runtime