DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   noob question, answer probably pretty easy, i just don't know where to start (http://www.daniweb.com/forums/thread80155.html)

Matt Tacular Jun 5th, 2007 11:09 am
noob question, answer probably pretty easy, i just don't know where to start
 
I need to set up 2 buttons to take input from the user, that increase and decrease a variable, it doesn't matter which 2 buttons are used, but preferably the up and down arrows. And I also need to have a display of the variable that constantly updates as it is changed by the user.

Basically what I'm doing is creating a simulated datalogging program used on a car's ECU. So the up and down arrows would be controlling my throttle position percentage. And the display would be constantly showing the percentage of throttle the user is controlling. I already have all the forumulas I need for all the other sensors I plan on showing (RPM, KPH, MAP sensor value, Air/fuel ratio etc etc.) I just need some sort of base sample of code of how to take the user's input in this style and have a constantly updating display.

Thanks guys.

Narue Jun 5th, 2007 11:35 am
Re: noob question, answer probably pretty easy, i just don't know where to start
 
Is this a console program? That kind of thing is better suited to windowed programs, but you can do it easily if you want:
#include <iostream>
#include <iomanip>
#include <climits>
#include <windows.h>

int main()
{
  int count = 0;

  for ( ; ; ) {
    if ( GetAsyncKeyState ( VK_ESCAPE ) != 0 )
      break;
    else if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX ) {
      if ( count < 100 )
        ++count;
    }
    else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX ) {
      if ( count > 0 )
        --count;
    }

    std::cout<< std::setw ( 3 ) << count <<"%\r";
    Sleep ( 100 );
  }
}

Opo Jun 6th, 2007 10:37 am
Re: noob question, answer probably pretty easy, i just don't know where to start
 
 
#include <iostream>
#include <iomanip>
#include <climits>
#include <windows.h>
using namespace std;
int main()
{
  int TPP = 0;
  for ( ; ; ) {
    if ( GetAsyncKeyState ( VK_ESCAPE ) != 0 )
      break;
    else if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX ) {
      if ( TPP < 100 )
        ++TPP;
    }
    else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX ) {
      if ( TPP > 0 )
        --TPP;
    }
    std::cout<< std::setw ( 2 ) << TPP <<"% Throttle\r";
    Sleep ( 100 );
int RPM
RPM = TPP * 74.5 + 750;
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if ( INVALID_HANDLE_VALUE != hConsole )
{
COORD pos = {0, 1};
SetConsoleCursorPosition ( hConsole, pos );
cout << RPM << " RPMs";
}

Okay that throttle stuff worked perfectly, thanks for that :) Now though I'm trying to put in my RPM gauge and I can't seem to get it working right. I have a section of code there that puts it on the second line too. I thought I would be able to figure it out myself but I'm having lots of trouble.

Opo Jun 7th, 2007 12:19 am
Re: noob question, answer probably pretty easy, i just don't know where to start
 
please help guys


All times are GMT -4. The time now is 7:59 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC