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.
Diff: PS3_Controller.cpp
- Revision:
- 0:03f05f023ff4
- Child:
- 3:378f57911f5d
diff -r 000000000000 -r 03f05f023ff4 PS3_Controller.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PS3_Controller.cpp Fri Mar 01 08:14:11 2019 +0000
@@ -0,0 +1,47 @@
+#include "PS3_Controller.h"
+
+PS3_controller::PS3_controller(PinName TX, PinName RX) : _uno(TX,RX)
+{
+ _uno.baud(57600);
+}
+PS3_controller::PS3_controller(Serial &uno):_uno(uno)
+{
+ _uno.baud(57600);
+}
+
+void PS3_controller::read_PAD()
+{
+ _uno.putc(send_data);
+
+ while(!_uno.readable()) {}
+
+ for(int i=0; i<9; i++) str[i]=_uno.getc();
+
+ all_button_on_off = (str[1] << 8);
+ all_button_on_off = (all_button_on_off & 0xff00);
+ all_button_on_off = (all_button_on_off | str[0]);
+
+ for(int i=0; i<6; i++) sthick_value[i] = str[i+2];
+
+ controller_check = str[8];
+}
+
+void PS3_controller::send_UNO(int send_pattern)
+{
+ send_data = send_pattern;
+}
+
+int PS3_controller::button(int button_pattern)
+{
+ return bitRead(all_button_on_off,button_pattern);
+}
+
+int PS3_controller::analog(int sthick_pattern)
+{
+ return sthick_value[sthick_pattern];
+}
+
+bool PS3_controller::conect(void)
+{
+ return controller_check;
+}
\ No newline at end of file