Dydaktyka

Dependencies:   FastPWM mbed-src

Fork of 2015_04_17_quadro_bez_sterowania by Quadrocopter

Committer:
Michu90
Date:
Fri Dec 19 12:13:43 2014 +0000
Revision:
4:a5b51a651db7
Parent:
3:1425359662e4
Child:
5:c3caf8b83e6b
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:50d2b9c62765 1 #include "mbed.h"
Igor_W 3:1425359662e4 2 #include "FastPWM.h"
Igor_W 2:9e6ed6302c78 3 #define PWM_period 2500
Igor_W 2:9e6ed6302c78 4
Igor_W 2:9e6ed6302c78 5
Igor_W 2:9e6ed6302c78 6 int valPWM1 = 1000;
Igor_W 2:9e6ed6302c78 7 int valPWM2 = 1000;
Igor_W 2:9e6ed6302c78 8 int valPWM3 = 1000;
Igor_W 2:9e6ed6302c78 9 int valPWM4 = 1000;
Igor_W 2:9e6ed6302c78 10
Igor_W 3:1425359662e4 11 /*
Igor_W 2:9e6ed6302c78 12 PwmOut motor1 (D10);
Igor_W 2:9e6ed6302c78 13 PwmOut motor2 (D11);
Igor_W 2:9e6ed6302c78 14 PwmOut motor3 (D12);
Igor_W 2:9e6ed6302c78 15 PwmOut motor4 (D13);
Igor_W 3:1425359662e4 16 */
Igor_W 3:1425359662e4 17 FastPWM motor1(D10);
mbedAustin 1:5160ea45399b 18
Michu90 4:a5b51a651db7 19 Serial pc(USBTX, USBRX);
Michu90 4:a5b51a651db7 20 Serial bluetooth(D1, D0);
Michu90 4:a5b51a651db7 21
Michu90 4:a5b51a651db7 22 char znak;
Michu90 4:a5b51a651db7 23 char znak2;
Michu90 4:a5b51a651db7 24 double i;
Michu90 4:a5b51a651db7 25 char buff[60];
Michu90 4:a5b51a651db7 26
mbed_official 0:50d2b9c62765 27 int main() {
Igor_W 2:9e6ed6302c78 28
Michu90 4:a5b51a651db7 29 pc.baud(115200);
Michu90 4:a5b51a651db7 30 bluetooth.baud(19200);
Igor_W 3:1425359662e4 31
Michu90 4:a5b51a651db7 32 sprintf(buff, "Hello: \n\r");
Michu90 4:a5b51a651db7 33 pc.printf(buff);
Michu90 4:a5b51a651db7 34
Michu90 4:a5b51a651db7 35 motor1.period_us(PWM_period);
Michu90 4:a5b51a651db7 36 motor1.pulsewidth_us(valPWM1);
Igor_W 3:1425359662e4 37
Igor_W 3:1425359662e4 38 /* motor1.period_us(PWM_period);
Igor_W 2:9e6ed6302c78 39 motor2.period_us(PWM_period);
Igor_W 2:9e6ed6302c78 40 motor3.period_us(PWM_period);
Igor_W 2:9e6ed6302c78 41 motor4.period_us(PWM_period);
Igor_W 3:1425359662e4 42 */
Michu90 4:a5b51a651db7 43 i=1000;
Michu90 4:a5b51a651db7 44
Igor_W 2:9e6ed6302c78 45 while(1) {
Michu90 4:a5b51a651db7 46
Michu90 4:a5b51a651db7 47
Michu90 4:a5b51a651db7 48 if(pc.readable()){
Michu90 4:a5b51a651db7 49
Michu90 4:a5b51a651db7 50 znak=pc.getc();
Michu90 4:a5b51a651db7 51
Michu90 4:a5b51a651db7 52 switch (znak){
Michu90 4:a5b51a651db7 53 case 'p':
Michu90 4:a5b51a651db7 54 sprintf(buff, "odczytany znak: %c\n\r",znak);
Michu90 4:a5b51a651db7 55 pc.printf(buff);
Michu90 4:a5b51a651db7 56
Michu90 4:a5b51a651db7 57 i+=10;
Michu90 4:a5b51a651db7 58 break;
Michu90 4:a5b51a651db7 59
Michu90 4:a5b51a651db7 60 case 'm':
Michu90 4:a5b51a651db7 61 i-=10;
Michu90 4:a5b51a651db7 62 break;
Michu90 4:a5b51a651db7 63
Michu90 4:a5b51a651db7 64 case 'u':
Michu90 4:a5b51a651db7 65 i+=0.1;
Michu90 4:a5b51a651db7 66 break;
Michu90 4:a5b51a651db7 67
Michu90 4:a5b51a651db7 68 case 'd':
Michu90 4:a5b51a651db7 69 i-=0.1;
Michu90 4:a5b51a651db7 70 break;
Michu90 4:a5b51a651db7 71
Michu90 4:a5b51a651db7 72
Michu90 4:a5b51a651db7 73 case 'q':
Michu90 4:a5b51a651db7 74 for(i=1000;i<1500;i++){
Michu90 4:a5b51a651db7 75 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 76 wait(0.005);
Michu90 4:a5b51a651db7 77 }
Michu90 4:a5b51a651db7 78 break;
Michu90 4:a5b51a651db7 79
Michu90 4:a5b51a651db7 80 case 'w':
Michu90 4:a5b51a651db7 81 for(i=1500;i>1000;i--){
Michu90 4:a5b51a651db7 82 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 83 wait(0.005);
Michu90 4:a5b51a651db7 84 }
Michu90 4:a5b51a651db7 85 break;
Michu90 4:a5b51a651db7 86 case 'e':
Michu90 4:a5b51a651db7 87 for(i=1000;i<1500;i=i+0.1){
Michu90 4:a5b51a651db7 88 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 89 wait(0.001);
Michu90 4:a5b51a651db7 90 }
Michu90 4:a5b51a651db7 91 break;
Michu90 4:a5b51a651db7 92 case 'r':
Michu90 4:a5b51a651db7 93 for(i=1500;i>1000;i-=0.1){
Michu90 4:a5b51a651db7 94 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 95 wait(0.001);
Michu90 4:a5b51a651db7 96 }
Michu90 4:a5b51a651db7 97 break;
Michu90 4:a5b51a651db7 98 }
Michu90 4:a5b51a651db7 99
Michu90 4:a5b51a651db7 100
Michu90 4:a5b51a651db7 101 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 102 }
Michu90 4:a5b51a651db7 103
Michu90 4:a5b51a651db7 104
Michu90 4:a5b51a651db7 105
Michu90 4:a5b51a651db7 106
Michu90 4:a5b51a651db7 107
Michu90 4:a5b51a651db7 108 if(bluetooth.readable()){
Michu90 4:a5b51a651db7 109
Michu90 4:a5b51a651db7 110 znak2=bluetooth.getc();
Michu90 4:a5b51a651db7 111 sprintf(buff, "Odczytany znak: %c\n\r",znak2);
Michu90 4:a5b51a651db7 112 pc.printf(buff);
Michu90 4:a5b51a651db7 113
Michu90 4:a5b51a651db7 114 /*switch (znak2){
Michu90 4:a5b51a651db7 115 case 'a':
Michu90 4:a5b51a651db7 116 sprintf(buff, "odczytany znak: %c\n\r",znak2);
Michu90 4:a5b51a651db7 117 pc.printf(buff);
Michu90 4:a5b51a651db7 118 break;
Michu90 4:a5b51a651db7 119
Michu90 4:a5b51a651db7 120 case 'b':
Michu90 4:a5b51a651db7 121 sprintf(buff, "odczytany znak: %c\n\r",znak2);
Michu90 4:a5b51a651db7 122 pc.printf(buff);
Michu90 4:a5b51a651db7 123 break;
Michu90 4:a5b51a651db7 124
Michu90 4:a5b51a651db7 125 case 'u':
Michu90 4:a5b51a651db7 126 i+=0.1;
Michu90 4:a5b51a651db7 127 break;
Michu90 4:a5b51a651db7 128
Michu90 4:a5b51a651db7 129 case 'd':
Michu90 4:a5b51a651db7 130 i-=0.1;
Michu90 4:a5b51a651db7 131 break;
Michu90 4:a5b51a651db7 132
Michu90 4:a5b51a651db7 133
Michu90 4:a5b51a651db7 134 case 'q':
Michu90 4:a5b51a651db7 135 for(i=1000;i<1500;i++){
Michu90 4:a5b51a651db7 136 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 137 wait(0.005);
Michu90 4:a5b51a651db7 138 }
Michu90 4:a5b51a651db7 139 break;
Michu90 4:a5b51a651db7 140
Michu90 4:a5b51a651db7 141 case 'w':
Michu90 4:a5b51a651db7 142 for(i=1500;i>1000;i--){
Michu90 4:a5b51a651db7 143 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 144 wait(0.005);
Michu90 4:a5b51a651db7 145 }
Michu90 4:a5b51a651db7 146 break;
Michu90 4:a5b51a651db7 147 case 'e':
Michu90 4:a5b51a651db7 148 for(i=1000;i<1500;i=i+0.1){
Michu90 4:a5b51a651db7 149 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 150 wait(0.001);
Michu90 4:a5b51a651db7 151 }
Michu90 4:a5b51a651db7 152 break;
Michu90 4:a5b51a651db7 153 case 'r':
Michu90 4:a5b51a651db7 154 for(i=1500;i>1000;i-=0.1){
Michu90 4:a5b51a651db7 155 motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 156 wait(0.001);
Michu90 4:a5b51a651db7 157 }
Michu90 4:a5b51a651db7 158 break;
Michu90 4:a5b51a651db7 159 }*/
Michu90 4:a5b51a651db7 160
Michu90 4:a5b51a651db7 161
Michu90 4:a5b51a651db7 162 //motor1.pulsewidth_us(i);
Michu90 4:a5b51a651db7 163 }
Michu90 4:a5b51a651db7 164
Igor_W 3:1425359662e4 165 /* for (int i = 1000; i < 1500;i++)
Igor_W 2:9e6ed6302c78 166 {
Igor_W 2:9e6ed6302c78 167
Igor_W 2:9e6ed6302c78 168 valPWM1 = i;
Igor_W 2:9e6ed6302c78 169 valPWM3 = i;
Igor_W 2:9e6ed6302c78 170 valPWM2 = 2500 - i;
Igor_W 2:9e6ed6302c78 171 valPWM4 = 2500 - i;
Igor_W 2:9e6ed6302c78 172
Igor_W 2:9e6ed6302c78 173 motor1.pulsewidth_ms(valPWM1);
Igor_W 2:9e6ed6302c78 174 motor2.pulsewidth_ms(valPWM2);
Igor_W 2:9e6ed6302c78 175 motor3.pulsewidth_ms(valPWM3);
Igor_W 2:9e6ed6302c78 176 motor4.pulsewidth_ms(valPWM4);
Igor_W 3:1425359662e4 177 }*/
Igor_W 2:9e6ed6302c78 178
Igor_W 2:9e6ed6302c78 179 }
mbed_official 0:50d2b9c62765 180 }