pomeroyb / PortalGun

Code to control a Portal Gun (From Rick and Morty)
32 stars 19 forks source link

Flickering LED #3

Open setiupyguppie opened 7 years ago

setiupyguppie commented 7 years ago

I'd like to make the main (middle) LED flicker, to simulate the effect seen in the show. Is there a quick-and-dirty way of doing this with your existing code?

SHOW ME WHAT YOU GOT!

:)

pomeroyb commented 7 years ago

All of the LEDS are wire to pins that are able to do PWM, so you can set the output using "analogWrite()".

Right now the part of the main loop that deals with the LEDS is:

void loop() {  
  if (justWokeUp) {  
    digitalWrite(frontRightPin, HIGH);  
    digitalWrite(frontLeftPin, HIGH);  
    digitalWrite(frontCenterPin, HIGH);  
    digitalWrite(topBulbPin, HIGH);  
    justWokeUp = false;  
  }  

This basically says "if you just turned on the portal gun, set all outputs to a 5V output". If you wanted to modulate the LED, you'd modify that part of the code to set a specific PWM value from 0-255, rather than always "HIGH" (Which is just another way of writing "255".

Check this link for an easy flickering effect

And this one if you want more of a soft breathing effect.

setiupyguppie commented 7 years ago

More excellent support and guidance! Thank you! I'll keep you posted on my progress.