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: SonicDist beep_sound mbed
Diff: main.cpp
- Revision:
- 0:c67fd32beab1
diff -r 000000000000 -r c67fd32beab1 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Sep 10 12:52:18 2016 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "stdio.h"
+#include "SonicDist.h"
+#include "beep_sound.h"
+
+PwmOut R1(PA_11);
+PwmOut R2(PC_6);
+PwmOut L1(PC_8);
+PwmOut L2(PC_9);
+SonicDist sd(D9,A3);
+DigitalOut ledR(A0);
+DigitalOut ledB(A1);
+beep_sound bs(D10);
+
+/* 前進関数 */
+void accel(double val){
+ R1 = 0;
+ R2 = val;
+ L1 = 0;
+ L2 = val;
+}
+/* 空転関数 */
+void idling(void){
+ R1 = 0;
+ R2 = 0;
+ L1 = 0;
+ L2 = 0;
+}
+
+int main(void){
+ double n, dis = sd.read();
+ while(1){
+ dis = sd.read();
+ n = dis/30;
+ if(n>=1){
+ idling();
+ ledR=0;
+ ledB=1;
+ }else{
+ accel(1.0-n);
+ ledR=1;
+ ledB=0;
+ bs.onpu(2,0,0.01);
+ }
+ }
+}
\ No newline at end of file