Now enters a button protocol when clicked

This commit is contained in:
BOTAlex 2025-01-25 03:34:00 +01:00
parent 02f63057bf
commit bb3d64a046
1 changed files with 25 additions and 0 deletions

View File

@ -7,12 +7,37 @@
#define JOYSTICK_PIN 63
#define JOY_CRITICAL_POINT 25
#define BTN_PIN 19
TaskHandle_t inputTask;
void ClawProtocol(void *params) {
Serial.println("Started button protocol");
StepperController::SetMotorEnabled('y', true);
StepperController::SetMovementEnabled('y', true);
StepperController::SetMoveQueue('y', 3000);
vTaskResume(inputTask);
Serial.println("Button protocol done");
vTaskDelete(NULL);
}
void InputControlTask(void *params) {
inputTask = xTaskGetCurrentTaskHandle();
pinMode(BTN_PIN, INPUT_PULLUP); // Setup button pin
while (true) {
int joystickValueRaw = analogRead(JOYSTICK_PIN);
int joystickValue = map(joystickValueRaw, 0, 1023, 0, 100);
bool leftMovement = (joystickValue > (100 - JOY_CRITICAL_POINT));
bool rightMovement = (joystickValue < JOY_CRITICAL_POINT);
bool isButtonPress = digitalRead(BTN_PIN) == LOW;
if (isButtonPress){
xTaskCreate(ClawProtocol, "Button protocol", 500, (void*)&inputTask, 100, NULL);
vTaskSuspend(inputTask);
}
if (leftMovement) {
StepperController::SetMotorEnabled('x', true);