My code seems to only show the buttons that I put in after I press them, before that the screen is just grey. How do I load them in beforehand?
using namespace pros;
lv_obj_t * myButton;
lv_obj_t * myButtonLabel;
lv_obj_t * myButton2;
lv_obj_t * myButtonLabel2;
lv_obj_t * myButton3;
lv_obj_t * myButtonLabel3;
lv_obj_t * myButton4;
lv_obj_t * myButtonLabel4;
lv_obj_t * myButton5;
lv_obj_t * myButtonLabel5;
lv_obj_t * myButton6;
lv_obj_t * myButtonLabel6;
lv_obj_t * myButton7;
lv_obj_t * myButtonLabel7;
lv_obj_t * myButton8;
lv_obj_t * myButtonLabel8;
lv_obj_t * myLabel;
int f;
lv_style_t RedREL; //relesed style
lv_style_t RedPR; //pressed style
lv_style_t BlueREL;
lv_style_t BluePR;
static lv_res_t btn_click_action(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn); //id usefull when there are multiple buttons
if(id == 0)
{
char buffer[100];
sprintf(buffer, "2pt Was Selected (Red)");
lv_label_set_text(myLabel, buffer);
f=0;
}
return LV_RES_OK;
}
static lv_res_t btn_click_action2(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 1)
{
char buffer[100];
sprintf(buffer, "1pt Was Selected (Red)");
lv_label_set_text(myLabel, buffer);
f=1;
}
}
static lv_res_t btn_click_action3(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 2)
{
char buffer[100];
sprintf(buffer, "5pt Was Selected (Red)");
lv_label_set_text(myLabel, buffer);
f=2;
}
}
static lv_res_t btn_click_action4(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 3)
{
char buffer[100];
sprintf(buffer, "3pt Was Selected (Red)");
lv_label_set_text(myLabel, buffer);
f=3;
}
}
static lv_res_t btn_click_action5(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 4)
{
char buffer[100];
sprintf(buffer, "2pt Was Selected (Blue)");
lv_label_set_text(myLabel, buffer);
f=4;
}
}
static lv_res_t btn_click_action6(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 5)
{
char buffer[100];
sprintf(buffer, "1pt Was Selected (Blue)");
lv_label_set_text(myLabel, buffer);
f=5;
}
}
static lv_res_t btn_click_action7(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 6)
{
char buffer[100];
sprintf(buffer, "5pt Was Selected (Blue)");
lv_label_set_text(myLabel, buffer);
f=6;
}
}
static lv_res_t btn_click_action8(lv_obj_t * btn)
{
uint8_t id = lv_obj_get_free_num(btn);
if(id == 7)
{
char buffer[100];
sprintf(buffer, "3pt Was Selected (Blue)");
lv_label_set_text(myLabel, buffer);
f=7;
}
}
void initialize()
{
lv_style_copy(&RedREL, &lv_style_plain);
RedREL.body.main_color = LV_COLOR_MAKE(150, 0, 0);
RedREL.body.grad_color = LV_COLOR_MAKE(150, 0, 0);
RedREL.body.radius = 0;
RedREL.text.color = LV_COLOR_MAKE(255, 255, 255);
lv_style_copy(&RedPR, &lv_style_plain);
RedPR.body.main_color = LV_COLOR_MAKE(255, 0, 0);
RedPR.body.grad_color = LV_COLOR_MAKE(255, 0, 0);
RedPR.body.radius = 0;
RedPR.text.color = LV_COLOR_MAKE(255, 255, 255);
lv_style_copy(&BlueREL, &lv_style_plain);
BlueREL.body.main_color = LV_COLOR_MAKE(0,0,150);
BlueREL.body.grad_color = LV_COLOR_MAKE(0,0,150);
BlueREL.body.radius = 0;
BlueREL.text.color = LV_COLOR_MAKE(255,255,255);
lv_style_copy(&BluePR, &lv_style_plain);
BluePR.body.main_color = LV_COLOR_MAKE(0,0,255);
BluePR.body.grad_color = LV_COLOR_MAKE(0,0,255);
BluePR.body.radius = 0;
BluePR.text.color = LV_COLOR_MAKE(255,255,255);
myButton = lv_btn_create(lv_scr_act(), NULL); //create button, lv_scr_act() is deafult screen object
lv_obj_set_free_num(myButton, 0); //set button is to 0
lv_btn_set_action(myButton, LV_BTN_ACTION_CLICK, btn_click_action); //set function to be called on button click
lv_btn_set_style(myButton, LV_BTN_STYLE_REL, &RedREL); //set the relesed style
lv_btn_set_style(myButton, LV_BTN_STYLE_PR, &RedPR); //set the pressed style
lv_obj_set_size(myButton, 200, 50); //set the button size
lv_obj_align(myButton, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); //set the position to top mid
myButton2 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton2, 1);
lv_btn_set_action(myButton2, LV_BTN_ACTION_CLICK, btn_click_action2);
lv_btn_set_style(myButton2, LV_BTN_STYLE_REL, &RedREL);
lv_btn_set_style(myButton2, LV_BTN_STYLE_PR, &RedPR);
lv_obj_set_size(myButton2, 200, 50);
lv_obj_align(myButton2, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 50);
myButton3 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton3, 2);
lv_btn_set_action(myButton3, LV_BTN_ACTION_CLICK, btn_click_action3);
lv_btn_set_style(myButton3, LV_BTN_STYLE_REL, &RedREL);
lv_btn_set_style(myButton3, LV_BTN_STYLE_PR, &RedPR);
lv_obj_set_size(myButton3, 200, 50);
lv_obj_align(myButton3, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 100);
myButton4 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton4, 3);
lv_btn_set_action(myButton4, LV_BTN_ACTION_CLICK, btn_click_action4);
lv_btn_set_style(myButton4, LV_BTN_STYLE_REL, &RedREL);
lv_btn_set_style(myButton4, LV_BTN_STYLE_PR, &RedPR);
lv_obj_set_size(myButton4, 200, 50);
lv_obj_align(myButton4, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 150);
myButton5 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton5, 4);
lv_btn_set_action(myButton5, LV_BTN_ACTION_CLICK, btn_click_action5);
lv_btn_set_style(myButton5, LV_BTN_STYLE_REL, &BlueREL);
lv_btn_set_style(myButton5, LV_BTN_STYLE_PR, &BluePR);
lv_obj_set_size(myButton5, 200, 50);
lv_obj_align(myButton5, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
myButton6 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton6, 5);
lv_btn_set_action(myButton6, LV_BTN_ACTION_CLICK, btn_click_action6);
lv_btn_set_style(myButton6, LV_BTN_STYLE_REL, &BlueREL);
lv_btn_set_style(myButton6, LV_BTN_STYLE_PR, &BluePR);
lv_obj_set_size(myButton6, 200, 50);
lv_obj_align(myButton6, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 50);
myButton7 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton7, 6);
lv_btn_set_action(myButton7, LV_BTN_ACTION_CLICK, btn_click_action7);
lv_btn_set_style(myButton7, LV_BTN_STYLE_REL, &BlueREL);
lv_btn_set_style(myButton7, LV_BTN_STYLE_PR, &BluePR);
lv_obj_set_size(myButton7, 200, 50);
lv_obj_align(myButton7, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 100);
myButton8 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_free_num(myButton8, 7);
lv_btn_set_action(myButton8, LV_BTN_ACTION_CLICK, btn_click_action8);
lv_btn_set_style(myButton8, LV_BTN_STYLE_REL, &BlueREL);
lv_btn_set_style(myButton8, LV_BTN_STYLE_PR, &BluePR);
lv_obj_set_size(myButton8, 200, 50);
lv_obj_align(myButton8, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 150);
myButtonLabel = lv_label_create(myButton, NULL); //create label and puts it inside of the button
lv_label_set_text(myButtonLabel, "2pt Claw"); //sets label text
myButtonLabel2 = lv_label_create(myButton2, NULL);
lv_label_set_text(myButtonLabel2, "1pt Push");
myButtonLabel3 = lv_label_create(myButton3, NULL);
lv_label_set_text(myButtonLabel3, "5pt Claw");
myButtonLabel4 = lv_label_create(myButton4, NULL);
lv_label_set_text(myButtonLabel4, "3pt Claw");
myButtonLabel5 = lv_label_create(myButton5, NULL);
lv_label_set_text(myButtonLabel5, "2pt Claw");
myButtonLabel6 = lv_label_create(myButton6, NULL);
lv_label_set_text(myButtonLabel6, "1pt Push");
myButtonLabel7 = lv_label_create(myButton7, NULL);
lv_label_set_text(myButtonLabel7, "5pt Claw");
myButtonLabel8 = lv_label_create(myButton8, NULL);
lv_label_set_text(myButtonLabel8, "3pt Claw");
myLabel = lv_label_create(lv_scr_act(), NULL); //create label and puts it on the screen
lv_label_set_text(myLabel, "Button has not been clicked yet"); //sets label text
lv_obj_align(myLabel, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); //set the position to center
}
/**
* 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.
*/
/**
* Runs initialization code. This occurs as soon as the program is started.
*
* All other competition modes are blocked by initialize; it is recommended
* to keep execution time for this mode under a few seconds.
*/
/**
* Runs while the robot is in the disabled state of Field Management System or
* the VEX Competition Switch, following either autonomous or opcontrol. When
* the robot is enabled, this task will exit.
*/
void disabled() {}
/**
* Runs after initialize(), and before autonomous when connected to the Field
* Management System or the VEX Competition Switch. This is intended for
* competition-specific initialization routines, such as an autonomous selector
* on the LCD.
*
* This task will exit when the robot is enabled and autonomous or opcontrol
* starts.
*/
/**
* Runs the user autonomous code. This function will be started in its own task
* with the default priority and stack size whenever the robot is enabled via
* the Field Management System or the VEX Competition Switch in the autonomous
* mode. Alternatively, this function may be called in initialize or opcontrol
* for non-competition testing purposes.
*
* If the robot is disabled or communications is lost, the autonomous task
* will be stopped. Re-enabling the robot will restart the task, not re-start it
* from where it left off.
*/
void autonomous() {
if(f == 0){
lv_label_set_text(myButtonLabel, "this was selected");
}
if(f == 1){
lv_label_set_text(myButtonLabel2, "this was selected");
}
if(f == 2){
lv_label_set_text(myButtonLabel3, "this was selected");
}
if(f == 3){
lv_label_set_text(myButtonLabel4, "this was selected");
}
if(f == 4){
lv_label_set_text(myButtonLabel5, "this was selected");
}
if(f == 5){
lv_label_set_text(myButtonLabel6, "this was selected");
}
if(f == 6){
lv_label_set_text(myButtonLabel7, "this was selected");
}
if(f == 7){
lv_label_set_text(myButtonLabel8, "this was selected");
}
/**
Motor front_left (1, true);
Motor back_left (2);
Motor front_right(3);
Motor back_right(4, true);
Motor left_lift(12, MOTOR_GEARSET_36);
Motor right_lift(13, MOTOR_GEARSET_36, true);
Motor claw(17);//set up mtrs/sensors
Controller master (CONTROLLER_MASTER);
claw.tare_position();
front_left.tare_position();
back_left.tare_position();
front_right.tare_position();
back_right.tare_position();
left_lift.tare_position();
right_lift.tare_position();//reset encoders
left_lift.set_brake_mode(E_MOTOR_BRAKE_HOLD);
right_lift.set_brake_mode(E_MOTOR_BRAKE_HOLD);
claw.set_brake_mode(E_MOTOR_BRAKE_HOLD);
front_left.set_brake_mode(E_MOTOR_BRAKE_HOLD);
back_left.set_brake_mode(E_MOTOR_BRAKE_HOLD);
front_right.set_brake_mode(E_MOTOR_BRAKE_HOLD);
back_right.set_brake_mode(E_MOTOR_BRAKE_HOLD);//set brake type
left_lift.move_absolute(50, 100);
right_lift.move_absolute(50, 100);
claw.move_absolute(-200,100);
left_lift.move_absolute(550,100);
right_lift.move_absolute(550,100);
front_left.move_absolute(190,100);
back_left.move_absolute(190,100);
front_right.move_absolute(190,100);
back_right.move_absolute(190,100);
front_left.tare_position();
back_left.tare_position();
front_right.tare_position();
back_right.tare_position();
left_lift.move_absolute(350,100);
right_lift.move_absolute(350,100);
claw.move_absolute(0,100);
left_lift.move_absolute(0,100);
right_lift.move_absolute(0,20);
front_left.move_absolute(20,20);
back_left.move_absolute(20,20);
front_right.move_absolute(20,20);
back_right.move_absolute(20,20);
front_left.tare_position();
back_left.tare_position();
front_right.tare_position();
back_right.tare_position();
claw.move_absolute(-200,100);
pros::delay(20);
left_lift.move_absolute(500,100);
right_lift.move_absolute(500,100);
front_left.move_absolute(70,100);
back_left.move_absolute(70,100);
front_right.move_absolute(70,100);
back_right.move_absolute(70,100);
front_left.tare_position();
back_left.tare_position();
front_right.tare_position();
back_right.tare_position();
front_left.move_absolute(70,100);
back_left.move_absolute(70,100);
front_right.move_absolute(-70,100);
back_right.move_absolute(-70,100);
front_left.tare_position();
back_left.tare_position();
front_right.tare_position();
back_right.tare_position();
front_left.move_absolute(370,100);
back_left.move_absolute(370,100);
front_right.move_absolute(370,100);
back_right.move_absolute(370,100);
front_left.tare_position();
back_left.tare_position();
front_right.tare_position();
back_right.tare_position();
*/
}
/**
* Runs the operator control code. This function will be started in its own task
* with the default priority and stack size whenever the robot is enabled via
* the Field Management System or the VEX Competition Switch in the operator
* control mode.
*
* If no competition control is connected, this function will run immediately
* following initialize().
*
* If the robot is disabled or communications is lost, the
* operator control task will be stopped. Re-enabling the robot will restart the
* task, not resume it from where it left off.
*/
void opcontrol() {
Motor front_left (1, true);
Motor back_left (2);
Motor front_right(3);
Motor back_right(4, true);
Motor left_lift(12, MOTOR_GEARSET_36);
Motor right_lift(13, MOTOR_GEARSET_36, true);
Motor claw(17);//set up mtrs/sensors
Controller master (CONTROLLER_MASTER);
left_lift.set_brake_mode(E_MOTOR_BRAKE_HOLD);
right_lift.set_brake_mode(E_MOTOR_BRAKE_HOLD);
claw.set_brake_mode(E_MOTOR_BRAKE_HOLD);
front_left.set_brake_mode(E_MOTOR_BRAKE_HOLD);
back_left.set_brake_mode(E_MOTOR_BRAKE_HOLD);
front_right.set_brake_mode(E_MOTOR_BRAKE_HOLD);
back_right.set_brake_mode(E_MOTOR_BRAKE_HOLD);//set brake type
while (true) {
front_left.move(master.get_analog(ANALOG_LEFT_Y));
back_left.move(master.get_analog(ANALOG_LEFT_Y));
back_right.move(master.get_analog(ANALOG_RIGHT_Y));
front_right.move(master.get_analog(ANALOG_RIGHT_Y));
if(master.get_digital(DIGITAL_R1)){
left_lift.move_velocity(100);
right_lift.move_velocity(100);
front_left.move(master.get_analog(ANALOG_LEFT_Y));
back_left.move(master.get_analog(ANALOG_LEFT_Y));
back_right.move(master.get_analog(ANALOG_RIGHT_Y));
front_right.move(master.get_analog(ANALOG_RIGHT_Y));
}else if(master.get_digital(DIGITAL_R2)){
left_lift.move_velocity(-100);
right_lift.move_velocity(-100);
front_left.move(master.get_analog(ANALOG_LEFT_Y));
back_left.move(master.get_analog(ANALOG_LEFT_Y));
back_right.move(master.get_analog(ANALOG_RIGHT_Y));
front_right.move(master.get_analog(ANALOG_RIGHT_Y));
}else if(master.get_digital(DIGITAL_L1)){
claw.move_absolute(1000, 200);
front_left.move(master.get_analog(ANALOG_LEFT_Y));
back_left.move(master.get_analog(ANALOG_LEFT_Y));
back_right.move(master.get_analog(ANALOG_RIGHT_Y));
front_right.move(master.get_analog(ANALOG_RIGHT_Y));
}else if(master.get_digital(DIGITAL_L2)){
claw.move_velocity(-200);
front_left.move(master.get_analog(ANALOG_LEFT_Y));
back_left.move(master.get_analog(ANALOG_LEFT_Y));
back_right.move(master.get_analog(ANALOG_RIGHT_Y));
front_right.move(master.get_analog(ANALOG_RIGHT_Y));
}else{
left_lift.move_velocity(0);
right_lift.move_velocity(0);
claw.move_velocity(0);
}
pros::delay(2);
}
}