LED's ramping up and down by turning on and off a dip switch
I am trying to simulate a car door opening and the dome light going softly up and then closing the door and dome light going softly down to off. I am using a dip switch and an LED; I am using a pull up circuit. My input pin is 4, my switch is 4, and my output is 12. the other switches are used for my other lights (they do not need ramping only on / off and I have that so far). I don't know if it is in the program or my circuitry. If anyone has any ideas or knows how please help. This is due tomorrow (Friday by 12:00 p.m.) Thanks
Comments
You need anything else let me know. I appreciate your help.
About the program, what does it actually do when you close the switch? I don't see any provisions for when the switch is opened or while the switch remains closed. Your description of how the switch should behave includes 4 states: 1) the switch is open; 2) the switch goes from open to closed; 3) the switch is closed; 4) the switch goes from closed to open. Your program only reacts to #3.
The program you posted only tests for the switch on pin 4 to be closed. It has no way to tell if the switch has just been closed or remains closed. When the switch tests closed, the program gradually increases the on time of the LED, then gradually decreases the on time of the LED, then goes back to testing the various other switches including the one on pin 4.
At the very least, you need to remember the most recent setting of the switch (on or off) using a BIT variable and compare that to the current setting. If they're equal, you can ignore them and continue in your main loop. If the switch was off and now is on, you would slowly turn on the LED the way you're doing it now. If the switch was on and now is off, you would slowly turn off the LED. In both cases, you would set the variable to the new state of the switch (on or off).
This method still "blocks" any actions controlled by any switches until the dome light turn on or turn off is finished. If you have to slowly turn on or off the dome light while still reacting to the switches, then you'd have to revise your program more than you have time for (and more than I have time to lead you through).