Shop OBEX P1 Docs P2 Docs Learn Events
LED's ramping up and down by turning on and off a dip switch — Parallax Forums

LED's ramping up and down by turning on and off a dip switch

MerMeltMerMelt Posts: 4
edited 2009-12-04 12:20 in Learn with BlocklyProp
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

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-04 04:55
    You will need to supply more information about your hardware and you will need to supply your source program as an attachment to a message (not cut and pasted into a message). The "Post Reply" button will bring up a message entry page that includes a button for the Attachment Manager which you can use to attach files to your message. You will need to describe how you have things connected to your input pin including the value of the pullup. A schematic would be helpful.
  • MerMeltMerMelt Posts: 4
    edited 2009-12-04 05:25
    I have attached the schematics (they are multisim files and I have attached the program written in PBasic2).
    You need anything else let me know. I appreciate your help.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-04 06:28
    Thanks for attaching the files, but I do not have a copy of MultiSim nor am I interested in installing a copy. I suggest you print your schematic to a PDF file if possible and attach that. If not, at least give a complete description of what you have attached to pins 4 and 12.

    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.
  • MerMeltMerMelt Posts: 4
    edited 2009-12-04 06:52
    Okay, please find attached the pdf of the circuits. When the switch is closed power goes to ground and when the switch is open power goes to the led gradually ramping up then when the switch is closed again the led gradually ramps down. I wish at this point. I have been working on and off on this for about two weeks. I've tried so many ways until I think I am just repeating my ideas and they still don't work. Again, thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-04 07:31
    I got the PDF files and they look like I expected. The switch causes IN4 to be 0 when closed and 1 when open. The LED goes on when pin 12 is high and off when pin 12 is low.

    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).
  • MerMeltMerMelt Posts: 4
    edited 2009-12-04 12:20
    Thank you for your help
Sign In or Register to comment.