From 2b4d5ab2e2714caf2e0a97b144d90357b19975f1 Mon Sep 17 00:00:00 2001 From: ion098 <146852218+ion098@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:05:59 -0700 Subject: [PATCH] update example code in main.cpp --- src/main.cpp | 62 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1cc258a..6836c8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,8 @@ #include "main.h" +#include "Gamepad/api.hpp" +#include "pros/screen.hpp" -/** - * A callback function for LLEMU's center button. - * - * When this callback is fired, it will toggle line 2 of the LCD text between - * "I was pressed!" and nothing. - */ -void on_center_button() { - static bool pressed = false; - pressed = !pressed; - if (pressed) { - pros::lcd::set_text(2, "I was pressed!"); - } else { - pros::lcd::clear_line(2); - } -} +Gamepad::Controller master(CONTROLLER_MASTER); /** * Runs initialization code. This occurs as soon as the program is started. @@ -23,10 +11,6 @@ void on_center_button() { * to keep execution time for this mode under a few seconds. */ void initialize() { - pros::lcd::initialize(); - pros::lcd::set_text(1, "Hello PROS User!"); - - pros::lcd::register_btn1_cb(on_center_button); } /** @@ -74,21 +58,31 @@ void autonomous() {} * task, not resume it from where it left off. */ void opcontrol() { - pros::Controller master(pros::E_CONTROLLER_MASTER); - pros::MotorGroup left_mg({1, -2, 3}); // Creates a motor group with forwards ports 1 & 3 and reversed port 2 - pros::MotorGroup right_mg({-4, 5, -6}); // Creates a motor group with forwards port 4 and reversed ports 4 & 6 - + master.Down.onPress([](){ + printf("Down Press!\n"); + }); + master.Down.onLongPress([](){ + printf("Down longPress!\n"); + }); + master.Down.onRelease([](){ + printf("Down Release!\n"); + }); + master.Up.onPress([](){ + printf("Up Press!\n"); + }); + master.Up.onLongPress([](){ + printf("Up longPress!\n"); + }); + auto i = master.Up.onRelease([](){ + printf("Up Release!\n"); + }); + master.Up.onRelease([=](){ + // master.Up.removeListener(i); + printf("Up Release 2!\n"); + }); while (true) { - pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2, - (pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1, - - (pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0); // Prints status of the emulated screen LCDs - - // Arcade control scheme - int dir = master.get_analog(ANALOG_LEFT_Y); // Gets amount forward/backward from left joystick - int turn = master.get_analog(ANALOG_RIGHT_X); // Gets the turn left/right from right joystick - left_mg.move(dir - turn); // Sets left motor voltage - right_mg.move(dir + turn); // Sets right motor voltage - pros::delay(20); // Run for 20 ms then update + master.update(); + pros::screen::print(TEXT_MEDIUM, 3, "%f %f %f %f", master.LeftX, master.LeftY, master.RightX, master.RightY); + pros::delay(20); } } \ No newline at end of file