Void Sentry
An AI-driven, real-time Sentry Turret platform leveraging asynchronous I/O and computer vision to deliver high-precision autonomous motion tracking on resource-constrained embedded hardware.
Loading...
Searching...
No Matches
joystick.h
1
9#pragma once
10
11#include <Arduino.h>
12
15#define JOYSTICK_DEADZONE 150
16#define JOYSTICK_RESOLUTION_BITS 12
17#define JOYSTICK_SAMPLES 5
27{
28private:
29 uint8_t _pin_x;
30 uint8_t _pin_y;
31 uint8_t _pin_z;
32 int _deadzone;
33 int _center_x, _center_y;
34
39 int _read_raw(uint8_t pin) const;
40
46 int _process_axis(int raw_val, int center) const;
47
54 int _map_speed(int val, int min_out, int max_out) const;
55
56public:
69 Joystick(uint8_t pin_x, uint8_t pin_y, uint8_t pin_z, int deadzone = JOYSTICK_DEADZONE)
70 : _pin_x(pin_x), _pin_y(pin_y), _pin_z(pin_z), _deadzone(deadzone), _center_x(0), _center_y(0) {};
71
77 void begin();
86 int get_x() const { return _process_axis(this->_read_raw(this->_pin_x), this->_center_x); }
87
89 int get_y() const { return _process_axis(this->_read_raw(this->_pin_y), this->_center_y); }
100 bool is_z_held() const { return digitalRead(this->_pin_z) == LOW; }
112 int get_speed_x(int min_out = -255, int max_out = 255) { return this->_map_speed(get_x(), min_out, max_out); }
113
118 int get_speed_y(int min_out = -255, int max_out = 255) { return this->_map_speed(get_y(), min_out, max_out); }
120};
High-level interface for 12-bit analog joystick input.
Definition joystick.h:27
Joystick(uint8_t pin_x, uint8_t pin_y, uint8_t pin_z, int deadzone=JOYSTICK_DEADZONE)
Construct a new Joystick object.
Definition joystick.h:69
void begin()
Configures hardware and performs auto-calibration.
Definition joystick.cpp:3
bool is_z_held() const
Check the current physical state of the button.
Definition joystick.h:100
int get_y() const
Definition joystick.h:89
int get_speed_y(int min_out=-255, int max_out=255)
Maps Y deflection to a motor speed range.
Definition joystick.h:118
int get_speed_x(int min_out=-255, int max_out=255)
Maps X deflection to a motor speed range.
Definition joystick.h:112
int get_x() const
Definition joystick.h:86