Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
JOG_EIXO_Z.cpp
- Committer:
- diogonac
- Date:
- 2021-05-14
- Revision:
- 14:2b72dd426da1
- Parent:
- 13:9ee128577854
- Child:
- 15:a0927f239a4c
File content as of revision 14:2b72dd426da1:
#include "mbed.h"
Serial pc (USBTX, USBRX);
AnalogIn eixo_Z(A0);
InterruptIn posicao_salva(PA_8);
InterruptIn botao_emergencia(PB_10);
BusOut motor_z(PB_1, PB_15, PB_14, PB_13);
double tempo; //Segundos
int i;
int Z;
int pegaZ;
int posicao_salva_estado, botao_emergencia_estado;
void rotina_posicao_salva(void);
void rotina_emergencia(void);
void rotida_velocidade_eixo_Z(void);
int main()
{
pc.baud(115200);
motor_z = 0x00;
posicao_salva.rise(&rotina_posicao_salva);
botao_emergencia.rise(&rotina_emergencia);
while(1) {
Z = eixo_Z.read_u16();
posicao_salva_estado = posicao_salva.read();
botao_emergencia_estado = botao_emergencia.read();
rotida_velocidade_eixo_Z();
pc.printf("Z=%4d, PegaZ=%4d, Posicao_salva_estado=%d, Botao_emergencia_estado=%d \r\n", Z, pegaZ, posicao_salva_estado, botao_emergencia_estado);
if(31000 <= Z & Z <= 35000) {
motor_z = 0x00;
} else {
if (Z > 31000) {
for(i = 0; i < 4; i++) {
motor_z = 1 << i;
wait(tempo);
}
}
if(Z < 35000) {
for(i = 3; i > -1; i--) {
motor_z = 1 << i;
wait(tempo);
}
}
}
}
}
void rotina_posicao_salva()
{
if(posicao_salva_estado == 0) pegaZ = Z;
else pegaZ = 0;
}
void rotina_emergencia()
{
if(botao_emergencia_estado == 0) motor_z = 0x00;
}
void rotida_velocidade_eixo_Z()
{
tempo = (Z/65535)*(1/512);
}