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:
- 0:2de015544cb2
diff -r 000000000000 -r 2de015544cb2 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Oct 06 06:03:53 2017 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+PwmOut ENA(D11);
+DigitalOut IN1(D3);
+DigitalOut IN2(D4);
+PwmOut ENB(D12);
+DigitalOut IN3(D5);
+DigitalOut IN4(D6);
+AnalogIn dial(A0);
+AnalogIn distance(A1);
+
+int main() {
+ ENA.period(0.01);
+ ENB.period(0.01);
+ ENA=0;
+ ENB=0;
+ IN1=1;
+ IN2=0;
+ IN3=1;
+ IN4=0;
+
+
+ while(1){
+ float pwm = dial.read();
+ float dist=distance.read();
+ printf("%f,%f\n",pwm,dist);
+ if(dist<0.5){
+ IN1=1;
+ IN2=0;
+ IN3=1;
+ IN4=0;
+ } else {
+ IN1=1;
+ IN2=0;
+ IN3=0;
+ IN4=1;
+ }
+ ENA = pwm;
+ ENB = pwm;
+ }
+}