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-13
- Revision:
- 3:ce5c55c100b1
- Child:
- 4:c3007ca446ec
File content as of revision 3:ce5c55c100b1:
#include "mbed.h"
Serial pc (USBTX, USBRX);
AnalogIn eixo_X(A0);
AnalogIn eixo_Y(A1);
InterruptIn botao_in(PA_8);
BusOut motor_x(PA_9, PC_7, PB_6, PA_7);
BusOut motor_y(PA_11, PB_12, PB_11, PB_2);
double frequencia; //Hz
double velocidade = 4; //RPM
double tempo; //Segundos
int i;
int X;
int Y;
int botao_estado;
bool rotacao;
void posicao_de_pega(void);
int main()
{
motor_x = 0x00;
motor_y = 0x00;
pc.baud(115200);
rotacao = 0;
botao_in.rise(&posicao_de_pega);
frequencia = (2048*velocidade)/60;
tempo = (1/frequencia);
while(1) {
X = eixo_X.read_u16();
Y = eixo_Y.read_u16();
botao_estado = botao_in.read();
pc.printf("X=%4d, Y=%4d, botao_estado=%d, rotacao_estado=%d \r\n", X, Y, botao_estado, rotacao);
if(31000 <= X & X <= 35000) {
motor_x = 0x00;
} else {
if (X > 31000) {
for(i = 0; i < 4; i++) {
motor_x = 1 << i;
wait(tempo);
}
}
if(X<35000) {
for(i = 3; i > -1; i--) {
motor_x = 1 << i;
wait(tempo);
}
}
}
if(31000 <= Y & Y <= 35000) {
motor_y = 0x00;
}
else {
if (rotacao == 0) {
for(i = 0; i < 4; i++) {
motor_y = 1 << i;
wait(tempo);
}
}
if(rotacao == 1) {
for(i = 3; i > -1; i--) {
motor_y = 1 << i;
wait(tempo);
}
}
}
}
}
void posicao_de_pega()
{
if(botao_estado == 0) rotacao = !rotacao;
}