Skip to content

Instantly share code, notes, and snippets.

@Miceuz
Last active November 15, 2015 15:38
Show Gist options
  • Save Miceuz/e514dfecb05136e5cbaa to your computer and use it in GitHub Desktop.
Save Miceuz/e514dfecb05136e5cbaa to your computer and use it in GitHub Desktop.
VU meter based on TLC5940 led dimmer
#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