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.
Fork of DFRobotMbedTest by
Revision 4:d5bf98a13160, committed 2016-07-15
- Comitter:
- dfrobot
- Date:
- Fri Jul 15 07:11:43 2016 +0000
- Parent:
- 3:a005efbb789e
- Child:
- 5:608466ce27ff
- Commit message:
- add user Button
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 15 03:02:40 2016 +0000
+++ b/main.cpp Fri Jul 15 07:11:43 2016 +0000
@@ -1,5 +1,5 @@
#include "mbed.h"
-
+
Serial uart1(PA_13, PA_14); // tx, rx
Serial uart2(PC_10, PC_11); // tx, rx
DigitalOut myD1(D10);
@@ -12,39 +12,56 @@
PwmOut PWM1(D3);
PwmOut PWM2(D5);
PwmOut PWM3(D6);
-
+DigitalIn myButton(PC_06);
+
+Timeout digitalTimeout;
+Timeout analogTimeout;
+void attimeoutD()
+{
+ static int pos = 0;
+ if(pos == 0){
+ myD1 = 0;
+ myD2 = 0;
+ myD3 = 0;
+ myD4 = 0;
+ }else{
+ myD1 = 1;
+ myD2 = 1;
+ myD3 = 1;
+ myD4 = 1;
+ }
+ pos = !pos;
+ digitalTimeout.attach(&attimeoutD,0.5);
+}
+void attimeoutA()
+{
+ uart1.printf("A1:%02fV ",myA1.read()*3.3);
+ uart1.printf("A2:%02fV ",myA2.read()*3.3);
+ uart1.printf("A3:%02fV \r\n",myA3.read()*3.3);
+ analogTimeout.attach(&attimeoutA,1);
+}
+
int main() {
- uart1.baud(115200);
- uart2.baud(115200);
+ uart1.baud(9600);
+ uart2.baud(9600);
PWM1.period_us(500);
PWM2.period_us(500);
PWM3.period_us(500);
PWM1 = 0.2;
- PWM2 = 0.5;
+ PWM2 = 0.5;
PWM3 = 0.8;
uart2.printf("uart2:for Loopback test,please input something\n");
- uart1.printf("start testing uart1 digitalOut and PWM and analogIn\n");
- while(1){
- while(uart2.readable())
- uart2.printf("%c", uart2.getc());
-
- wait(0.25);
- myD1 = 1;
- myD2 = 1;
- myD3 = 1;
- myD4 = 1;
- wait(0.25);
- myD1 = 0;
- myD2 = 0;
- myD3 = 0;
- myD4 = 0;
-
- uart1.printf("A1:%02f\n",myA1.read()*3.3);
- uart1.printf("A2:%02f\n",myA2.read()*3.3);
- uart1.printf("A3:%02f\n",myA3.read()*3.3);
- }
-}
-
-
-
-
+ uart1.printf("start testing uart1 digitalOut and PWM and analogIn\r\n");
+ digitalTimeout.attach(&attimeoutD,0.5);
+ analogTimeout.attach(&attimeoutA,1);
+
+ while(1) {
+ if (myButton == 0) {
+ uart1.printf("User Button is Pressed!!!\r\n");
+ }
+ if(uart2.readable()){
+ char ch = uart2.getc();
+ uart2.printf("%c", ch);
+ }
+ }
+}
\ No newline at end of file
