Dydaktyka
Dependencies: FastPWM mbed-src
Fork of 2015_04_17_quadro_bez_sterowania by
Diff: main.cpp
- Revision:
- 4:a5b51a651db7
- Parent:
- 3:1425359662e4
- Child:
- 5:c3caf8b83e6b
--- a/main.cpp Thu Dec 18 09:13:10 2014 +0000 +++ b/main.cpp Fri Dec 19 12:13:43 2014 +0000 @@ -16,20 +16,152 @@ */ FastPWM motor1(D10); +Serial pc(USBTX, USBRX); +Serial bluetooth(D1, D0); + +char znak; +char znak2; +double i; +char buff[60]; + int main() { - + pc.baud(115200); + bluetooth.baud(19200); - motor1.period(PWM_period); - motor1.pulsewidth(valPWM1); + sprintf(buff, "Hello: \n\r"); + pc.printf(buff); + + motor1.period_us(PWM_period); + motor1.pulsewidth_us(valPWM1); /* motor1.period_us(PWM_period); motor2.period_us(PWM_period); motor3.period_us(PWM_period); motor4.period_us(PWM_period); */ + i=1000; + while(1) { - + + + if(pc.readable()){ + + znak=pc.getc(); + + switch (znak){ + case 'p': + sprintf(buff, "odczytany znak: %c\n\r",znak); + pc.printf(buff); + + i+=10; + break; + + case 'm': + i-=10; + break; + + case 'u': + i+=0.1; + break; + + case 'd': + i-=0.1; + break; + + + case 'q': + for(i=1000;i<1500;i++){ + motor1.pulsewidth_us(i); + wait(0.005); + } + break; + + case 'w': + for(i=1500;i>1000;i--){ + motor1.pulsewidth_us(i); + wait(0.005); + } + break; + case 'e': + for(i=1000;i<1500;i=i+0.1){ + motor1.pulsewidth_us(i); + wait(0.001); + } + break; + case 'r': + for(i=1500;i>1000;i-=0.1){ + motor1.pulsewidth_us(i); + wait(0.001); + } + break; + } + + + motor1.pulsewidth_us(i); + } + + + + + + if(bluetooth.readable()){ + + znak2=bluetooth.getc(); + sprintf(buff, "Odczytany znak: %c\n\r",znak2); + pc.printf(buff); + + /*switch (znak2){ + case 'a': + sprintf(buff, "odczytany znak: %c\n\r",znak2); + pc.printf(buff); + break; + + case 'b': + sprintf(buff, "odczytany znak: %c\n\r",znak2); + pc.printf(buff); + break; + + case 'u': + i+=0.1; + break; + + case 'd': + i-=0.1; + break; + + + case 'q': + for(i=1000;i<1500;i++){ + motor1.pulsewidth_us(i); + wait(0.005); + } + break; + + case 'w': + for(i=1500;i>1000;i--){ + motor1.pulsewidth_us(i); + wait(0.005); + } + break; + case 'e': + for(i=1000;i<1500;i=i+0.1){ + motor1.pulsewidth_us(i); + wait(0.001); + } + break; + case 'r': + for(i=1500;i>1000;i-=0.1){ + motor1.pulsewidth_us(i); + wait(0.001); + } + break; + }*/ + + + //motor1.pulsewidth_us(i); + } + /* for (int i = 1000; i < 1500;i++) {