Projeto Mecatrônico
/
ProjetoMecatronico
testando
main_PM.cpp
- Committer:
- enricoan
- Date:
- 2020-05-25
- Revision:
- 13:257302e01c7c
- Parent:
- 10:4f49e9859535
- Child:
- 14:69d8f50c2336
File content as of revision 13:257302e01c7c:
#include "mbed.h" #include "TextLCD.h" #include "Keypad.h" //local para a declaração de pinos e variáveis float t_motor = 0.005; float t_teclado = 0.1; //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 da placa usados na biblioteca 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 DigitalOut a1(PA_15); DigitalOut b1(PA_14); DigitalOut c1(PA_13); DigitalOut d1(PA_12); //eixo y DigitalOut a2(PA_11); DigitalOut b2(PA_10); DigitalOut c2(PB_2); DigitalOut d2(PB_1); //eixo z DigitalOut a3(PC_9); DigitalOut b3(PC_8); DigitalOut c3(PB_8); DigitalOut d3(PC_6); int main() { lcd.printf("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"); char tecla; 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); } if (x_mais == 0){ a1 = 1;b1 = 1;wait(t_motor); a1 = 0;c1 = 1;wait(t_motor); b1 = 0;d1 = 1;wait(t_motor); c1 = 0;a1 = 1;wait(t_motor); d1 = 0;a1 = 0; } if (x_menos == 0){ d1 = 1;c1 = 1;wait(t_motor); d1 = 0;b1 = 1;wait(t_motor); c1 = 0;a1 = 1;wait(t_motor); b1 = 0;d1 = 1;wait(t_motor); a1 = 0;d1 = 0; } if (y_mais == 0){ a2 = 1;b2 = 1;wait(t_motor); a2 = 0;c2 = 1; wait(t_motor); b2 = 0;d2 = 1;wait(t_motor); c2 = 0;a2 = 1;wait(t_motor); d2 = 0;a2 = 0; } if (y_menos == 0){ d2 = 1;c2 = 1;wait(t_motor); d2 = 0;b2 = 1;wait(t_motor); c2 = 0;a2 = 1;wait(t_motor); b2 = 0;d2 = 1;wait(t_motor); a2 = 0;d2 = 0; } if (z_mais == 0){ a3 = 1;b3 = 1;wait(t_motor); a3 = 0;c3 = 1;wait(t_motor); b3 = 0;d3 = 1;wait(t_motor); c3 = 0;a3 = 1;wait(t_motor); d3 = 0;a3 = 0; } if (z_menos == 0){ d3 = 1;c3 = 1;wait(t_motor); d3 = 0;b3 = 1;wait(t_motor); c3 = 0;a3 = 1;wait(t_motor); b3 = 0;d3 = 1;wait(t_motor); a3 = 0;d3 = 0; } } }