File tree Expand file tree Collapse file tree 4 files changed +2285
-875
lines changed Expand file tree Collapse file tree 4 files changed +2285
-875
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,8 @@ String pinstrapToName(uint8_t pinstrap) {
228228 switch (pinstrap) {
229229 case 0x3C :
230230 return " Buzzer" ;
231+ case 0x58 :
232+ return " Joystick" ;
231233 case 0x7C :
232234 return " Buttons" ;
233235 case 0x76 :
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ ModulinoKnob encoder;
1616ModulinoDistance distance;
1717ModulinoMovement imu;
1818ModulinoThermo thermo;
19+ ModulinoJoystick joystick;
1920
2021void setup () {
2122
@@ -30,6 +31,7 @@ void setup() {
3031 leds.begin ();
3132 imu.begin ();
3233 thermo.begin ();
34+ joystick.begin ();
3335}
3436
3537int skip = 0 ;
@@ -67,6 +69,10 @@ void loop() {
6769 Serial.println (" \t Temperature: " + String (thermo.getTemperature ()));
6870 }
6971
72+ if (joystick.update ()) {
73+ Serial.println (" x: " + String (joystick.getX ()) + " // y: " + String (joystick.getY ()) + " // pressed: " + String (joystick.isPressed ()));
74+ }
75+
7076 // Check for button presses
7177 if (buttons.update ()) {
7278 // Button A: Red LED and 440Hz tone
Original file line number Diff line number Diff line change 99 #error "Learn more at: https://support.arduino.cc/hc/en-us/articles/10483225565980-Select-pin-numbering-for-Nano-ESP32-in-Arduino-IDE"
1010#endif
1111
12+ #include " Arduino.h"
1213#include " Wire.h"
1314#include < vl53l4cd_class.h> // from stm32duino
1415#include < vl53l4ed_class.h> // from stm32duino
@@ -182,6 +183,42 @@ class ModulinoButtons : public Module {
182183 uint8_t match[1 ] = { 0x7C }; // same as fw main.c
183184};
184185
186+ class ModulinoJoystick : public Module {
187+ public:
188+ ModulinoJoystick (uint8_t address = 0xFF )
189+ : Module(address, " JOYSTICK" ) {}
190+ bool update () {
191+ uint8_t buf[3 ];
192+ auto res = read ((uint8_t *)buf, 3 );
193+ auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
194+ last_status[0 ] = buf[0 ];
195+ last_status[1 ] = buf[1 ];
196+ last_status[2 ] = buf[2 ];
197+ return ret;
198+ }
199+ PinStatus isPressed () {
200+ return last_status[2 ] ? HIGH : LOW;
201+ }
202+ int8_t getX () {
203+ return (last_status[0 ] < 128 ? (128 - last_status[0 ]) : -(last_status[0 ] - 128 ));
204+ }
205+ int8_t getY () {
206+ return (last_status[1 ] < 128 ? (128 - last_status[1 ]) : -(last_status[1 ] - 128 ));
207+ }
208+ virtual uint8_t discover () {
209+ for (int i = 0 ; i < match.size (); i++) {
210+ if (scan (match[i])) {
211+ return match[i];
212+ }
213+ }
214+ return 0xFF ;
215+ }
216+ private:
217+ uint8_t last_status[3 ];
218+ protected:
219+ std::vector<uint8_t > match = { 0x58 }; // same as fw main.c
220+ };
221+
185222class ModulinoBuzzer : public Module {
186223public:
187224 ModulinoBuzzer (uint8_t address = 0xFF )
You can’t perform that action at this time.
0 commit comments