generated from tpII/templates-grupos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cdfd37
commit 922bab2
Showing
8 changed files
with
184 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
#include "joystick_controller.h" | ||
|
||
//Lecturas de X,Y cuando el joystick esta inactivo, y rango de valores ignorados | ||
#define X_STANDBY 800 | ||
#define Y_STANDBY 3200 | ||
#define DEADZONE 300 | ||
|
||
static bool initialized_flag = false; | ||
|
||
static int x_reading = X_STANDBY; | ||
static int y_reading = Y_STANDBY; | ||
static int stick_button_state = 0; | ||
|
||
static bool shift = false; | ||
static int shift_x = 0; | ||
static int shift_y = 0; | ||
|
||
void JOYSTICK_init() | ||
{ | ||
pinMode(SWPin, INPUT_PULLUP); | ||
initialized_flag = true; | ||
} | ||
|
||
void JOYSTICK_update() | ||
{ | ||
if (initialized_flag) | ||
{ | ||
shift = false; | ||
shift_x = 0; | ||
shift_y = 0; | ||
|
||
// Lee los valores del joystick | ||
x_reading = analogRead(VRxPin); | ||
y_reading = analogRead(VRyPin); | ||
stick_button_state = digitalRead(SWPin); // Lee el boton (0 si se presiona, 1 si no) | ||
|
||
if (x_reading > X_STANDBY + 3*DEADZONE) | ||
{ | ||
//Serial.println("Moviendo X+"); | ||
shift_x = 1; | ||
shift = true; | ||
} | ||
|
||
if (x_reading < X_STANDBY - 2*DEADZONE) | ||
{ | ||
//Serial.println("Moviendo X-"); | ||
shift_x = -1; | ||
shift = true; | ||
} | ||
|
||
if (y_reading > Y_STANDBY + 2*DEADZONE) | ||
{ | ||
//Serial.println("Moviendo Y-"); | ||
shift_y = -1; | ||
shift = true; | ||
} | ||
|
||
if (y_reading < Y_STANDBY - 3*DEADZONE) | ||
{ | ||
//Serial.println("Moviendo Y+"); | ||
shift_y = 1; | ||
shift = true; | ||
} | ||
|
||
if (shift) ARM_shift_by(shift_x, shift_y); | ||
|
||
if (!stick_button_state) | ||
{ | ||
//Serial.println("Stick Presionado"); | ||
ARM_line_to(STARTING_X, STARTING_Y); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
#ifndef _JOYSTICK_CONTROLLER_H_ | ||
#define _JOYSTICK_CONTROLLER_H_ | ||
|
||
#include <Arduino.h> | ||
#include "arm_controller.h" | ||
|
||
//Pines a los que se conectan las entradas de X, Y, y el boton del Stick respectivamente | ||
const int VRxPin = 2; | ||
const int VRyPin = 4; | ||
const int SWPin = 26; | ||
|
||
void JOYSTICK_init(); | ||
void JOYSTICK_update(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters