switches & LEDs ... my first attempt


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    yankee's Avatar
    yankee Guest


    Did you find this post helpful? Yes | No

    Default

    I just love it when someone quotes Clint!

    Well, it looks like it's going to be a rough transition to digital after 25 years of analog. I tried your code Melanie, but I couldn't get it to work either LED. I must have gone wrong somewhere. I'll have to double & triple check things on my end.

    picnaut is talking WAY above my head, but I'm going to try and figure that one out too, eventually. I can understand all zeros for "off" all of the time and all ones for "on" all of the time, but the rest of it baffles me, so far.

    What I need is a picbasic pro for idiots book. Does anything like that exist?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I posted the code as an example without testing... hmmm.... I'll go check...

  3. #3


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by yankee
    picnaut is talking WAY above my head, but I'm going to try and figure that one out too
    Sorry about that.

    I'm not at a computer that has Pic Basic Pro installed on it.
    Also, I haven't programmed using PBP for a while, so I didn't want to type a bunch of code with a bunch of syntax errors.
    That would just confuse you more.
    That's why I tried to keep it to mostly theory.

    Maybe I can take a look at it tonight and whip something up.
    It's a lot easier than my description sounds at first.

    How much do you know about binary and hexadecimal number systems?
    It would help to know what your background is so that I know where to start.

    Anyway, you're going to love programming PICs with basic.
    It's a great way to start.
    Especially, if you've been working with strictly analogue for a quarter century.



    Cheers.
    ---> picnaut

  4. #4
    yankee's Avatar
    yankee Guest


    Did you find this post helpful? Yes | No

    Default

    Oh my, don't be sorry, I do appreciate the help!

    My background is electronics, 100% analog. I remember learning about binary & hex back in school ... nineteen seventy something *grin* and that's about the only place that I've ever used it. I do understand it, but relating it to electronics has me scratching my head. Old Dog New Trick Syndrome?

    Now, if we need to take a single D cell battery and light up 3 white LEDs in series, I'm your man! I'd just as well like to leave that world behind though and learn digital. It's making my life easier, even though I've just begun.

  5. #5


    Did you find this post helpful? Yes | No

    Thumbs up LED Flash Pattern Simulation

    Hi,

    OK. I've attached a program (in a ZIP file) that illustrates the LED flashing method that I described earlier.
    It doesn't generate any PBP code, but it will give you a better idea of what is going on so that you can do it for yourself.

    The 16 checkboxes at the bottom of the program represent the 16 bits (0 to 15) of the flash pattern word.
    Checking or unchecking these boxes will change the "Flash Pattern Word Value" at the top.

    NOTE:
    I'm only displaying the "Flash Pattern Word Value" in binary format.


    The little blue circle below the check boxes and the number in the "Current Pattern Bit Selected" text box indicate at what point in the flash pattern the LED (the big red box) is getting it's status from. Checked = ON, Unchecked = OFF.

    Now, neither of the top 2 text boxes accept data input. They are simply indicators. However, the bottom 2 text boxes do accept input. These are the "Loop Delay (PAUSE)" text box and the "LED Update Count" text box. Any changes in these boxes will turn the box yellow. You will need to click the "Update Values" button to enter the changes you make here.

    The "Loop Delay (PAUSE)" text box indicates the delay in milliseconds between each launch (i.e. a GOSUB) of the LED's status update routine. In PBP code, look at it as the delay between loops through "Main".

    The "LED Update Count" is sort of a countdown between updates of the LED's status. It gets decremented each time the LED's status update routine is launched, and when it hit's zero the LED's flash pattern bit gets advanced by one.

    The reason that I use a delay and a count is because a program is often doing several things. You may only want a 10ms delay between loops to handle debounce on switches. 10 milliseconds is way too short for 16 part LED flash though. You need a longer interval like 100ms. So, you end up using a count of ten with a loop delay of 10 milliseconds. Every ten milliseconds the switches are checked and the LED status update routine is launched. Within that routine the count gets decremented. If it's reached zero, the LED pattern bit is advanced and the count is reset to 10.

    NOTE:
    Due to some "VB issues", you can't make the loop delay value less than 100 milliseconds in the simulation. You can make it as small as you want on an actual PIC though.

    Anyway, it will make much more sense to you when you run the program. Try it out by checking and unchecking the boxes. For example, checking the first 8 boxes and unchecking the last 8 boxes will produced a slow flashing pattern.

    Enjoy!
    Attached Files Attached Files
    ---> picnaut

  6. #6
    yankee's Avatar
    yankee Guest


    Did you find this post helpful? Yes | No

    Default

    Hey, that's a neat lil' demo. Thanks! Now it does make sense. Lets see if I can get something working now.

    I'm also still interested in seeing what Melanie comes up with. I keep trying different things with no luck.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Silly mistake in the code (which everyone should have spotted!)...

    Change the two lines (one in each LED control block)...

    If LedACounter>1 then...

    and

    If LedBCounter>1 then...

    to both be >0 and not >1

    Runs like a trooper...

    (I have edited my posted code to reflect the corrections, just copy and run)

  8. #8
    yankee's Avatar
    yankee Guest


    Did you find this post helpful? Yes | No

    Smile Sorry for the long overdue reply ...

    ... I've been out of commission since August and just wanted to say thanks! Now that I'm back in the game, I'll try this out.

    ~ Dave

Similar Threads

  1. Run a string of LEDs from the mains
    By The Master in forum Off Topic
    Replies: 30
    Last Post: - 1st October 2009, 18:55
  2. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  3. arrays LEDs Switches
    By ilteris in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd October 2005, 03:05
  4. controlling leds with the switches
    By ilteris in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th October 2005, 21:02
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts