Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

Committer:
haefeman
Date:
Wed Apr 28 14:58:37 2021 +0000
Revision:
26:caa4fab7023e
Parent:
22:f71d32309307
3 servos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ackerden 16:f0480e9c5039 1 #include "mbed.h"
ackerden 16:f0480e9c5039 2 #include "Servo.h"
ackerden 16:f0480e9c5039 3
ackerden 16:f0480e9c5039 4 #include "servo_bewegung.h"
ackerden 16:f0480e9c5039 5
haefeman 26:caa4fab7023e 6 #define RIGHT 1200
haefeman 26:caa4fab7023e 7 #define MID 1000
haefeman 26:caa4fab7023e 8 #define MAX 2000
haefeman 26:caa4fab7023e 9 #define LEFT 800
ackerden 22:f71d32309307 10 #define STEP 25
ackerden 16:f0480e9c5039 11 //Time delay between steps in milliseconds
haefeman 26:caa4fab7023e 12 #define TIME 100
ackerden 16:f0480e9c5039 13
ackerden 16:f0480e9c5039 14
haefeman 26:caa4fab7023e 15 void bewegung(int servo_id){
haefeman 26:caa4fab7023e 16 switch(servo_id) {
haefeman 26:caa4fab7023e 17 case 1:{
haefeman 26:caa4fab7023e 18
haefeman 26:caa4fab7023e 19 Servo servo1(PA_0/*PB_2*/);
haefeman 26:caa4fab7023e 20 servo1.Enable(MID,MAX);
haefeman 20:f825e91784fe 21
haefeman 26:caa4fab7023e 22 //Servo Bewegung
haefeman 26:caa4fab7023e 23 for (int pos = MID; pos > LEFT; pos -= STEP) {
haefeman 26:caa4fab7023e 24 servo1.SetPosition(pos);
haefeman 26:caa4fab7023e 25 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 26 }
haefeman 26:caa4fab7023e 27 for(int j=0; j<2; j++){
haefeman 26:caa4fab7023e 28 for (int pos = LEFT; pos < RIGHT; pos += STEP) {
haefeman 26:caa4fab7023e 29 servo1.SetPosition(pos);
haefeman 26:caa4fab7023e 30 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 31 }
haefeman 26:caa4fab7023e 32 for (int pos = RIGHT; pos > LEFT; pos -= STEP) {
haefeman 26:caa4fab7023e 33 servo1.SetPosition(pos);
haefeman 26:caa4fab7023e 34 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 35 }
haefeman 26:caa4fab7023e 36 }
haefeman 26:caa4fab7023e 37 for (int pos = LEFT; pos < MID; pos += STEP) {
haefeman 20:f825e91784fe 38 servo1.SetPosition(pos);
ackerden 22:f71d32309307 39 thread_sleep_for(TIME);
haefeman 20:f825e91784fe 40 }
haefeman 26:caa4fab7023e 41 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 42 servo1.Disable();
haefeman 26:caa4fab7023e 43 break;
haefeman 26:caa4fab7023e 44 }
haefeman 26:caa4fab7023e 45 case 2:{
haefeman 26:caa4fab7023e 46
haefeman 26:caa4fab7023e 47 Servo servo2(PA_1/*PC_8*/);
haefeman 26:caa4fab7023e 48 servo2.Enable(MID,MAX);
haefeman 26:caa4fab7023e 49
haefeman 26:caa4fab7023e 50 //Servo Bewegung
haefeman 26:caa4fab7023e 51 for (int pos = MID; pos > LEFT; pos -= STEP) {
haefeman 26:caa4fab7023e 52 servo2.SetPosition(pos);
haefeman 26:caa4fab7023e 53 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 54 }
haefeman 26:caa4fab7023e 55 for(int j=0; j<2; j++){
haefeman 26:caa4fab7023e 56 for (int pos = LEFT; pos < RIGHT; pos += STEP) {
haefeman 26:caa4fab7023e 57 servo2.SetPosition(pos);
haefeman 26:caa4fab7023e 58 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 59 }
haefeman 26:caa4fab7023e 60 for (int pos = RIGHT; pos > LEFT; pos -= STEP) {
haefeman 26:caa4fab7023e 61 servo2.SetPosition(pos);
haefeman 26:caa4fab7023e 62 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 63 }
haefeman 26:caa4fab7023e 64 }
haefeman 26:caa4fab7023e 65 for (int pos = LEFT; pos < MID; pos += STEP) {
haefeman 26:caa4fab7023e 66 servo2.SetPosition(pos);
ackerden 22:f71d32309307 67 thread_sleep_for(TIME);
haefeman 20:f825e91784fe 68 }
haefeman 26:caa4fab7023e 69 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 70 servo2.Disable();
haefeman 26:caa4fab7023e 71 break;
haefeman 26:caa4fab7023e 72 }
haefeman 26:caa4fab7023e 73 case 3:{
haefeman 26:caa4fab7023e 74
haefeman 26:caa4fab7023e 75 Servo servo3(PA_4/*PC_6*/);
haefeman 26:caa4fab7023e 76 servo3.Enable(MID,MAX);
haefeman 26:caa4fab7023e 77
haefeman 26:caa4fab7023e 78 //Servo Bewegung
haefeman 26:caa4fab7023e 79 for (int pos = MID; pos > LEFT; pos -= STEP) {
haefeman 26:caa4fab7023e 80 servo3.SetPosition(pos);
haefeman 26:caa4fab7023e 81 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 82 }
haefeman 26:caa4fab7023e 83 for(int j=0; j<2; j++){
haefeman 26:caa4fab7023e 84 for (int pos = LEFT; pos < RIGHT; pos += STEP) {
haefeman 26:caa4fab7023e 85 servo3.SetPosition(pos);
haefeman 26:caa4fab7023e 86 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 87 }
haefeman 26:caa4fab7023e 88 for (int pos = RIGHT; pos > LEFT; pos -= STEP) {
haefeman 26:caa4fab7023e 89 servo3.SetPosition(pos);
haefeman 26:caa4fab7023e 90 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 91 }
haefeman 26:caa4fab7023e 92 }
haefeman 26:caa4fab7023e 93 for (int pos = LEFT; pos < MID; pos += STEP) {
haefeman 26:caa4fab7023e 94 servo3.SetPosition(pos);
haefeman 26:caa4fab7023e 95 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 96 }
haefeman 26:caa4fab7023e 97 thread_sleep_for(TIME);
haefeman 26:caa4fab7023e 98 servo3.Disable();
haefeman 26:caa4fab7023e 99 break;
haefeman 26:caa4fab7023e 100 }
haefeman 26:caa4fab7023e 101 default:{
haefeman 26:caa4fab7023e 102 printf("servo not found");
haefeman 26:caa4fab7023e 103 break;
haefeman 26:caa4fab7023e 104 }
haefeman 20:f825e91784fe 105 }
ackerden 16:f0480e9c5039 106 }