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 1:76024c0d418c, committed 2020-11-03
- Comitter:
- tetsu_0207
- Date:
- Tue Nov 03 12:05:58 2020 +0000
- Parent:
- 0:b80ab98d2602
- Commit message:
- [Update] analog read type changes float to short
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Nov 02 11:42:46 2020 +0000
+++ b/main.cpp Tue Nov 03 12:05:58 2020 +0000
@@ -9,36 +9,27 @@
int main()
{
- while(1){
- int x = (int32_t)joyX.read();
- int y = (int32_t)joyY.read();
+ serial.baud(115200);
+
+ while(1) {
+ uint16_t x = joyX.read_u16();
+ uint16_t y = joyY.read_u16();
// convert float to byte array
- // x
- char bytesX[4];
- bytesX[0] = (x >> 24) & 0xFF;
- bytesX[1] = (x >> 16) & 0xFF;
- bytesX[2] = (x >> 8) & 0xFF;
- bytesX[3] = x & 0xFF;
- // y
- char bytesY[4];
- bytesY[0] = (y >> 24) & 0xFF;
- bytesY[1] = (y >> 16) & 0xFF;
- bytesY[2] = (y >> 8) & 0xFF;
- bytesY[3] = y & 0xFF;
- // head
- serial.putc(0x3a);
- // send bytes
- // x
- serial.putc(bytesX[0]);
- serial.putc(bytesX[1]);
- serial.putc(bytesX[2]);
- serial.putc(bytesX[3]);
- // y
- serial.putc(bytesY[0]);
- serial.putc(bytesY[1]);
- serial.putc(bytesY[2]);
- serial.putc(bytesY[3]);
-
+ char bytes[4];
+ bytes[0] = x >> 8;
+ bytes[1] = x & 0xfff0;
+ bytes[2] = y >> 8;
+ bytes[3] = y & 0xfff0;
+ if(serial.writeable()) {
+ // send bytes
+ serial.putc(0x3A);
+ for(int i = 0; i <= 3;i++){
+ serial.putc(bytes[i]);
+ }
+ }
+
+ wait_ms(50);
+ printf("uint[x:%d y:%d]\n\r",x,y);
}
}