Skip to content

Instantly share code, notes, and snippets.

@crossdjinn
Last active December 22, 2018 23:14
Show Gist options
  • Save crossdjinn/d0821cc3e9c9edd26cc58c245eb00b9a to your computer and use it in GitHub Desktop.
Save crossdjinn/d0821cc3e9c9edd26cc58c245eb00b9a to your computer and use it in GitHub Desktop.
C++, Arduino, LED pulse effect everytime different one
int ledPin = 11;
float sinVal;
int ledVal;
void setup(){
pinMode(ledPin, OUTPUT);
}
void loop(){
for(int x=0; x<180; x++) {
if(x == 90){
digitalWrite(LED_BUILTIN, LOW);
delay(random(30000));
digitalWrite(LED_BUILTIN, HIGH);
} else if(x == 179){
digitalWrite(LED_BUILTIN, LOW);
analogWrite(ledPin, LOW);
delay(random(60000));
digitalWrite(LED_BUILTIN, HIGH);
} else {
sinVal = (sin(x*(3.14159265359/180)));
ledVal = int(sinVal*255);
analogWrite(ledPin, ledVal);
delay(55.333);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment