Skip to content

Commit

Permalink
update example code in main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ion098 committed Jun 5, 2024
1 parent 7d22c8b commit 2b4d5ab
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2b4d5ab

Please sign in to comment.