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: HCSR04 SRF05 mbed
Diff: colorsensor.cpp
- Revision:
- 1:60c79e942c98
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/colorsensor.cpp Fri Jun 08 22:22:10 2018 +0000
@@ -0,0 +1,69 @@
+#include "mbed.h"
+#include "gyro.h"
+#include "Distance.h"
+
+Timer ccc;
+
+void blue()
+{
+ M1=-1;M2=1;//左边45度
+ wait(0.4);
+ M1=0;M2=0;
+ change(135);
+ driveit();
+ ccc.start();
+ while(1)
+ {
+ if(ccc.read()>15)
+ {
+ M1=1;M2=-1;//右边135度
+ wait(1.25);
+ M1=0;M2=0;
+ change(-135);
+ driveit();
+ enable1();
+ break;
+ }
+ }
+ }
+void red()
+{
+ M1=1;M2=-1;//右边45度
+ wait(0.4);
+ M1=0;M2=0;
+ change(45);
+ driveit();
+ ccc.start();
+ while(1)
+ {
+ if(ccc.read()>15)
+ {
+ M1=1;M2=-1;//右边45度
+ wait(0.4);
+ M1=0;M2=0;
+ change(-45);
+ driveit();
+ enable1();
+ break;
+ }
+ }
+ }
+void green()
+{
+ change(90);
+ driveit();
+ ccc.start();
+ while(1)
+ {
+ if(ccc.read()>20)
+ {
+ M1=1;M2=-1; //右转90
+ wait(0.75);
+ change(-90);
+ driveit();
+ enable1();
+ break;
+ }
+ }
+ }
+