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: mbed
Diff: main.cpp
- Revision:
- 0:7918b43be5cf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jan 10 06:36:28 2019 +0000
@@ -0,0 +1,239 @@
+#include "mbed.h"
+DigitalOut led1(LED1);
+
+//红绿灯引脚定义
+DigitalOut NorthStraightRed(PC_9);
+DigitalOut NorthStraightYellow(PB_8);
+DigitalOut NorthStraightGreen(PB_9);
+DigitalOut NorthLeftRed(PC_8);
+DigitalOut NorthLeftYellow(PC_6);
+DigitalOut NorthLeftGreen(PC_5);
+DigitalOut WestStraightRed(PA_10);
+DigitalOut WestStraightYellow(PA_2);
+DigitalOut WestStraightGreen(PA_3);
+DigitalOut WestLeftRed(PB_15);
+DigitalOut WestLeftYellow(PB_14);
+DigitalOut WestLeftGreen(PB_13);
+
+DigitalOut Cameraout(PC_10);
+
+PwmOut mypwm(PB_3);
+
+int State=1;
+int i=0;
+Timer debounce;
+bool judg = true;
+int ju=0;
+
+InterruptIn button1(USER_BUTTON);
+InterruptIn detector(PC_7);
+
+void Emergence()
+{
+ NorthStraightRed=1;
+ NorthStraightGreen=0;
+ NorthStraightYellow=0;
+ NorthLeftRed=1;
+ NorthLeftGreen=0;
+ NorthLeftYellow=0;
+ WestStraightRed=0;
+ WestStraightYellow=0;
+ WestStraightGreen=1;
+ WestLeftRed=1;
+ WestLeftYellow=0;
+ WestLeftGreen=0;
+
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(18.5);
+ wait_ms(100);
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(1.5);
+ wait_ms(240);
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(20);
+ wait(4);
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(18.5);
+}
+
+void Flash()
+/*{
+ if(judg)
+ {
+ Cameraout = !Cameraout;
+ wait_ms(100);
+ //Cameraout = !Cameraout;
+ }
+ judg=!judg;
+}*/
+/*{
+ if((debounce.read_ms()>100)&&judg&&ju==1)
+ {
+ Cameraout=!Cameraout;
+ debounce.reset();
+ wait_ms(100);
+ Cameraout=!Cameraout;
+ ju=0;
+ }
+ else
+ ju=1;
+ judg = !judg;
+
+}*/
+
+{
+ if(i==1)
+ {
+ if(debounce.read_ms()>1000)
+ {
+ Cameraout=!Cameraout;
+ debounce.reset();
+ wait_ms(100);
+ Cameraout=!Cameraout;
+
+ }
+ }
+}
+
+int main()
+{
+ debounce.start();
+ button1.fall(&Emergence);
+ detector.fall(&Flash);
+ while(1)
+ {
+ i=State%9;
+ State++;
+ switch(i){
+ case 1: NorthStraightRed=0;
+ NorthStraightGreen=1;
+ NorthStraightYellow=0;
+ NorthLeftRed=1;
+ NorthLeftGreen=0;
+ NorthLeftYellow=0;
+ WestStraightRed=1;
+ WestStraightYellow=0;
+ WestStraightGreen=0;
+ WestLeftRed=1;
+ WestLeftYellow=0;
+ WestLeftGreen=0;
+ wait(5);
+ break;
+ case 2: NorthStraightRed=0;
+ NorthStraightGreen=0;
+ NorthStraightYellow=1;
+ NorthLeftRed=0;
+ NorthLeftGreen=0;
+ NorthLeftYellow=1;
+ WestStraightRed=1;
+ WestStraightYellow=0;
+ WestStraightGreen=0;
+ WestLeftRed=1;
+ WestLeftYellow=0;
+ WestLeftGreen=0;
+ wait(2);
+ break;
+ case 3: NorthStraightRed=1;
+ NorthStraightGreen=0;
+ NorthStraightYellow=0;
+ NorthLeftRed=0;
+ NorthLeftGreen=1;
+ NorthLeftYellow=0;
+ WestStraightRed=1;
+ WestStraightYellow=0;
+ WestStraightGreen=0;
+ WestLeftRed=1;
+ WestLeftYellow=0;
+ WestLeftGreen=0;
+ wait(5);
+ break;
+ case 4: NorthStraightRed=1;
+ NorthStraightGreen=0;
+ NorthStraightYellow=0;
+ NorthLeftRed=0;
+ NorthLeftGreen=0;
+ NorthLeftYellow=1;
+ WestStraightRed=0;
+ WestStraightYellow=1;
+ WestStraightGreen=0;
+ WestLeftRed=1;
+ WestLeftYellow=0;
+ WestLeftGreen=0;
+ wait(2);
+ break;
+ case 5: NorthStraightRed=1;
+ NorthStraightGreen=0;
+ NorthStraightYellow=0;
+ NorthLeftRed=1;
+ NorthLeftGreen=0;
+ NorthLeftYellow=0;
+ WestStraightRed=0;
+ WestStraightYellow=0;
+ WestStraightGreen=1;
+ WestLeftRed=1;
+ WestLeftYellow=0;
+ WestLeftGreen=0;
+ //闸杆抬起
+
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(18.5);
+ wait_ms(100);
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(1.5);
+ wait_ms(240);
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(20);
+ wait(4);
+ mypwm.period_ms(20);
+ mypwm.pulsewidth_ms(18.5);
+ break;
+ case 6: NorthStraightRed=1;
+ NorthStraightGreen=0;
+ NorthStraightYellow=0;
+ NorthLeftRed=1;
+ NorthLeftGreen=0;
+ NorthLeftYellow=0;
+ WestStraightRed=0;
+ WestStraightYellow=1;
+ WestStraightGreen=0;
+ WestLeftRed=0;
+ WestLeftYellow=1;
+ WestLeftGreen=0;
+ wait(2);
+ break;
+ case 7: NorthStraightRed=1;
+ NorthStraightGreen=0;
+ NorthStraightYellow=0;
+ NorthLeftRed=1;
+ NorthLeftGreen=0;
+ NorthLeftYellow=0;
+ WestStraightRed=1;
+ WestStraightYellow=0;
+ WestStraightGreen=0;
+ WestLeftRed=0;
+ WestLeftYellow=0;
+ WestLeftGreen=1;
+ wait(5);
+ break;
+ case 8: NorthStraightRed=0;
+ NorthStraightGreen=0;
+ NorthStraightYellow=1;
+ NorthLeftRed=1;
+ NorthLeftGreen=0;
+ NorthLeftYellow=0;
+ WestStraightRed=1;
+ WestStraightYellow=0;
+ WestStraightGreen=0;
+ WestLeftRed=0;
+ WestLeftYellow=1;
+ WestLeftGreen=0;
+ wait(2);
+ break;
+ default:break;
+ }
+
+
+ }
+
+
+}