Projeto Mecatrônico
/
LCD_IHM
main.cpp@1:4ba95a6ae582, 2021-05-18 (annotated)
- Committer:
- juan_ruiz
- Date:
- Tue May 18 17:59:46 2021 +0000
- Revision:
- 1:4ba95a6ae582
- Parent:
- 0:4d11c8fe2ef9
- Child:
- 2:2547de0cde50
Juan
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
diogonac | 0:4d11c8fe2ef9 | 1 | #include "mbed.h" |
diogonac | 0:4d11c8fe2ef9 | 2 | #include "TextLCD.h" |
diogonac | 0:4d11c8fe2ef9 | 3 | |
juan_ruiz | 1:4ba95a6ae582 | 4 | Serial pc (USBTX, USBRX); |
juan_ruiz | 1:4ba95a6ae582 | 5 | |
juan_ruiz | 1:4ba95a6ae582 | 6 | TextLCD lcd(D8, D9, D4, D5, D6, D7); |
juan_ruiz | 1:4ba95a6ae582 | 7 | AnalogIn eixo_Z(A0); |
juan_ruiz | 1:4ba95a6ae582 | 8 | InterruptIn posicao_salva(PA_15); |
juan_ruiz | 1:4ba95a6ae582 | 9 | InterruptIn botao_emergencia(PB_10); |
juan_ruiz | 1:4ba95a6ae582 | 10 | |
juan_ruiz | 1:4ba95a6ae582 | 11 | BusOut motor_z(PB_1, PB_15, PB_14, PB_13); |
diogonac | 0:4d11c8fe2ef9 | 12 | |
juan_ruiz | 1:4ba95a6ae582 | 13 | double tempo; //Segundos |
juan_ruiz | 1:4ba95a6ae582 | 14 | int i; |
juan_ruiz | 1:4ba95a6ae582 | 15 | int Z; |
juan_ruiz | 1:4ba95a6ae582 | 16 | int pegaZ; |
juan_ruiz | 1:4ba95a6ae582 | 17 | int posicao_salva_estado, botao_emergencia_estado; |
diogonac | 0:4d11c8fe2ef9 | 18 | |
juan_ruiz | 1:4ba95a6ae582 | 19 | void rotina_posicao_salva(void); |
juan_ruiz | 1:4ba95a6ae582 | 20 | void rotina_emergencia(void); |
juan_ruiz | 1:4ba95a6ae582 | 21 | void rotida_velocidade_eixo_Z(void); |
diogonac | 0:4d11c8fe2ef9 | 22 | |
juan_ruiz | 1:4ba95a6ae582 | 23 | float pos_Z; |
diogonac | 0:4d11c8fe2ef9 | 24 | |
diogonac | 0:4d11c8fe2ef9 | 25 | int main() |
diogonac | 0:4d11c8fe2ef9 | 26 | { |
diogonac | 0:4d11c8fe2ef9 | 27 | |
juan_ruiz | 1:4ba95a6ae582 | 28 | pc.baud(115200); |
juan_ruiz | 1:4ba95a6ae582 | 29 | motor_z = 0x00; |
juan_ruiz | 1:4ba95a6ae582 | 30 | posicao_salva.rise(&rotina_posicao_salva); |
juan_ruiz | 1:4ba95a6ae582 | 31 | botao_emergencia.rise(&rotina_emergencia); |
juan_ruiz | 1:4ba95a6ae582 | 32 | |
diogonac | 0:4d11c8fe2ef9 | 33 | while(1) { |
diogonac | 0:4d11c8fe2ef9 | 34 | |
juan_ruiz | 1:4ba95a6ae582 | 35 | Z = eixo_Z.read_u16(); |
juan_ruiz | 1:4ba95a6ae582 | 36 | posicao_salva_estado = posicao_salva.read(); |
juan_ruiz | 1:4ba95a6ae582 | 37 | botao_emergencia_estado = botao_emergencia.read(); |
juan_ruiz | 1:4ba95a6ae582 | 38 | rotida_velocidade_eixo_Z(); |
juan_ruiz | 1:4ba95a6ae582 | 39 | pc.printf("Z=%4d, PegaZ=%4d, Posicao_salva_estado=%d, Botao_emergencia_estado=%d \r\n", Z, pegaZ, posicao_salva_estado, botao_emergencia_estado); |
juan_ruiz | 1:4ba95a6ae582 | 40 | |
juan_ruiz | 1:4ba95a6ae582 | 41 | if(31000 <= Z & Z <= 35000) { |
juan_ruiz | 1:4ba95a6ae582 | 42 | |
juan_ruiz | 1:4ba95a6ae582 | 43 | motor_z = 0x00; |
juan_ruiz | 1:4ba95a6ae582 | 44 | |
juan_ruiz | 1:4ba95a6ae582 | 45 | } else { |
juan_ruiz | 1:4ba95a6ae582 | 46 | if (Z > 31000) { |
juan_ruiz | 1:4ba95a6ae582 | 47 | for(i = 0; i < 4; i++) { |
juan_ruiz | 1:4ba95a6ae582 | 48 | motor_z = 1 << i; |
juan_ruiz | 1:4ba95a6ae582 | 49 | wait(tempo); |
juan_ruiz | 1:4ba95a6ae582 | 50 | } |
juan_ruiz | 1:4ba95a6ae582 | 51 | } |
juan_ruiz | 1:4ba95a6ae582 | 52 | |
juan_ruiz | 1:4ba95a6ae582 | 53 | if(Z < 35000) { |
juan_ruiz | 1:4ba95a6ae582 | 54 | for(i = 3; i > -1; i--) { |
juan_ruiz | 1:4ba95a6ae582 | 55 | motor_z = 1 << i; |
juan_ruiz | 1:4ba95a6ae582 | 56 | wait(tempo); |
juan_ruiz | 1:4ba95a6ae582 | 57 | } |
juan_ruiz | 1:4ba95a6ae582 | 58 | } |
juan_ruiz | 1:4ba95a6ae582 | 59 | } |
juan_ruiz | 1:4ba95a6ae582 | 60 | |
juan_ruiz | 1:4ba95a6ae582 | 61 | } |
juan_ruiz | 1:4ba95a6ae582 | 62 | } |
juan_ruiz | 1:4ba95a6ae582 | 63 | |
juan_ruiz | 1:4ba95a6ae582 | 64 | |
juan_ruiz | 1:4ba95a6ae582 | 65 | void rotina_posicao_salva() |
juan_ruiz | 1:4ba95a6ae582 | 66 | { |
juan_ruiz | 1:4ba95a6ae582 | 67 | if(posicao_salva_estado == 0) pegaZ = Z; |
juan_ruiz | 1:4ba95a6ae582 | 68 | else pegaZ = 0; |
juan_ruiz | 1:4ba95a6ae582 | 69 | } |
juan_ruiz | 1:4ba95a6ae582 | 70 | |
juan_ruiz | 1:4ba95a6ae582 | 71 | void rotina_emergencia() |
juan_ruiz | 1:4ba95a6ae582 | 72 | { |
juan_ruiz | 1:4ba95a6ae582 | 73 | if(botao_emergencia_estado == 0) motor_z = 0x00; |
juan_ruiz | 1:4ba95a6ae582 | 74 | } |
juan_ruiz | 1:4ba95a6ae582 | 75 | |
juan_ruiz | 1:4ba95a6ae582 | 76 | void rotida_velocidade_eixo_Z() |
juan_ruiz | 1:4ba95a6ae582 | 77 | { |
juan_ruiz | 1:4ba95a6ae582 | 78 | tempo = (Z/65535)*(1/512); |
juan_ruiz | 1:4ba95a6ae582 | 79 | |
juan_ruiz | 1:4ba95a6ae582 | 80 | while(1) { |
juan_ruiz | 1:4ba95a6ae582 | 81 | |
juan_ruiz | 1:4ba95a6ae582 | 82 | pos_Z = eixo_Z; |
diogonac | 0:4d11c8fe2ef9 | 83 | lcd.locate(0,0); |
juan_ruiz | 1:4ba95a6ae582 | 84 | lcd.printf("Posicao Z:"); |
juan_ruiz | 1:4ba95a6ae582 | 85 | lcd.locate(0,1); |
juan_ruiz | 1:4ba95a6ae582 | 86 | lcd.printf("%fmm",pos_Z); |
juan_ruiz | 1:4ba95a6ae582 | 87 | wait(0.5); |
diogonac | 0:4d11c8fe2ef9 | 88 | lcd.cls(); |
diogonac | 0:4d11c8fe2ef9 | 89 | |
diogonac | 0:4d11c8fe2ef9 | 90 | } |
juan_ruiz | 1:4ba95a6ae582 | 91 | |
diogonac | 0:4d11c8fe2ef9 | 92 | } |