Skip to content

Commit

Permalink
Added limit switch for lcd
Browse files Browse the repository at this point in the history
  • Loading branch information
HakopZ committed Jan 7, 2022
1 parent 55fc9d5 commit 21da733
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/EZ-Template/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "EZ-Template/drive/drive.hpp"
#include "EZ-Template/sdcard.hpp"
#include "EZ-Template/util.hpp"
#include "EZ-Template/pre_auto_selector.hpp"
22 changes: 22 additions & 0 deletions include/EZ-Template/pre_auto_selector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include "main.h"

namespace ez
{
extern pros::ADIDigitalIn* left_limit_switch;
extern pros::ADIDigitalIn* right_limit_switch;
/**
* Initialize two limitswithces to change pages on the lcd
*
* @param left_limit_port
* port for the left limit switch
* @param right_limit_port
* port for the right limit switch
*/
void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port);

/**
* pre_auto_task
*/
extern pros::Task limit_switch_task;
}
38 changes: 38 additions & 0 deletions src/EZ-Template/pre_auto_selector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "pre_auto_selector.hpp"

namespace ez
{
pros::ADIDigitalIn* left_limit_switch = nullptr;
pros::ADIDigitalIn* right_limit_switch = nullptr;
void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port)
{
if(left_limit_port == -1 || right_limit_port == -1)
{
limit_switch_task.suspend();
return;
}
left_limit_switch = new pros::ADIDigitalIn(left_limit_port);
right_limit_switch = new pros::ADIDigitalIn(right_limit_port);
limit_switch_task.resume();
}

void limitSwitchTask()
{
while(true)
{
if(left_limit_switch || right_limit_switch)
{
if(left_limit_switch->get_new_press())
{
ez::as::page_down();
}
else if(right_limit_switch->get_new_press())
{
ez::as::page_up();
}
}
pros::delay(20);
}
}
pros::Task limit_switch_task(limitSwitchTask, nullptr);
}
11 changes: 5 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Drive chassis (
// eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 2.333.
// eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 0.6.
,2


// Uncomment if using tracking wheels
/*
Expand Down Expand Up @@ -56,9 +56,8 @@ Drive chassis (
void initialize() {
// Print our branding over your terminal :D
ez::print_ez_template();

pros::delay(500); // Stop the user from doing anything while legacy ports configure.

ez::limit_switch_lcd_initialize(-1, -1); //limit switch for lcd
// Configure your chassis controls
chassis.toggle_modify_curve_with_controller(true); // Enables modifying the controller curve with buttons on the joysticks
chassis.set_active_brake(0); // Sets the active brake kP. We recommend 0.1.
Expand Down Expand Up @@ -127,9 +126,9 @@ void competition_initialize() {
void autonomous() {
chassis.reset_gyro(); // Reset gyro position to 0
chassis.reset_drive_sensor(); // Reset drive sensors to 0
chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.
chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.

ez::as::auton_selector.call_selected_auton(); // Calls selected auton from autonomous selector.
ez::as::auton_selector.call_selected_auton(); // Calls selected auton from autonomous selector.
}


Expand All @@ -152,7 +151,7 @@ void opcontrol() {
chassis.set_drive_brake(MOTOR_BRAKE_COAST);

while (true) {

chassis.tank(); // Tank control
// chassis.arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.arcade_standard(ez::SINGLE); // Standard single arcade
Expand Down

1 comment on commit 21da733

@ssejrog
Copy link
Member

@ssejrog ssejrog commented on 21da733 Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#34

Please sign in to comment.