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 @@ -30,6 +30,8 @@ String pinstrapToName(uint8_t pinstrap) {
3030 switch (pinstrap) {
3131 case 0x3C :
3232 return " BUZZER" ;
33+ case 0x58 :
34+ return " JOYSTICK" ;
3335 case 0x7C :
3436 return " BUTTONS" ;
3537 case 0x76 :
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ ModulinoKnob encoder;
77ModulinoDistance distance;
88ModulinoMovement imu;
99ModulinoThermo thermo;
10+ ModulinoJoystick joystick;
1011
1112void setup () {
1213
@@ -22,6 +23,7 @@ void setup() {
2223
2324 imu.begin ();
2425 thermo.begin ();
26+ joystick.begin ();
2527}
2628
2729int skip = 0 ;
@@ -55,6 +57,10 @@ void loop() {
5557 Serial.println (" \t Temperature: " + String (thermo.getTemperature ()));
5658 }
5759
60+ if (joystick.update ()) {
61+ Serial.println (" x: " + String (joystick.getX ()) + " // y: " + String (joystick.getY ()) + " // pressed: " + String (joystick.isPressed ()));
62+ }
63+
5864 if (buttons.update ()) {
5965 if (buttons.isPressed (0 )) {
6066 leds.set (1 + skip, RED, 100 );
Original file line number Diff line number Diff line change 11// Copyright (c) 2024 Arduino SA
22// SPDX-License-Identifier: MPL-2.0
33
4+ #include " Arduino.h"
45#include " Wire.h"
56#include < vector>
67#include < vl53l4cd_class.h> // from stm32duino
@@ -155,6 +156,42 @@ class ModulinoButtons : public Module {
155156 std::vector<uint8_t > match = { 0x7C }; // same as fw main.c
156157};
157158
159+ class ModulinoJoystick : public Module {
160+ public:
161+ ModulinoJoystick (uint8_t address = 0xFF )
162+ : Module(address, " JOYSTICK" ) {}
163+ bool update () {
164+ uint8_t buf[3 ];
165+ auto res = read ((uint8_t *)buf, 3 );
166+ auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
167+ last_status[0 ] = buf[0 ];
168+ last_status[1 ] = buf[1 ];
169+ last_status[2 ] = buf[2 ];
170+ return ret;
171+ }
172+ PinStatus isPressed () {
173+ return last_status[2 ] ? HIGH : LOW;
174+ }
175+ int8_t getX () {
176+ return (last_status[0 ] < 128 ? (128 - last_status[0 ]) : -(last_status[0 ] - 128 ));
177+ }
178+ int8_t getY () {
179+ return (last_status[1 ] < 128 ? (128 - last_status[1 ]) : -(last_status[1 ] - 128 ));
180+ }
181+ virtual uint8_t discover () {
182+ for (int i = 0 ; i < match.size (); i++) {
183+ if (scan (match[i])) {
184+ return match[i];
185+ }
186+ }
187+ return 0xFF ;
188+ }
189+ private:
190+ uint8_t last_status[3 ];
191+ protected:
192+ std::vector<uint8_t > match = { 0x58 }; // same as fw main.c
193+ };
194+
158195class ModulinoBuzzer : public Module {
159196public:
160197 ModulinoBuzzer (uint8_t address = 0xFF )
You can’t perform that action at this time.
0 commit comments