Push Button 'Menu' to Choose Variable.


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    I believe it wasn't working properly due to the Interrupt settings which i have now disabled on PortB.0.

    I have it working the way i want apart from one thing.

    It recognises the push switch, displays the appropriate PWM and then if it reaches 9 goes to 1 again. Also, if no input for 5 seconds it starts the flashing sequence (just to signal the end of the 5 seconds).

    How does one get the LEDs to stay in their PWM routine until the switch is pressed again, without using Interrupts. When the swicth is pushed it goes to the appropriate PWM routine but after the PWM cycle, the LED goes off.

    Here is the code.

    Code:
    MyNumber    VAR Byte	' Variable 1-9
    MyTimeOut   VAR Byte	' 5 second Timeout (100 loops of 50mS)
    
    Red         VAR PORTB.1 ' All LEDs
    Green       VAR PORTB.2 ' Connected between
    Blue        VAR PORTB.3 ' RC pins and ground
    Orange      VAR PORTB.4
    
    DISABLE INTERRUPT
    MyButton    VAR PORTB.0 	' Pin goes LOW when Button pressed
    
    MyNumber=1		' Power-On with this starting value
    MyTimeOut=0		' TimeOut starts from zero at Power-Up	
    
    	While MyTimeOut<100
            If MyButton=0 then
    			gosub mynumberpwm
                MyNumber=MyNumber+1
    			If MyNumber>9 then MyNumber=1
                MyTimeOut=0
    			Pause 50	
    				' This Pause DEBOUNCES Button - do not remove it
    			While MyButton=0:Wend
    				' Wait here if Button held down
    			else
    			MyTimeOut=MyTimeOut+1
    			Pause 50
    				' This Pause is the Timeout Pause
    			endif
    		Wend
    
    main:
        high Orange
        pause 500
        low Orange
        pause 500
    goto main
    
    MynumberPWM:
        If Mynumber = 1 then PWM Red,1,255
        If Mynumber = 2 then PWM Red,25,255
        If Mynumber = 3 then PWM Red,255,255
        If Mynumber = 4 then PWM green,1,255
        If Mynumber = 5 then PWM green,25,255
        If Mynumber = 6 then PWM green,255,255
        If Mynumber = 7 then PWM BLUE,1,255
        If Mynumber = 8 then PWM BLUE,25,255
        If Mynumber = 9 then PWM BLUE,255,255
    Return
    Many thanks,

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    How does one get the LEDs to stay in their PWM routine until the switch is pressed again, without using Interrupts? When the swicth is pushed it goes to the appropriate PWM routine but after the PWM cycle, the LED goes off"

    Unless you are able to write a program with an "active real-time" loop that executes continuous PWM (I do recall posting an example of such code dimming multiple LED's continuously sometime ago), the only option you have is chosing a PIC with multiple hardware PWM.

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  3. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06

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