Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:ebc7a8e353d1, committed 2021-05-23
- Comitter:
- quagga
- Date:
- Sun May 23 15:09:33 2021 +0000
- Commit message:
- Emulate Gravis Stinger: pitch and roll and buttons A and B to serial data packet
Changed in this revision
diff -r 000000000000 -r ebc7a8e353d1 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Sun May 23 15:09:33 2021 +0000 @@ -0,0 +1,8 @@ +Emulate Gravis stinger gamepad on microbit. +Uses accelerometer pitch and roll data plus input from buttons to create serial data packet. + +On linux connect using inputattach: +sudo inputattach --baud 115200 --stinger /dev/ttyXXXX + +Calibrate with: +jscal -c /dev/input/jsX
diff -r 000000000000 -r ebc7a8e353d1 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun May 23 15:09:33 2021 +0000
@@ -0,0 +1,35 @@
+#include"MicroBit.h"
+
+MicroBit uBit;
+
+int main()
+{
+ uBit.init();
+ //listen for stinger signal E5E5
+ ManagedString sting=" E5E5";
+ ManagedString readbuf=uBit.serial.read(5);
+ if (readbuf==sting)
+ {
+ //Identify to inputattach driver
+ uBit.serial.send("\r\n0600520058C272");
+ uBit.display.scroll("Stinger");
+ int x,y;
+ unsigned char data[4];
+ while(1)
+ {
+ //packets [0 && 3] deal with buttons
+ //packet [0,1,2] deal with joystick
+ x=((uBit.accelerometer.getPitch()+180)*126/360);
+ y=((uBit.accelerometer.getRoll()+180)*126/360);
+ data[1]=0x3f-(x & 0x3f);
+ data[2]=y & 0x3f;
+ data[0]=((y & 0x40)>>5)+((x & 0x40)>>6);
+
+ if (uBit.buttonA.isPressed()){data[0]+=0x20;}
+ if (uBit.buttonB.isPressed()){data[0]+=0x10;}
+ //send packet
+ for (int i=0;i<4;i++){uBit.serial.sendChar(data[i]);}
+ }
+ }
+ return 0;
+}
diff -r 000000000000 -r ebc7a8e353d1 microbit.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/microbit.lib Sun May 23 15:09:33 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Lancaster-University/code/microbit/#4b89e7e3494f