Last active
August 29, 2015 14:12
-
-
Save blambi/50cabfe0502d534643af to your computer and use it in GitHub Desktop.
Simple test of a VU-Metre
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
#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