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: backup.txt
- Revision:
- 2:72952132894a
diff -r 77096ac47e7a -r 72952132894a backup.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/backup.txt Sat Feb 20 09:04:41 2021 +0000
@@ -0,0 +1,162 @@
+#include "mbed.h"
+#include "stdio.h"
+
+//DigitalOut led(LED1);
+
+Serial pc(USBTX, USBRX);
+DigitalIn my_button(USER_BUTTON); // Use the user button to switch from dc motor to servo motor and vice versa
+DigitalIn end_stop(D12); // relais fin de course
+
+PwmOut l1_dc_motor_en(D0);
+DigitalOut l1_dc_motor_cw(D1);
+DigitalOut l1_dc_motor_ccw(D2);
+
+PwmOut l1_servo_en(D5);
+DigitalOut l1_servo_cw(D3);
+DigitalOut l1_servo_ccw(D4);
+
+//
+//PwmOut l2_dc_motor_en(D6);
+//DigitalOut l2_dc_motor_cw(D7);
+//DigitalOut l2_dc_motor_ccw(D8);
+//
+//PwmOut l2_servo_en(D11);
+//DigitalOut l2_servo_cw(D9);
+//DigitalOut l2_servo_ccw(D10);
+
+
+void run_l1_dc_motor_cw(void){
+ l1_dc_motor_en.period_ms(20); // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
+ l1_dc_motor_en.pulsewidth_us(3000);
+ l1_dc_motor_cw=0;
+ l1_dc_motor_ccw=1;
+}
+void run_l1_dc_motor_ccw(void){
+ l1_dc_motor_en.period_ms(20); // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
+ l1_dc_motor_en.pulsewidth_us(3000);
+ l1_dc_motor_cw=1;
+ l1_dc_motor_ccw=0;
+}
+//void run_l2_dc_motor_cw(void){
+// l2_dc_motor_en.period_ms(20); // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
+// l2_dc_motor_en.pulsewidth_us(3000);
+// l2_dc_motor_cw=0;
+// l2_dc_motor_ccw=1;
+//}
+//void run_l2_dc_motor_ccw(void){
+// l2_dc_motor_en.period_ms(20); // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
+// l2_dc_motor_en.pulsewidth_us(3000);
+// l2_dc_motor_cw=1;
+// l2_dc_motor_ccw=0;
+//}
+
+
+void stop_dc_motor(void){
+ l1_dc_motor_cw=0;
+ l1_dc_motor_ccw=0;
+// l2_dc_motor_cw=0;
+// l2_dc_motor_ccw=0;
+
+}
+
+void run_l1_servo_cw(void){
+ l1_servo_cw=1;
+ l1_servo_ccw=0;
+ l1_servo_en.period_us(870);
+ l1_servo_en.pulsewidth_ms(870);
+}
+void run_l1_servo_ccw(void){
+ l1_servo_cw=0;
+ l1_servo_ccw=1;
+ l1_servo_en.period_us(870);
+ l1_servo_en.pulsewidth_ms(870);
+}
+void stop_servo(void){
+ l1_servo_cw=0;
+ l1_servo_ccw=0;
+}
+
+
+void test_limite(void){
+ end_stop.mode(PullDown);
+ while(1){
+ printf("lim=%d\n", end_stop.read());
+
+ if(end_stop.read()==1){
+ stop_dc_motor();
+// led=0;
+ printf("stop_dc_motor\n");
+ }
+ else{
+ run_l1_dc_motor_ccw();
+ printf("motor runs\n");
+// led=1;
+ }
+ }
+
+}
+
+
+int main()
+{
+ unsigned char cmd=0;
+
+ while (true) {
+ scanf("%c", &cmd);
+ if(cmd == '1')
+ {
+ cmd = 0;
+ stop_dc_motor();
+ printf("stop_dc_motor\r\n");
+ }
+ if(cmd == '2')
+ {
+ cmd = 0;
+ run_l1_dc_motor_cw();
+ printf("run_l1_dc_motor_cw\r\n");
+ }
+ if(cmd == '3')
+ {
+ cmd = 0;
+ run_l1_dc_motor_ccw();
+ printf("run_l1_dc_motor_ccw\r\n");
+ }
+ if(cmd == '4')
+ {
+ cmd = 0;
+ run_l1_servo_cw();
+ wait(1);
+ stop_servo();
+ printf("run_l1_servo_cw\r\n");
+ }
+ if(cmd == '5')
+ {
+ cmd = 0;
+ run_l1_servo_ccw();
+ wait(1);
+ stop_servo();
+ printf("run_l1_servo_ccw\r\n");
+ }
+ if(cmd == '6')
+ {
+// cmd = 0;
+// run_l2_dc_motor_cw();
+// printf("run_l2_dc_motor_cw\r\n");
+ }
+ if(cmd == '7')
+ {
+// cmd = 0;
+// run_l2_dc_motor_ccw();
+// printf("run_l2_dc_motor_ccw\r\n");
+ }
+
+
+
+ if(cmd == 'h')
+ {
+ cmd=0;
+ printf("1=stop_dc_motor; 2=run_l1_dc_motor_cw; 3=run_l1_dc_motor_ccw; 4=run_l1_servo_cw; 5=run_l1_servo_ccw, 6=run_l1_dc_motor_cw; 7=run_l1_dc_motor_ccw\n");
+ }
+ }
+
+}