diff --git a/include/EZ-Template/pre_auto_selector.hpp b/include/EZ-Template/pre_auto_selector.hpp index f55e017d..8ff1a65b 100644 --- a/include/EZ-Template/pre_auto_selector.hpp +++ b/include/EZ-Template/pre_auto_selector.hpp @@ -1,10 +1,10 @@ #pragma once #include "main.h" - +#include namespace ez { -extern pros::ADIDigitalIn* left_limit_switch; -extern pros::ADIDigitalIn* right_limit_switch; +extern pros::ADIDigitalIn left_limit_switch; +extern pros::ADIDigitalIn right_limit_switch; /** * Initialize two limitswithces to change pages on the lcd * diff --git a/src/EZ-Template/pre_auto_selector.cpp b/src/EZ-Template/pre_auto_selector.cpp index 22292db2..5e827fd9 100644 --- a/src/EZ-Template/pre_auto_selector.cpp +++ b/src/EZ-Template/pre_auto_selector.cpp @@ -2,8 +2,9 @@ namespace ez { - pros::ADIDigitalIn* left_limit_switch = nullptr; - pros::ADIDigitalIn* right_limit_switch = nullptr; + bool limitSwitchesExist = false; + pros::ADIDigitalIn left_limit_switch(-1); + pros::ADIDigitalIn right_limit_switch(-1); void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port) { if(left_limit_port == -1 || right_limit_port == -1) @@ -11,8 +12,9 @@ namespace ez limit_switch_task.suspend(); return; } - left_limit_switch = new pros::ADIDigitalIn(left_limit_port); - right_limit_switch = new pros::ADIDigitalIn(right_limit_port); + limitSwitchesExist = true; + left_limit_switch = pros::ADIDigitalIn(left_limit_port); + right_limit_switch = pros::ADIDigitalIn(right_limit_port); limit_switch_task.resume(); } @@ -20,19 +22,20 @@ namespace ez { while(true) { - if(left_limit_switch || right_limit_switch) + if(limitSwitchesExist) { - if(left_limit_switch->get_new_press()) + if(left_limit_switch.get_new_press()) { ez::as::page_down(); } - else if(right_limit_switch->get_new_press()) + else if(right_limit_switch.get_new_press()) { ez::as::page_up(); } } + pros::delay(20); - } } +} pros::Task limit_switch_task(limitSwitchTask, nullptr); }