toggle command w/ multiple switches


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96

    Default toggle command w/ multiple switches

    Hello,
    I want to use the toggle command to efficiently jump from LCD screen to LCD screen using just 2 push button switches. I have heard that using the toggle command is the best way to do this. Can anyone provide a sample code for doing this. Here is a small portion of my code....
    thanks,





    main:
    Pause 100
    While PORTB.6 = 0
    LCDOut 254,1
    LCDOut 254,130, "Is your favorite"
    LCDOut 254,196, "color green?"
    LCDOut 254,216, "Yes No"
    Pause 50

    IF switch1 = 0 Then YES 'yes selected
    IF switch2 = 0 Then NO 'no selected
    GoTo main

    YES:
    Pause 100'wait for enought time to remove finger
    While PORTB.6 = 0 'always true
    Low PORTB.4
    LCDOut 254,1
    LCDOut 254,128,"U must B a GRN thumb"
    LCDOut 254,192,"Here is YOUR color!"
    LCDOut 254,152,"Keep Going?"
    LCDOut 254,216,"Yes No"
    High PORTB.4
    Pause 50
    IF switch1 = 0 Then KeepGoing 'yes selected
    IF switch2 = 0 Then Finished 'no selected
    GoTo YES

    Wend
    GoTo intro'this condition will never be met

    KeepGoing:
    Pause 100'wait for enought time to remove finger
    Low PORTB.4
    While PORTB.6 = 0 'always true
    Low PORTB.4
    LCDOut 254,1
    LCDOut 254,129,"Thanks for playing"
    'LCDOut 254,195,"my game show!"
    LCDOut 254,148,"Try it from the top?"
    LCDOut 254,216,"Yes No"
    Pause 50

    IF switch1 = 0 Then YES3 'yes selected
    IF switch2 = 0 Then NO3 'no selected
    GoTo KeepGoing

    Wend
    GoTo intro'this condition will never be met

    YES3:
    GoTo intro
    NO3:
    Pause 50
    LCDOut 254,1
    LCDOut 254,134,"The End"
    GoTo NO3
    Padawan-78

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by earltyso View Post
    Hello,
    I want to use the toggle command to efficiently jump from LCD screen to LCD screen using just 2 push button switches. I have heard that using the toggle command is the best way to do this. thanks,
    What does your PBP manual say about the 'TOGGLE' command?

  3. #3
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Talking

    not enough...else why would I ask?!
    Padawan-78

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by earltyso View Post
    not enough...else why would I ask?!
    Because 'TOGGLE' doesn't really have anything to do with switches or inputs, except to make inputs into outputs and 'TOGGLE' the state of that output.

    You set up a couple of routines, one for each display, add in a flag variable.
    In the main loop, you check your switches. If the correct switch is pushed, the loop jumps to one of the routines (according to the 'flag' setting) to display AND sets the 'flag' to X, then jumps back to the main loop.
    If another switch is pushed, the loop jumps to another one of the routines (again, according to the 'flag' setting) to display AND sets the 'flag' to Y, and again, jumps back to the main loop to await another switch push.

    Your program looks like it should work just fine, it's just a bit jumbled around and, as you pointed out, isn't quite as efficient as it could be. Then again, if it works, who cares

  5. #5
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Smile flag bits

    Thanks for the help, could you please tell me more about setting up flags in PBP? I remember doing this back in my microprocessor machine code (many years ago) class but did not know this could be done in PBP.
    Padawan-78

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    A flag is just a bit that you set or reset at one (ore more) point in the program and then read at another point. Sort of a one bit memory if you will.
    Code:
    myFlag VAR BIT		'This is a single bit flag.
    
    Flags VAR BYTE		'Variable containig 8 bits ("flags").
    
    Flag0 VAR Flags.0	'This points to the first bit in Flags
    Flag1 VAR Flags.1	'This points to the second bit in Flags
    DisplayON VAR Flags.2  'Another flag in the 'flag-byte'
    
    ' //And so on....
    
    Main:
    
    If Flag0 = 1 then	'Is Flag0 set?
    	High Portb.0	'If so set PortB.0 High
    Else
    	Low PortB.0	'If not, set it low
    Endif
    
    
    If PortA.0 = 1 AND PORTA.1 = 0 then
    	Flag1 = 1	'If so
    Else 
    	Flag1 = 0
    Endif
    
    ' //And so on...
    /Henrik Olsson.

  7. #7
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Smile toggle with flags

    thanks for the help!
    Padawan-78

Similar Threads

  1. Toggle command
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2011, 02:07
  2. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  3. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  4. TOGGLE code space and ICD
    By duncan303 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th October 2006, 16:08
  5. Two switches per pin!!!
    By picnaut in forum General
    Replies: 4
    Last Post: - 18th June 2004, 19:02

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