Last active
November 15, 2015 15:38
-
-
Save Miceuz/e514dfecb05136e5cbaa to your computer and use it in GitHub Desktop.
VU meter based on TLC5940 led dimmer
This file contains hidden or 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
#include "Tlc5940.h" | |
void setup() { | |
Tlc.init(); | |
} | |
uint32_t level = 0; | |
void loop() { | |
int vol; | |
int maxVol = 0; | |
int minVol = 1024; | |
for(int i = 0; i < 50; i++) { | |
vol = analogRead(A0); | |
if(vol > maxVol) { | |
maxVol = vol; | |
} | |
if(vol < minVol) { | |
minVol = vol; | |
} | |
} | |
int vpp = maxVol - minVol; | |
Tlc.clear(); | |
uint32_t newLevel= map(vpp, 0, 400, 0, 4095 * 8); | |
if(newLevel > level) { | |
level = newLevel; | |
} else { | |
if(level > 1000) | |
level-=400; | |
} | |
for(int i = 0; i < int(level / 4095); i++) { | |
Tlc.set(i, 4095); | |
} | |
Tlc.set(int(level/4095), level % 4095); | |
Tlc.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment