Skip to content

Instantly share code, notes, and snippets.

@blambi
Last active August 29, 2015 14:12
Show Gist options
  • Save blambi/50cabfe0502d534643af to your computer and use it in GitHub Desktop.
Save blambi/50cabfe0502d534643af to your computer and use it in GitHub Desktop.
Simple test of a VU-Metre
#define PWM_CNT 2
int pwm_pins[] = {5, 6};
int value = 0;
boolean falling = false;
void setup() {
Serial.begin(9600);
}
void loop() {
for (int x = 0; x<PWM_CNT; x++) {
if (x == 1) {
analogWrite(pwm_pins[x], value);
}
else {
// Take value times 20 if led
analogWrite(pwm_pins[x], min(value*20, 255));
}
}
Serial.print("V: ");
Serial.print(value);
Serial.println();
if (falling) {
value -= 1;
falling = value == 0 ? false : true;
} else {
value += 1;
falling = value != 13 ? false : true;
}
delay(80);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment