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: main.cpp
- Revision:
- 5:aef6f39b9683
- Parent:
- 4:679bf698903e
- Child:
- 6:17e3a28338dc
--- a/main.cpp Mon Nov 16 09:08:56 2020 +0000
+++ b/main.cpp Tue Nov 17 08:29:41 2020 +0000
@@ -16,6 +16,9 @@
// power clock
#define POWER_CHANGE_PER_CLOCK 5
+// connect timeout LED
+#define CONNECT_TIMEOUT_LED D2
+
// PWM
PwmOut pwmL(PWM_L);
// DIR
@@ -27,6 +30,8 @@
// serial
Serial serial(D5,D4);
+// time out led
+DigitalOut connectTimeoutLED(CONNECT_TIMEOUT_LED);
// joystick analogin
//AnalogIn joyX(A0);
@@ -42,10 +47,12 @@
// attach function
void control_rx();
+// time out
+Timer connectTimer;
+int connectLimit = 2000;
int main()
{
- //printf("start program... \n\r");
// period
pwmL.period_us(100);
pwmR.period_us(100);
@@ -58,15 +65,22 @@
// serial attach
serial.baud(115200);
serial.attach(control_rx,Serial::RxIrq);
-
- //printf("finish start up! \n\r");
-
+ // connect timer
+ connectTimer.reset();
+ connectTimer.start();
+
while(1) {
// prepare power value
float powerL,powerR;
- //float x = joyX.read(); // go ahead & back
- //float y = joyY.read(); // left & right
+ // last connect checker
+ if(connectTimer.read_ms() > connectLimit){
+ x = 0.5;
+ y = 0.5;
+ // LED
+ connectTimeoutLED = !connectTimeoutLED;
+ wait_ms(50);
+ }
// value format
if(x > 1) x = 1.0;
if(x < 0) x = 0.0;
@@ -198,7 +212,9 @@
// save
x = formatX;
y = formatY;
- //printf("x:%hu y:%hu byte[%x %x %x %x]\n\r",uintX,uintY,bytes[1],bytes[2],bytes[3],bytes[4]);
+
+ // reset connect timer
+ connectTimer.reset();
break;
}else{
head = -1;