Now enters a button protocol when clicked
This commit is contained in:
parent
02f63057bf
commit
bb3d64a046
|
@ -7,12 +7,37 @@
|
||||||
#define JOYSTICK_PIN 63
|
#define JOYSTICK_PIN 63
|
||||||
#define JOY_CRITICAL_POINT 25
|
#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) {
|
void InputControlTask(void *params) {
|
||||||
|
inputTask = xTaskGetCurrentTaskHandle();
|
||||||
|
pinMode(BTN_PIN, INPUT_PULLUP); // Setup button pin
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int joystickValueRaw = analogRead(JOYSTICK_PIN);
|
int joystickValueRaw = analogRead(JOYSTICK_PIN);
|
||||||
int joystickValue = map(joystickValueRaw, 0, 1023, 0, 100);
|
int joystickValue = map(joystickValueRaw, 0, 1023, 0, 100);
|
||||||
bool leftMovement = (joystickValue > (100 - JOY_CRITICAL_POINT));
|
bool leftMovement = (joystickValue > (100 - JOY_CRITICAL_POINT));
|
||||||
bool rightMovement = (joystickValue < 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) {
|
if (leftMovement) {
|
||||||
StepperController::SetMotorEnabled('x', true);
|
StepperController::SetMotorEnabled('x', true);
|
||||||
|
|
Loading…
Reference in New Issue