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.
Dependencies: PinDetect_hw3 USBDevice mbed
Revision 2:e3a7b0fd4a59, committed 2015-09-21
- Comitter:
- franklu
- Date:
- Mon Sep 21 15:22:04 2015 +0000
- Parent:
- 1:8252a6052ebe
- Commit message:
- changed main names;
Changed in this revision
| joystick_main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show diff for this revision Revisions of this file |
diff -r 8252a6052ebe -r e3a7b0fd4a59 joystick_main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/joystick_main.cpp Mon Sep 21 15:22:04 2015 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "USBKeyboard.h"
+#include "PinDetect.h"
+
+AnalogIn potx(A0);
+AnalogIn poty(A1);
+USBKeyboard keyboard;
+PinDetect button(D3);
+PinDetect button1(D4);
+PinDetect button2(D5);
+int state[3];
+
+void button_pressed() {
+ state[0] = 1;
+}
+
+void button_released() {
+ state[0] = 0;
+}
+
+void button1_pressed() {
+ state[1] = 1;
+}
+
+void button1_released() {
+ state[1] = 0;
+}
+
+void button2_pressed() {
+ state[2] = 1;
+}
+
+void button2_released() {
+ state[2] = 0;
+}
+
+int main() {
+ button.attach_asserted(&button_pressed);
+ button.attach_deasserted(&button_released);
+ button.setAssertValue(0);
+ button.setSampleFrequency();
+
+ button1.attach_asserted(&button1_pressed);
+ button1.attach_deasserted(&button1_released);
+ button1.setAssertValue(0);
+ button1.setSampleFrequency();
+
+ button2.attach_asserted(&button2_pressed);
+ button2.attach_deasserted(&button2_released);
+ button2.setAssertValue(0);
+ button2.setSampleFrequency();
+
+ while(1) {
+ if (state[0] == 1) {
+ keyboard.keyCode('e');
+ }
+ if (state[1] == 1) {
+ keyboard.keyCode('m');
+ }
+ if (state[2] == 1) {
+ keyboard.keyCode('n');
+ }
+ int potx_read = (int)(potx.read() * 100.0f);
+ int poty_read = (int)(poty.read() * 100.0f);
+ if (potx_read > 70) {
+ keyboard.keyCode('s');
+ }else if (potx_read < 30) {
+ keyboard.keyCode('w');
+ } else if (poty_read > 80) {
+ keyboard.keyCode('d');
+ } else if (poty_read < 20) {
+ keyboard.keyCode('a');
+ }
+ wait_ms(1);
+ }
+}
diff -r 8252a6052ebe -r e3a7b0fd4a59 main.cpp
--- a/main.cpp Mon Sep 21 15:19:03 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-#include "mbed.h"
-#include "USBKeyboard.h"
-#include "PinDetect.h"
-
-AnalogIn potx(A0);
-AnalogIn poty(A1);
-USBKeyboard keyboard;
-PinDetect button(D3);
-PinDetect button1(D4);
-PinDetect button2(D5);
-int state[3];
-
-void button_pressed() {
- state[0] = 1;
-}
-
-void button_released() {
- state[0] = 0;
-}
-
-void button1_pressed() {
- state[1] = 1;
-}
-
-void button1_released() {
- state[1] = 0;
-}
-
-void button2_pressed() {
- state[2] = 1;
-}
-
-void button2_released() {
- state[2] = 0;
-}
-
-int main() {
- button.attach_asserted(&button_pressed);
- button.attach_deasserted(&button_released);
- button.setAssertValue(0);
- button.setSampleFrequency();
-
- button1.attach_asserted(&button1_pressed);
- button1.attach_deasserted(&button1_released);
- button1.setAssertValue(0);
- button1.setSampleFrequency();
-
- button2.attach_asserted(&button2_pressed);
- button2.attach_deasserted(&button2_released);
- button2.setAssertValue(0);
- button2.setSampleFrequency();
-
- while(1) {
- if (state[0] == 1) {
- keyboard.keyCode('e');
- }
- if (state[1] == 1) {
- keyboard.keyCode('m');
- }
- if (state[2] == 1) {
- keyboard.keyCode('n');
- }
- int potx_read = (int)(potx.read() * 100.0f);
- int poty_read = (int)(poty.read() * 100.0f);
- if (potx_read > 70) {
- keyboard.keyCode('s');
- }else if (potx_read < 30) {
- keyboard.keyCode('w');
- } else if (poty_read > 80) {
- keyboard.keyCode('d');
- } else if (poty_read < 20) {
- keyboard.keyCode('a');
- }
- wait_ms(1);
- }
-}