button help


Closed Thread
Results 1 to 16 of 16

Thread: button help

  1. #1
    Join Date
    Oct 2008
    Posts
    47

    Question button help

    How do i write code to create a means of storing a setpoint that can be incremented or decremented using buttons?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    First setup some variables
    Code:
    cnt     var byte 
    TSET   var byte
    TS      var byte
    TLOG   var byte
    Then the button VARs
    Code:
    TUP        var PORTD.0
    TDOWN   var PORTC.3
    This reads the eeprom at start up
    Code:
    read  TLOG, TSET 
    TS = TSET
    Then the code
    Code:
    START:
    if TUP = 1 then gosub T_UP
    if TDOWN = 1 then gosub T_DOWN
    GOTO START
    
    T_UP:
        for cnt = 1 to 1
        TS = TS + 1
        write TLOG, TS
        read  TLOG, TSET
        pause 100
        next
        return
        
    T_DOWN:
        for cnt = 1 to 1
        TS = TS - 1
        write TLOG, TS
        read  TLOG, TSET
        pause 100
        next
        return
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Smile

    ok that seems kewl. bt what if i had a high setpoint and a low setpoint and i wanted to use another two buttons, one to access the high setpoint then once the user has entered a value, the user could press the same button to exit and return to the main screen? the same goes for the other button.. im really pulling my hair off with trying to figure this out
    Last edited by Kalind; - 8th October 2008 at 14:09.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    ok that seems kewl. bt what if i had a high setpoint and a low setpoint and i wanted to use another two buttons, one to access the high setpoint then once the user has entered a value, the user could press the same button to exit and return to the main screen? the same goes for the other button.. im really pulling my hair off with trying to figure this out
    <h2> SO WHY SHOULD YOU BE THE ONLY ONE, WITH HAIR ?</h2>
    Before you pluck out those last strands . . . Search for Clock examples by Melanie, she details how to use 1 button to do several things . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hey Joe,
    Have you tried miracle grow?

    Kalind,
    This might be the thread Joe is referring to.
    http://www.picbasic.co.uk/forum/showthread.php?t=3600

    If you use it. Read the value of Time and goto where ever from there.
    Code:
    IF Time = 3 THEN ???
    IF Time = 9 THEN ?!?!
    When that bit of code is ran, set Time back to 0 for the next run.

    Oh, and if you have more questions, add a post to the thread, that way people that are working with you get an update in their e-mail. No e-mails for editing. I did not see you added more to the post until Joe replied.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Hey Joe,
    Have you tried miracle grow?

    Kalind,
    This might be the thread Joe is referring to.
    http://www.picbasic.co.uk/forum/showthread.php?t=3600
    NOPE ! I was referring to Melanie's Olympic timer. I had hoped Kalind would get busy and search for it. Ambition feeds the helpers. Anyway here is the link to her PDF file . . .http://www.picbasic.co.uk/forum/atta...4&d=1091819883
    Look at how She used buttons to do different functions.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Ambition feeds the helpers.
    Agreed.
    I was just trying to give the OP a boost. Get'em through that first project before they become completely lost.

    Oh well, we will have to see where it goes from here
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Agreed.
    I was just trying to give the OP a boost. Get'em through that first project before they become completely lost.

    Oh well, we will have to see where it goes from here
    So why does that <b>first</b> project have to be so complicated ?
    Nobody fell out of the womb and landed on their feet in a dead run, human beings do not learn that way, we learn in chunks, and fail until we get the gestalt of that chunk, that becomes the cornerstone and we bite off another chunk, It's why some people here constantly ask about blinkys, cause if you cannot do that . . . you're basically screwed. You build a house, 1st Foundation, 2 stemwall, 3 Floor joists,subfloor, Walls, Rafters . . . If you build the roof first, then someone is going to have to help you put it on. In this instance, he would do well to set aside the keypad routine untill he can do with buttons what he wants, make the device work first, then think about how to JAZZ IT UP. Yes you can make a suit out of patches, but would anyone wear it to an interview?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Joe S. View Post
    Yes you can make a suit out of patches, but would anyone wear it to an interview?
    I would!

  10. #10
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Red face

    gee, that example is confusing. all i want to use is 5 buttons on port c of my 16f873.

    button A = High Setpoint
    buttonB = Low Setpoint
    buttonC= Increment
    buttonD= Decrement
    buttonE= Return to main display

    At power up of my device, I want my program to prompt the user to enter a high and low setpoint then continue to display the main program afterwards. If the user decides to change setpoint, then the buttons above can be used.

  11. #11
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    gee, that example is confusing. all i want to use is 5 buttons on port c of my 16f873.

    button A = High Setpoint
    buttonB = Low Setpoint
    buttonC= Increment
    buttonD= Decrement
    buttonE= Return to main display

    At power up of my device, I want my program to prompt the user to enter a high and low setpoint then continue to display the main program afterwards. If the user decides to change setpoint, then the buttons above can be used.
    Yes, it can be so why bother with all that keypad code then?
    Code:
    'simple if then loop
    BUTTONA VAR PORTC.0
    BUTTONB VAR PORTC.1
    BUTTONC VAR PORTC.2 ' and so on . . . 
    MAIN:
    IF BUTTONA = 0 THEN gosub High_Setpoint
    IF BUTTONB = 0 THEN GOSUB Low_Setpoint
    IF BUTTONC = 0 THEN GOSUB Increment
    ' More code goes in here
    
    GOTO MAIN
    high_setpoint:
    'do something in here
    return
    Low_Setpoint:
    'do something in here
    return
    Increment:
    'do something in here
    return
    
    'more sub directories here
    
    
    end
    To address your original question, you may wish to store the value in the eeprom of your chip. Use WRITE command to store and READ to retrieve the values.
    Last edited by Archangel; - 9th October 2008 at 10:08.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  12. #12
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Exclamation

    think it will be easier to use 5 buttons instead of using a matrix keypad. How would I prompt the user to enter high and low setpoints immediately once the device is powered? With that, how would i configure a button to act as an "enter" button? The reason i ask this is because i want the program to ask the user to enter high setpoint then the user should press enter. The program should then ask the user to enter a low setpoint and pressing enter again will cause the program the jump to the main temperature display.
    Last edited by Kalind; - 13th October 2008 at 12:46.

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    How would I.....
    With that, how would i.....
    i want...................
    then ask......
    Write some code...write some code...write some code. You have the PBP manual, you have internet access, you can search for methods on how to use BASIC, you can do almost anything, so, write some code. When that code that YOU write doesn't work, I'm sure a load of people here will help you troubleshoot that code to figure out why it doesn't work the way you want it to work. If you can't write the code, at least write out what you want to do on paper. Use a 'flowchart' type of setup. Just write it out. 'cause quite frankly, good luck finding somebody to write the code for you...

  14. #14
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Angry

    skimask, you not obliged to reply. Keep your brilliance to yourself dude. You suck!

  15. #15
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    You suck!
    That may be true. Some may even believe it. Here's the filename to my latest program:

    What's the filename of your latest program?

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Kalind,
    Joe and I gave you some code to get started. Have you done anything with it?

    In the mean time http://www.picbasic.co.uk/forum/show...6&postcount=13 then get back to us.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06
  5. Button subfunction 16F628
    By Jųan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2005, 16:44

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