12944qwerty

Untitled

Nov 9th, 2021
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*/
  2. /*                                                                            */
  3. /*    Module:       main.cpp                                                  */
  4. /*    Author:       C:\Users\fathe                                            */
  5. /*    Created:      Sat Oct 23 2021                                           */
  6. /*    Description:  V5 project                                                */
  7. /*                                                                            */
  8. /*----------------------------------------------------------------------------*/
  9.  
  10. // ---- START VEXCODE CONFIGURED DEVICES ----
  11. // Robot Configuration:
  12. // [Name]               [Type]        [Port(s)]
  13. // Controller          controller                    
  14. // LeftBack             motor         1              
  15. // LeftFront            motor         2              
  16. // RightBack            motor         3              
  17. // RightFront           motor         4              
  18. // RightForkLift        motor         5              
  19. // LeftForkLift         motor         6              
  20. // RingIntake           motor         7              
  21. // ---- END VEXCODE CONFIGURED DEVICES ----
  22.  
  23. #include "vex.h"
  24. #include <iostream>
  25. #include <array>
  26.  
  27. using namespace vex;
  28. using namespace std;
  29.  
  30. string statuses[4] = {"auto", "drive", "record", "game"}; // Autonomous Test, Driver Test, Autonomous Recorder, ACTUAL GAME (choose autonomous too)
  31. string status;
  32. string buttons[4] = {"(A)", "(B)", "(X)", "(Y)"};
  33. string autons[2] = {"right", "left"};
  34. string auton;
  35.  
  36. string chooseMode(string desc, array<string> modes, int default_index, double timeout = 5000) { // MAX OF 4 MODES ONLY
  37.   int length = modes.size();
  38.   Controller.lcd.clearScreen();
  39.   Controller.lcd.setCursor(0, 0);
  40.   Controller.lcd.print(desc);
  41.  
  42.   for (int i=0;i<length;i++) {
  43.     Controller.lcd.newLine();
  44.     Controller.lcd.print(buttons[i] + modes[i]);
  45.   }
  46.  
  47.   timer _timer = timer::timer();
  48.  
  49.   while (_timer.time(timeUnits::msec) < timeout) {
  50.     if (Controller.ButtonA.pressing()) return modes[0];
  51.     if (Controller.ButtonB.pressing()) return modes[1];
  52.     if (Controller.ButtonX.pressing() && modes.size() > 2) return modes[2];
  53.     if (Controller.ButtonY.pressing() && modes.size() > 3) return modes[3];
  54.   }
  55.   return modes[default_index];
  56. }
  57.  
  58. int main() {
  59.   // Initializing Robot Configuration. DO NOT REMOVE!
  60.   vexcodeInit();
  61.  
  62.   status = chooseMode("Status", statuses, 3);
  63.  
  64.   printf("Status: %d\n", status);
  65.  
  66.   if (status == "auto" || status == "game") {
  67.     auton = chooseMode("Autonomous", autons, 0, 3000);
  68.    
  69.     printf("Autonomous: %d\n", auton);
  70.   }
  71.  
  72.   return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment