Buttons


Closed Thread
Results 1 to 7 of 7

Thread: Buttons

  1. #1
    Join Date
    May 2008
    Location
    Texas
    Posts
    16

    Question Buttons

    I know this seems like a simple question, but I want to make sure my code is in the right ball park. The section of code should add 1 or minus 1 to a setpoint that another part of code will interpret and output to and lcd and turn on a red led or a green led

    ADCON1 = 7 ' Set PORTD and PORTE to digital

    Setpoint Var word
    Temp_Down Var PortB.3 'Temp down button input port
    Temp_Up VAR PortB.2 'Temp up button input port
    R_LED VAR PortB.0 ' Red LED output
    G_LED VAR PortB.1 ' Green LED output
    DQ VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
    Busy VAR BIT ' Busy Status-Bit
    Sign VAR BYTE ' +/- sign for temp display
    Dummy VAR BYTE ' Dummy for Div32
    R_Temp VAR WORD ' RAW Temperature readings
    TempC VAR WORD ' Temp in deg C
    TempF VAR WORD ' Temp in deg F
    Float VAR WORD ' Holds remainder for + temp C display
    Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    Real_Cold CON 1 ' Define Real_Cold = 1
    DS18B20_9bit CON %00011111 ' 93.75ms, 0.5°C
    DS18B20_10bit CON %00111111 ' 187.5ms, 0.25°C <-- My favorite
    DS18B20_11bit CON %01011111 ' 375ms, 0.125°C
    DS18B20_12bit CON %01111111 ' 750ms, 0.0625°C (default)

    OPTION_REG = $7f


    OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit] 'Skip ROM search and write 10bit resolution to scratch pad
    Pause 500
    LCDOut $FE 'Clear LCD
    Setpoint = 22

    Start_Convert:
    OWOUT DQ, 1, [$CC, $44] ' Skip ROM search & do temp conversion
    PortB = 0
    If Temp_Up = 0 Then
    Setpoint = Setpoint + 1
    Endif
    If Temp_Down = 0 Then
    Setpoint = Setpoint - 1
    Endif
    lcdout $fe, 1, "Setpoint = ", #Setpoint
    If TempC < Setpoint Then
    high R_LED ' Turn on Red LED and turn off Green LED
    low G_LED
    Else
    High G_LED ' Turn on Green LED and turn off Red LED
    low R_LED
    EndIf

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Cool

    You can run, but you can't hide.

    Equally, you can create a new thread, but I can still reply.<hr>
    OK, resolution looks good.
    Start temp conversions OK,
    And the setpoint via buttons probably work too. (But a bit bouncy)

    Only thing left is to actually read the temperature from the DS18B20.

    ruthlessly,
    DT

  3. #3
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Default aha

    One step ahead of you good sir

    I was able to read temp and actually write in a setpoint that turned on a green LED when temp was over setpoint and a red one when below.

    so maybe two steps

    You think I should use the button command to send the program to a subroutine that loops as long as the button is pushed? This way if you want to increase the temp by say ten you can just hold it down.

    Later
    Bryan

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by WarPony View Post
    You think I should use the button command to send the program to a subroutine that loops as long as the button is pushed? This way if you want to increase the temp by say ten you can just hold it down.
    Hi, Bryan

    looks pretty good that way ...

    and also works pretty good with the BUTTON command which is really ideal for such use ...

    Alain
    Last edited by Acetronics2; - 15th May 2008 at 16:07.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Thanks Alain

    I am just starting to wrap my head around this stuff

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    I knew there was an example in my projects ...

    Code:
    '*****************************************************************************
    mainloop:
    
    Writeok = 0
    
    delay = 0
    
    button Up, 		0, 255, 0, delay, 1, upbutton
    button Down, 	0, 255, 0, delay, 1, dwnbutton
    button Prog, 	0, 255, 0, delay, 1, Program
    
    Gosub Outsig
    PAUSE 18
    compte = 0
    
    Goto Mainloop
    
    
    '*****************************************************************************
    upbutton:
    
    IF Down = 0 THEN 
    
    	Pos = posn
    	Goto Jump1
    	
    Endif
    
    	Compte = compte + 1
    	
    	Select Case Compte
    	
    		Case 255
    			Compte = Compte-1
    			N = 10
    			
    		Case is > 50
    			N = 10
    				
    		Case is > 15 
    		 	N = 3
    		 	
    		Case else
    			N = 1
    			
    	End Select
    	
       	pos = pos + 2*N
       
       	if pos > 2250 then  pos = 2250
      
    Jump1:
    
    For delay = 1 to 9	
    
    	Gosub Outsig
    	Pause 18
    
    Next delay
    
    	Gosub Outsig
    
    Goto mainloop
    
    
    '*****************************************************************************
    dwnbutton:
    
    IF Up = 0 THEN 
    
    	Pos = posn
    	Goto Jump2
    	
    Endif
    
    	Compte = compte + 1
    	
    	Select Case Compte
    	
    		Case 255
    			Compte = Compte - 1
    			N = 10
    			
    		Case is > 50
    			N = 10
    			
    		Case is > 10 
    		 	N = 3
    		 			
    		Case else
    			N = 1
    			
    	End Select
    	
       	pos = pos - 2*N
       
       	if pos < 750 then pos = 750
       	 
    Jump2:
    	
    For delay = 1 to 9	
    
    	Gosub Outsig
    	Pause 18
    
    Next delay
    
    	Gosub Outsig
    
     Goto mainloop
     
    
    '*****************************************************************************
    Program:
    
    Compte = 0
    
    Test: 
    
    IF Prog = 0 Then 
    	
    	compte = compte + 1
    	Gosub Outsig
    	Pause 18
    	
    	IF Compte > 250 THEN Compte = 250: Goto Test
    	IF Compte >= 80 THEN WriteoK = Compte .4 : Goto Test
    	IF Compte >= 20 THEN WriteoK = Compte .2
    	
    	Goto Test		'Attendre relāchement bouton ...
    	
    Endif	
    	
    	IF Compte > 250 OR Compte < 20 Then mainloop
    	
    	IF Compte >= 80 Then
    	 
    		pos = 1500 
    		Goto Save	'remise au Neutre
    
    	Endif
    NB : WriteOk is the led that shows where you are ...
    Outsig is generating a servo pulse ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    ty alain

    I am going to use your example instead of pbp manual on this one. I am almost there

    Bryan

Similar Threads

  1. In Circut Debug (ICD) buttons palet is disable for 18F2620
    By muskut in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th June 2010, 05:21
  2. Button command question
    By aherrera in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 31st August 2009, 08:44
  3. 6 Buttons
    By Johansch in forum General
    Replies: 3
    Last Post: - 4th July 2007, 15:21
  4. Buttons are driving me nuts
    By Doormatt in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st May 2007, 23:09
  5. Latched buttons
    By peu in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2006, 00:22

Members who have read this thread : 1

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