944,093 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1277
  • C++ RSS
Jun 5th, 2007
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 7
Unverified User
Matt Tacular is offline Offline
187 posts
since Jun 2006
Jun 5th, 2007
0

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:
C++ Syntax (Toggle Plain Text)
  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. }
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jun 6th, 2007
0

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

C++ Syntax (Toggle Plain Text)
  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.
Opo
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Opo is offline Offline
6 posts
since Jun 2007
Jun 7th, 2007
0

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

please help guys
Opo
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Opo is offline Offline
6 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: loop that creates strings?
Next Thread in C++ Forum Timeline: Where to get C++ GUI prgramming tutorials?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC