create joystick controller

This commit is contained in:
rafa 2025-05-23 22:07:45 +01:00
parent a4cd6d1796
commit 19cd517153

View File

@ -0,0 +1,67 @@
#import "Arduino.h"
class JoySitkController {
private:
int pin_x;
int pin_y;
int x = 1024 / 2;
int y = 1024 / 2;
public:
JoySitkController(int pin_x, int pin_y) {
this->set_pin_x(pin_x);
this->set_pin_y(pin_y);
}
void configure_pins() {
pinMode(this->pin_x, INPUT);
pinMode(this->pin_y, INPUT);
}
int get_x() {
return this->x;
}
int get_y() {
return this->y;
}
void set_x(int x) {
this->x = x;
}
void set_y(int y) {
this->y = y;
}
int get_pin_x() {
return this->pin_x;
}
void set_pin_x(int pin_x) {
this->pin_x = pin_x;
}
int get_pin_y() {
return this->pin_y;
}
void set_pin_y(int pin_y) {
this->pin_y = pin_y;
}
void read(){
this->set_y(analogRead(this->pin_y));
this->set_x(analogRead(this->pin_x));
}
bool is_moving_right(){
return this->get_x() < 512;
}
bool is_moving_left(){
return this->get_x() > 512;
}
};