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: Serial6050Yaw CERICA_2019
Diff: main.cpp
- Revision:
- 0:dfbe64c7cd06
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Apr 25 09:11:47 2022 +0000
@@ -0,0 +1,110 @@
+#include "mbed.h"
+#include "board.h"
+#include "Serial6050.h"
+#include "Utility.h"
+
+/*void TurnAround()
+{
+ while(1) {
+ while(dire!=0)
+ dire=mpu.read();
+ if(dire<=180) {
+ cerica.Motor(3,255);
+ } else if(dire>=180) {+
+ 65
+ cerica.Motor(3,-255);
+ }
+ cerica.Motor(3,0);
+ }
+}*/
+void Reload()
+{
+ //PWM.period_us(20000); //周期設定
+ pc.printf("OPEN\r\n");
+ PWM.pulsewidth_us(500);
+ wait(2);
+ pc.printf("CLOSE\r\n");
+ PWM.pulsewidth_us(2400);
+ wait(2);
+}
+
+void ReloadThread()
+{
+ while(true) {
+ if(Opflag==1) {
+ pc.printf("ReloadOP\r\n");
+ PWM.pulsewidth_us(500);
+ wait(1);
+ Opflag=0;
+ } else if(Clflag==1) {
+ pc.printf("ReloadCL\r\n");
+ PWM.pulsewidth_us(2400);
+ wait(1);
+ Clflag=0;
+ } else {
+ //Opflag=0;
+ //Clflag=0;
+ }
+ }
+}
+
+void Bow()
+{
+
+ Opflag=1;
+ cerica.Motor(0,-40);
+ wait(0.5);
+ while(limit_pin.read()==1) {
+
+ cerica.Motor(0,-40);
+ //pc.printf("BOW LOW\r\n");
+
+ }
+ pc.printf("%d\r\n",limit_pin.read());
+ while(1) {
+ cerica.Motor(0,0);
+ Clflag=1;
+ count--;
+ pc.printf("%d\r\n",count);
+ wait(0.4);
+ if(count==0) {
+ count=3;
+ pc.printf("break\r\n");
+ break;
+ }
+ }
+}
+int main()
+{
+ boardInit();
+ limit_pin.mode(PullUp);
+ Thread reload;
+ Thread led;
+ led.start(LEDThread);
+ reload.start(ReloadThread);;
+ PWM.period_us(20000); //周期設定
+ PWM.pulsewidth_us(2400);
+
+ //mpu.init();
+
+ MoveFlag = 1;
+ wait_ms(900);
+ MoveFlag = 0;
+
+ Thread comm;
+ comm.start(commArduinoThread);
+
+ while (true) {
+ if(MoveFlag==1||button.read() == 0) {
+ pc.printf("ON\r\n");
+ Bow();
+ } else {
+ //pc.printf("OFF\r\n");
+ }
+ }
+ //Reload();
+ //pc.printf("%d\n\r",SW1.read());
+ //pc.printf("aaaa\n\r");
+ //pc.printf("%d\n\r",limit_pin.read());
+
+}
\ No newline at end of file