Skip to content

Instantly share code, notes, and snippets.

@Miceuz
Created August 6, 2015 10:14
Show Gist options
  • Save Miceuz/faec7b57ead5d28a7077 to your computer and use it in GitHub Desktop.
Save Miceuz/faec7b57ead5d28a7077 to your computer and use it in GitHub Desktop.
Kazimiero širdis
#define BPM 85//beats per minute
#define fadeinLength 20 //milliseconds
#define fadeoutLength fadeinLength * 3
#define fadeinPause fadeinLength * 1000L / 255
#define fadeoutPause fadeoutLength * 1000L /255
#define pause 60000/BPM - 255*fadeinPause*1e-3 - 255*fadeoutPause*1e-3
int ledPin = 5; // LED connected to digital pin 9
void setup() {
// nothing happens in setup
}
void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue++) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
delayMicroseconds(fadeinPause);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delayMicroseconds(fadeoutPause);
}
delay(pause);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment