Update stable version 24/05/2025 #2
67
code/JoyStickController.cpp
Normal file
67
code/JoyStickController.cpp
Normal 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;
|
||||
}
|
||||
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user