​ ​ ​ ​ Help with push-button to change LED flash pattern
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Help with push-button to change LED flash pattern

  1. #1
    New Member
    Join Date
    Aug 2015
    Location
    Edmonton Alberta
    Posts
    5

    Default Help with push-button to change LED flash pattern

    Hi all,

    I have learned a lot from the people here. To-day I am asking for some help with my program. Been working with it since July 2015.
    I want a push button to be detected immediately to change a LED flash sequence.

    Manual 3 says SETINT is polled between program lines. I thought that would get it done.
    As written the program will leave flash1 and proceed to flash2 but will not leave flash2.

    The program is below. An experienced eye is appreciated.

    Thank you for your help.

    David

    Code

    Code:
    '08M2 FBI style LED strobing_Jul_26_2015_1007.bas
    'Program by David Beatty @ Edmonton, Alberta
    'inspired by a Youtube video https://www.youtube.com/watch?v=tQoZCix_1mY
    'Labelled RC car flasher (FBI style) by Vicsys, http://vicsys.hu
    '
    
    #Picaxe 08M2
    #no_data
    setint %00010000,%00010000            'button on C.4'
    pinC.4 = b1                        'declare button on C.4
    b1 = 0                        'initialize b1'
    
        
    
    
        
    Interrupt:                        'used to get an imediate button response
            
            high C.0: high C.1        'turn 'em all on to show flash sequence change
            pause 1000                'time to see the button push was detected
            
            b1 = b1 + 1                'cause the program to select the next flash sequence
            
            if b1 = 1 then flash1         'array of flash sequences
            if b1 = 2 then flash2 
            if b1 = 3 then flash3 
            if b1 = 4 then flash4 
            if b1 = 5 then flash5 
            if b1 = 6 then flash6 
            if b1 = 7 then flash7 
            if b1 = 8 then flash8 
            if b1 > 8 then flash1 
            
            setint %00010000,%00010000    'resets the setint for the next button push 
            
            return    
                    
            
                                'flash sequence catalogue
                                    
                        
    flash1:
        do
            high C.0: high C.1        'all on for area illumination
            
        loop
        
    flash2:    
        do
            pulsout C.0, 255: pulsout C.1,255    'simultaneous flash of both LEDs
            pause 150
            pulsout C.0,255: pulsout C.1,255
            
        loop
    
    flash3:                            'LEDs both pulse 3X, wait 1 sec. - loop
        do
            high C.0, C.1
            pause 100
            
            low C.0, C.1
            pause 100
            
            high C.0, C.1
            pause 100
            
            low C.0, C.1
            pause 100
            
            high C.0, C.1
            pause 100
            
            low C.0, C.1
            pause 600
            
        loop
            
    flash4:                            'LED right pulses 2X then LED left pulses 2X loop
        do
            pulsout C.0, 255:pause 60: pulsout C.0,255 pause 400
            
            pulsout C.1, 255:pause 60: pulsout C.1,255 pause 400
            
        loop
            
    flash5:                            'LED right pulses 2X and remains high while LED left pulses 2X and remains high -                                 loop
        
        do
            pulsout C.0,150
            pause    80
            high C.0
            pause 30
            low C.0
            Pulsout C.1,150
            pause 80
            high C.1
            pause 30
            low C.1
            pause 30
            
        loop
    
    flash6:                            'LED right pulses 2X pausing while LED left pulses 2X and pauses, loop
        do
            pulsout C.0,255
            pause 100
            pulsout C.0,255
            pause 100
            
            pulsout C.1,255
            pause 100
            pulsout C.1,255
            pause 125
        loop
        
    flash7:                            ' wig wag pattern
        do
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
            
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
            
            pulsout C.0,255
            pause 100
            pulsout C.0,255
            pause 100
            
            pulsout C.1,255
            pause 100
            pulsout C.1,255
            pause 100
            
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
        loop
        
    flash8:                            'alternating wig wag pattern
        do
            pulsout C.0,255
            pause 100
            high C.0
            pause 170
            low C.0
            pause 600
            
            pulsout C.1,255
            pause 100
            high C.1
            pause 170
            low C.1
            pause 600
        loop
    Last edited by eclectic; 16-12-2016 at 21:42.

  2. #2
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,053

    Default

    Define what you mean by "... to be detected immediately ...."

    You probably don't need an Interrupt routine. Just keep the detection of "button on C.4" in a tight loop.
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  3. #3
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,060

    Default

    There was an almost similar question a couple of weeks ago for which I provided a solution. Don't have time to search for which thread it was at present but it's there somewhere.

  4. #4
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,053

    Default

    Perhaps this post contains the information that Hippy suggested.

    http://www.picaxeforum.co.uk/showthr...ple-Interrupts
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  5. #5
    Senior Member
    Join Date
    Feb 2009
    Location
    Cheshire, England
    Posts
    2,275
    Blog Entries
    4

    Default

    When your interrupt routine runs, work out on paper what happens. The simulator is no use here.

    The sequence you have is :

    Interrupt triggered, inc b1, goto selected flash routine, loop forever in that routine.

    You never reach the code that re-enables the interrupt.


    Solution : In the interrupt inc b1, then return. In the main loop do the if/then stuff.

  6. #6
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,060

    Default

    Quote Originally Posted by Texasclodhopper View Post
    Perhaps this post contains the information that Hippy suggested.

    http://www.picaxeforum.co.uk/showthr...ple-Interrupts
    That's the one and many thanks for tracking it down.

    But while I was away I realised there's an easier way. Simply RESET and start the program again, jump to whatever routine one now wants to run.

    Of course, the problem there is that 'everything' is zeroed or re-initialised on RESET, and one doesn't like to wear EEPROM out ( and it may be being used for something else anyway ), so how can a number indicating what to do next be preserved through RESET ... ?

    http://www.picaxeforum.co.uk/showthr...-RESET-command

  7. #7
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,053

    Default

    I forgot how slick that RESET save idea is.

    dbeatty, only one program, but switch the variable values and save them with Hippy's RESET save idea, then RESET to run your program with the new values.

    Slick!
    - Tex
    __________________________________________________ _______________________
    "Truth lies dormant in our future history." ― Tex Clodhopper LXV
    “Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.” ― Eoin Colfer, Artemis Fowl

  8. #8
    New Member
    Join Date
    Aug 2015
    Location
    Edmonton Alberta
    Posts
    5

    Default

    Thanks everyone.

    Texasclodhopper I had one variation of the program which included a goto in eacg of the flash1 to flash8 sequences. I had to hit the button at the right moment while the subroutine was running to get a response. I tried Start: routines for a parallel program to catch the button press, that didn't work. Now I tried the setinit as the pin is polled between program lines to catch the button push.
    As can be seen in the youtube video the original programmer is able to change flash sequences on demand.
    I'll read the help offered above and pitch it against what I'm after.

    Cheers

    David

  9. #9

    Default

    Hi dbeatty,
    merry Christmas and welcome to the forum.
    I didn't look at the video just modded your code abit
    I think its what your trying to do hopefully should be enough to get you rolling !
    Code:
    #Picaxe 08M2
    #no_data
    setint %00010000,%00010000 
                   
      main:      
        'Starts in OFF STATE                        'flash sequence catalogue                    
    flash1:
         if b1 = 1 then
            high C.0: high C.1        'all on for area illumination    
        goto flash1 :endif
        
    flash2:
        low C.0, C.1
        if b1 = 2 then  
            pulsout C.0, 255: pulsout C.1,255    'simultaneous flash of both LEDs
            pause 150     
        goto flash2 :endif
    
    flash3:                            'LEDs both pulse 3X, wait 1 sec. - loop
        if b1 = 3 then
            high C.0, C.1
            pause 100
            
            low C.0, C.1
            pause 100
            
            high C.0, C.1
            pause 100
            
            low C.0, C.1
            pause 100
            
            high C.0, C.1
            pause 100
            
            low C.0, C.1
            pause 600
            
        goto flash3 :endif
            
    flash4:                            'LED right pulses 2X then LED left pulses 2X loop
        if b1 = 4 then
            pulsout C.0, 255:pause 60: pulsout C.0,255 pause 400
            
            pulsout C.1, 255:pause 60: pulsout C.1,255 pause 400
            
        goto flash4 :endif
            
    flash5:                            'LED right pulses 2X and remains high while LED left pulses 2X and remains high -                                 loop
        
        if b1 = 5 then
            pulsout C.0,150
            pause    80
            high C.0
            pause 30
            low C.0
            Pulsout C.1,150
            pause 80
            high C.1
            pause 30
            low C.1
            pause 30
            
        goto flash5 :endif
    
    flash6:                            'LED right pulses 2X pausing while LED left pulses 2X and pauses, loop
        if b1 = 6 then
            pulsout C.0,255
            pause 100
            pulsout C.0,255
            pause 100
            
            pulsout C.1,255
            pause 100
            pulsout C.1,255
            pause 125
        goto flash6 :endif
        
    flash7:                            ' wig wag pattern
        if b1 = 7 then
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
            
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
            
            pulsout C.0,255
            pause 100
            pulsout C.0,255
            pause 100
            
            pulsout C.1,255
            pause 100
            pulsout C.1,255
            pause 100
            
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
            pulsout C.0,255
            pause 100
            pulsout C.1,255
            pause 100
        goto flash7 :endif
        
    flash8:                            'alternating wig wag pattern
        if b1 = 8 then
            pulsout C.0,255
            pause 100
            high C.0
            pause 170
            low C.0
            pause 600
            
            pulsout C.1,255
            pause 100
            high C.1
            pause 170
            low C.1
            pause 600
        goto flash8 :endif
    goto main
    
    Interrupt:                        'used to get an imediate button response
              do while pinc.4=1 loop
             inc b1                'cause the program to select the next flash sequence   
             setint %00010000,%00010000    'resets the setint for the next button push   
            if b1 > 8 then : b1=0 :endif    
          return
    Last edited by marks; 17-12-2016 at 08:37. Reason: edit flash2:

  10. #10
    New Member
    Join Date
    Aug 2015
    Location
    Edmonton Alberta
    Posts
    5

    Default

    Thanks so much for your time and effort. I'll give it some time.
    Merry Christmas to you and yours.

    David

Bookmarks

Posting Permissions

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