testando

Dependencies:   mbed TextLCD2

main_PM.cpp

Committer:
enricoan
Date:
2020-05-25
Revision:
20:81a44a25b21d
Parent:
19:ebe198368444
Child:
22:dd336b95db5d
Child:
23:1c74f54c9d4a

File content as of revision 20:81a44a25b21d:

//local para inclusão de bibliotecas
#include "mbed.h"
#include "TextLCD.h"
#include "Keypad.h"

//local para a declaração de variáveis
float t_motor = 0.002;
float t_teclado = 0.01;
int hor[] = {12,6,3,9};
int antihor[] = {3,6,12,9};
int parado[] = {0,0,0,0};
char tecla;
float coord_x = 0;
float coord_y = 0;
float coord_z = 0;
int est_x = 0;
int est_y = 0;
int est_z = 0;

//pinos usados pelos botões de fim de curso
DigitalIn fdc_x(PC_10);
DigitalIn fdc_y(PC_11);
DigitalIn fdc_z(PC_12);

//botões para movimentação eixo a eixo
DigitalIn x_mais(PA_0);
DigitalIn x_menos(PA_1);
DigitalIn y_mais(PC_0);
DigitalIn y_menos(PC_1);
DigitalIn z_mais(PC_2);
DigitalIn z_menos(PC_3);

//pinos da placa usados na biblioteca do LCD
TextLCD lcd(D4, D5, D6, D7, D8, D9); 

//pinos do teclado
Keypad teclado(PA_6, PA_7, PB_6, PC_7, PB_7, PC_13, PC_14, PC_15);

//pinos de saída para os motores
//eixo x
BusOut eixox(PA_15,PA_14,PA_13,PA_12);
//eixo y
BusOut eixoy(PA_11,PA_10,PB_2,PB_1);
//eixo z
BusOut eixoz(PC_9,PC_8,PB_8,PC_6);

int main() {
    printf("\n%i",est_x);
    printf("\n%i",est_y);
    printf("\n%i",est_z);
    lcd.printf("Bem-vindo ao Pipemax");
    lcd.locate(0,1);
    lcd.printf("o seu sistema");
    lcd.locate(0,2);
    lcd.printf("automatizado");
    lcd.locate(0,3);
    lcd.printf("de pipetagem");
    while (fdc_x != 0){for(int i = 0; i < 4; i++){eixox = hor[i];wait(t_motor);est_x = 1;}}
    while (fdc_y != 0){for(int i = 0; i < 4; i++){eixoy = hor[i];wait(t_motor);est_y = 1;}}
    while (fdc_z != 0){for(int i = 0; i < 4; i++){eixoz = hor[i];wait(t_motor);est_z = 1;}}
    printf("\n%i",est_x);
    printf("\n%i",est_y);
    printf("\n%i",est_z);
    while(1) {
         int solta = 1;
         tecla = teclado.ReadKey();               //read the current key pressed
         if(tecla == '\0') solta = 1;             //set the flag when all keys are released
         if((tecla != '\0') && (solta == 1)) {    //if a key is pressed AND previous key was released
             printf("%c\n", tecla);
             solta = 0;                           //clear the flag to indicate that key is still pressed
             wait(0.1);}
             /* tentativa de fazer o motor parar ao apertar algum dos fins de curso
        if(fdc_x == 0 || fdc_y == 0 || fdc_z == 0){
            for(int i = 0; i < 4; i++){eixox = parado[i];wait(t_motor);est_x = 1;}
            for(int i = 0; i < 4; i++){eixoy = parado[i];wait(t_motor);est_y = 1;}
            for(int i = 0; i < 4; i++){eixoz = parado[i];wait(t_motor);est_z = 1;}
             */
        if (x_mais == 0 && est_x == 1){for(int i = 0; i < 4; i++){eixox = parado[i];wait(t_motor);coord_x += 0;lcd.cls();lcd.printf("Limite de x atingido");}}
        if (y_mais == 0 && est_y == 1){for(int i = 0; i < 4; i++){eixoy = parado[i];wait(t_motor);coord_y += 0;lcd.cls();lcd.printf("Limite de y atingido");}}
        if (z_mais == 0 && est_z == 1){for(int i = 0; i < 4; i++){eixoz = parado[i];wait(t_motor);coord_z += 0;lcd.cls();lcd.printf("Limite de z atingido");}}
                
        if (x_menos == 0){for(int i = 0; i < 4; i++){eixox = antihor[i];wait(t_motor);coord_x -= (5.625*5/32)/360;est_x = 0;
            lcd.cls();
            lcd.printf("X: %4.1f", coord_x);
            lcd.locate(0,1);
            lcd.printf("Y: %4.1f", coord_y);
            lcd.locate(0,2);
            lcd.printf("Z: %4.1f", coord_z);}}
        if (y_menos == 0){for(int i = 0; i < 4; i++){eixoy = antihor[i];wait(t_motor);coord_y -= (5.625*5/32)/360;est_y = 0;
            lcd.cls();
            lcd.printf("X: %4.1f", coord_x);
            lcd.locate(0,1);
            lcd.printf("Y: %4.1f", coord_y);
            lcd.locate(0,2);
            lcd.printf("Z: %4.1f", coord_z);}}  
        if (z_menos == 0){for(int i = 0; i < 4; i++){eixoz = antihor[i];wait(t_motor);coord_z -= (5.625*5/32)/360;est_z = 0;
            lcd.cls();
            lcd.printf("X: %4.1f", coord_x);
            lcd.locate(0,1);
            lcd.printf("Y: %4.1f", coord_y);
            lcd.locate(0,2);
            lcd.printf("Z: %4.1f", coord_z);}}

        if (x_mais == 0){for(int i = 0; i < 4; i++){eixox = hor[i];wait(t_motor);coord_x += (5.625*5/32)/360;est_x = 0;
            lcd.cls();
            lcd.printf("X: %4.1f", coord_x);
            lcd.locate(0,1);
            lcd.printf("Y: %4.1f", coord_y);
            lcd.locate(0,2);
            lcd.printf("Z: %4.1f", coord_z);}}      
        if (y_mais == 0){for(int i = 0; i < 4; i++){eixoy = hor[i];wait(t_motor);coord_y += (5.625*5/32)/360;est_y = 0;
            lcd.cls();
            lcd.printf("X: %4.1f", coord_x);
            lcd.locate(0,1);
            lcd.printf("Y: %4.1f", coord_y);
            lcd.locate(0,2);
            lcd.printf("Z: %4.1f", coord_z);}}
        if (z_mais == 0){for(int i = 0; i < 4; i++){eixoz = hor[i];wait(t_motor);coord_z += (5.625*5/32)/360;est_z = 0;
            lcd.cls();
            lcd.printf("X: %4.1f", coord_x);
            lcd.locate(0,1);
            lcd.printf("Y: %4.1f", coord_y);
            lcd.locate(0,2);
            lcd.printf("Z: %4.1f", coord_z);}}

        if (x_mais || x_menos || y_mais || y_menos || z_mais || z_menos != 0){
            for(int i = 0; i < 4; i++){eixox = parado[i];}
            for(int i = 0; i < 4; i++){eixoy = parado[i];}
            for(int i = 0; i < 4; i++){eixoz = parado[i];}
            }
        
        /*
        lcd.cls();
        lcd.printf("X: %4.1f", coord_x);
        lcd.locate(0,1);
        lcd.printf("Y: %4.1f", coord_y);
        lcd.locate(0,2);
        lcd.printf("Z: %4.1f", coord_z);
        */
        
    }
}