Go Down

Topic: Fading up LED PWM with fade down on button press. Delay problem (Read 810 times) previous topic - next topic


Hi guys,
getting annoyed with this now.
I want to add a debounce to the switch, but trying to use the example hasnt worked out. Can someone show me the right code to add where?

The idea of the code is to fade up a transistor that has a load of leds on it. However, I want to be able to turn if off while it is still fading up. Thats why i havnt just used for(i=0;i=256;i++); delay(30); .

So basically. Button press > Fade up ... full brightness stop... Button press > Fade down .. Button press>Fade up from where the fade down got to.

Thanks for any help.

Code: [Select]

int LEDpwmPIN = 9;    // LED connected to digital pin 9
int Switch1 = 8;
int powerup = 0;
int Switch1state = 0;
int PWMfullon = 255;
int PWMfulloff = 0;
int PWMstepping = 5;
int PWMcurrent = 0;
int delaytime = 40;

void setup()  {
 Serial.println("Arduino Connected");

void loop()  {
 delay(delaytime); //This is just to stop the up/donw LED power being too fast

void switchcheck(){

int PWMcontrollerLED(){
 if(powerup==1 && PWMcurrent != PWMfullon){
   PWMcurrent = PWMcurrent + PWMstepping;
 else if(powerup==0 && PWMcurrent != PWMfulloff){
   PWMcurrent = PWMcurrent - PWMstepping;


Code: [Select]
Where does Switch1state get set?


Missing a ( here?


Should this be 'void' instead of 'int'?
int PWMcontrollerLED(){
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131