noob question, answer probably pretty easy, i just don't know where to start

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 187
Reputation: Matt Tacular is an unknown quantity at this point 
Solved Threads: 7
Matt Tacular's Avatar
Matt Tacular Matt Tacular is offline Offline
Unverified User

noob question, answer probably pretty easy, i just don't know where to start

 
0
  #1
Jun 5th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: noob question, answer probably pretty easy, i just don't know where to start

 
0
  #2
Jun 5th, 2007
Is this a console program? That kind of thing is better suited to windowed programs, but you can do it easily if you want:
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <climits>
  4. #include <windows.h>
  5.  
  6. int main()
  7. {
  8. int count = 0;
  9.  
  10. for ( ; ; ) {
  11. if ( GetAsyncKeyState ( VK_ESCAPE ) != 0 )
  12. break;
  13. else if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX ) {
  14. if ( count < 100 )
  15. ++count;
  16. }
  17. else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX ) {
  18. if ( count > 0 )
  19. --count;
  20. }
  21.  
  22. std::cout<< std::setw ( 3 ) << count <<"%\r";
  23. Sleep ( 100 );
  24. }
  25. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 6
Reputation: Opo is an unknown quantity at this point 
Solved Threads: 0
Opo Opo is offline Offline
Newbie Poster

Re: noob question, answer probably pretty easy, i just don't know where to start

 
0
  #3
Jun 6th, 2007
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <climits>
  5. #include <windows.h>
  6. using namespace std;
  7. int main()
  8. {
  9. int TPP = 0;
  10. for ( ; ; ) {
  11. if ( GetAsyncKeyState ( VK_ESCAPE ) != 0 )
  12. break;
  13. else if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX ) {
  14. if ( TPP < 100 )
  15. ++TPP;
  16. }
  17. else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX ) {
  18. if ( TPP > 0 )
  19. --TPP;
  20. }
  21. std::cout<< std::setw ( 2 ) << TPP <<"% Throttle\r";
  22. Sleep ( 100 );
  23. int RPM
  24. RPM = TPP * 74.5 + 750;
  25. HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
  26. if ( INVALID_HANDLE_VALUE != hConsole )
  27. {
  28. COORD pos = {0, 1};
  29. SetConsoleCursorPosition ( hConsole, pos );
  30. cout << RPM << " RPMs";
  31. }

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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 6
Reputation: Opo is an unknown quantity at this point 
Solved Threads: 0
Opo Opo is offline Offline
Newbie Poster

Re: noob question, answer probably pretty easy, i just don't know where to start

 
0
  #4
Jun 7th, 2007
please help guys
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC