Last active
January 25, 2026 13:49
-
-
Save songkeys/71fd0d46d5d0e2e1b3606f7af5273836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "vex.h" | |
| using namespace vex; | |
| // ----- Tuning values (edit these!) ----- | |
| const int MAX_HITS = 10; | |
| const int DRIVE_SPEED = 55; // % | |
| const int TURN_SPEED = 40; // % | |
| const int BACKUP_MM = 180; // mm | |
| const int TURN_DEG = 90; // degrees | |
| int hits = 0; | |
| bool turnRightNext = true; | |
| void showHUD() { | |
| Brain.Screen.clearScreen(); | |
| Brain.Screen.printAt(10, 30, "Pinball Bot"); | |
| Brain.Screen.printAt(10, 60, "Hits: %d / %d", hits, MAX_HITS); | |
| } | |
| void bounce() { | |
| Drivetrain.stop(); | |
| Drivetrain.driveFor(reverse, BACKUP_MM, mm); | |
| if (turnRightNext) { | |
| Drivetrain.turnFor(right, TURN_DEG, degrees); | |
| } else { | |
| Drivetrain.turnFor(left, TURN_DEG, degrees); | |
| } | |
| turnRightNext = !turnRightNext; | |
| Drivetrain.drive(forward); | |
| } | |
| void celebration() { | |
| Drivetrain.stop(); | |
| Brain.Screen.clearScreen(); | |
| Brain.Screen.printAt(10, 60, "JACKPOT! %d hits!", hits); | |
| // Fun but still safe in a classroom: | |
| Drivetrain.turnFor(right, 360, degrees); | |
| Drivetrain.stop(); | |
| } | |
| int main() { | |
| vexcodeInit(); | |
| Drivetrain.setDriveVelocity(DRIVE_SPEED, percent); | |
| Drivetrain.setTurnVelocity(TURN_SPEED, percent); | |
| Drivetrain.drive(forward); | |
| while (true) { | |
| showHUD(); | |
| if (hits >= MAX_HITS) { | |
| celebration(); | |
| while (true) { wait(100, msec); } // end program safely | |
| } | |
| // IMPORTANT: read .PRESSED ONCE per loop | |
| // (mevents are "one-shot" style) | |
| if (BumperSwitch.PRESSED) { | |
| hits++; | |
| bounce(); | |
| } | |
| wait(20, msec); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment