Dydaktyka

Dependencies:   FastPWM mbed-src

Fork of 2015_04_17_quadro_bez_sterowania by Quadrocopter

main.cpp

Committer:
Michu90
Date:
2014-12-19
Revision:
4:a5b51a651db7
Parent:
3:1425359662e4
Child:
5:c3caf8b83e6b

File content as of revision 4:a5b51a651db7:

#include "mbed.h"
#include "FastPWM.h"
#define PWM_period 2500


int valPWM1 = 1000;
int valPWM2 = 1000;
int valPWM3 = 1000;
int valPWM4 = 1000;

/*
PwmOut motor1 (D10);
PwmOut motor2 (D11);
PwmOut motor3 (D12);
PwmOut motor4 (D13);
*/
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);
    
    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++)
     {
     
     valPWM1 = i;
     valPWM3 = i;
     valPWM2 = 2500 - i;
     valPWM4 = 2500 - i;
     
    motor1.pulsewidth_ms(valPWM1); 
    motor2.pulsewidth_ms(valPWM2); 
    motor3.pulsewidth_ms(valPWM3); 
    motor4.pulsewidth_ms(valPWM4); 
       }*/
       
    }
}