View unanswered posts | View active topics It is currently Sat Aug 30, 2014 4:31 pm






Reply to topic  [ 2 posts ] 
LCD Buttons 
Author Message
Rookie

Joined: Thu Jul 08, 2010 3:50 pm
Posts: 18
Post LCD Buttons
I need some help with using the buttons on the LCD. I'm trying to switch between values inputted to the LCD. Any samples? The samples in RobotC don't go into button use and there's no help topic.


Sat Jul 10, 2010 8:16 am
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: LCD Buttons
Hi.

It's very simple, each button has a set value, and you can check the sum to see which are being pushed. 2 states (0 or 1) for 3 buttons = 2^3 = 8 possible combinations.

The LCD Buttons have values in powers of 2.
kLeftButton returns 1 (2^0)
kCenterButton returns 2 (2^1)
kRightButton returns 4 (2^2)

nLCDButtons returns the sum of the buttons when called. So it has these possible values 0 (none pushed) through 7 (all pushed).

here is a quick example, you can do more complex stuff with bit shifts and stuff, but this should show you the basic commands and how to use them. Download and run the code, and push the buttons and try to get the values 0 through 7 to show up. I hope it helps.


Code:
#pragma config(UART_Usage, UART2, VEX_2x16_LCD)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


/**************************/
/* Possible combinations: */
/*                        */
/* Binary   Decimal   Btn */
/**************************/
/* 000        0       --- */
/* 001        1       L-- */
/* 010        2       -C- */
/* 011        3       LC- */
/* 100        4       --R */
/* 101        5       L-R */
/* 110        6       -CR */
/* 111        7       LCR */
/**************************/

task main()

  while(true)
  {
    // Clear LCD Lines
    clearLCDLine(0);
    clearLCDLine(1);
   
    // Top LCD Line Display Stuff:
    displayLCDPos(0,0);
    displayNextLCDString("nLCDButtons = ");
    displayNextLCDNumber(nLCDButtons);      // 'nLCDButtons' is the SUM of the LCD button values.     
   
    // Bottom LCD Line Display Stuff:
    displayLCDPos(1,0);
    displayNextLCDChar('L');
    displayLCDPos(1,2);
    displayNextLCDNumber(kLeftButton);      // 'kLeftButton' is worth decimal 1, binary 00000001, or 2^0.
   
    displayLCDPos(1,6);
    displayNextLCDChar('C');
    displayLCDPos(1,8);
    displayNextLCDNumber(kCenterButton);    // 'kCenterButton' is worth decimal 2, binary 00000010, or 2^1.
   
    displayLCDPos(1,13);
    displayNextLCDChar('R');
    displayLCDPos(1,15);
    displayNextLCDNumber(kRightButton);     // 'kRightButton' is worth decimal 4, binary 00000100, or 2^2.
   
   
    // Wait a little to keep the screen refreshing smoothly:
    wait1Msec(250);
  }
}


Attachments:
testLCDbuttons.c [1.59 KiB]
Downloaded 202 times

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学
Tue Jul 13, 2010 4:48 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.