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,11 @@ void loop() {
6769 Serial.println (" \t Temperature: " + String (thermo.getTemperature ()));
6870 }
6971
72+ // Check for joystick movement
73+ if (joystick.update ()) {
74+ Serial.println (" x: " + String (joystick.getX ()) + " // y: " + String (joystick.getY ()) + " // pressed: " + String (joystick.isPressed ()));
75+ }
76+
7077 // Check for button presses
7178 if (buttons.update ()) {
7279 // Button A: Red LED and 440Hz tone
Original file line number Diff line number Diff line change @@ -182,6 +182,42 @@ class ModulinoButtons : public Module {
182182 uint8_t match[1 ] = { 0x7C }; // same as fw main.c
183183};
184184
185+ class ModulinoJoystick : public Module {
186+ public:
187+ ModulinoJoystick (uint8_t address = 0xFF )
188+ : Module(address, " JOYSTICK" ) {}
189+ bool update () {
190+ uint8_t buf[3 ];
191+ auto res = read ((uint8_t *)buf, 3 );
192+ auto ret = res && (buf[0 ] != last_status[0 ] || buf[1 ] != last_status[1 ] || buf[2 ] != last_status[2 ]);
193+ last_status[0 ] = buf[0 ];
194+ last_status[1 ] = buf[1 ];
195+ last_status[2 ] = buf[2 ];
196+ return ret;
197+ }
198+ PinStatus isPressed () {
199+ return last_status[2 ] ? HIGH : LOW;
200+ }
201+ int8_t getX () {
202+ return (last_status[0 ] < 128 ? (128 - last_status[0 ]) : -(last_status[0 ] - 128 ));
203+ }
204+ int8_t getY () {
205+ return (last_status[1 ] < 128 ? (128 - last_status[1 ]) : -(last_status[1 ] - 128 ));
206+ }
207+ virtual uint8_t discover () {
208+ for (unsigned int i = 0 ; i < sizeof (match)/sizeof (match[0 ]); i++) {
209+ if (scan (match[i])) {
210+ return match[i];
211+ }
212+ }
213+ return 0xFF ;
214+ }
215+ private:
216+ uint8_t last_status[3 ];
217+ protected:
218+ uint8_t match[1 ] = { 0x58 }; // same as fw main.c
219+ };
220+
185221class ModulinoBuzzer : public Module {
186222public:
187223 ModulinoBuzzer (uint8_t address = 0xFF )
You can’t perform that action at this time.
0 commit comments