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.
main.cpp
- Committer:
- lucasfontenla
- Date:
- 2018-05-02
- Revision:
- 4:48717b42eab2
- Parent:
- 3:eb9bd4131e95
- Child:
- 5:0cbf491f703d
File content as of revision 4:48717b42eab2:
#include "mbed.h"
DigitalOut stepX(D2);
DigitalOut dirX(D3);
DigitalOut stepY(D8);
DigitalOut dirY(D9);
DigitalOut stepZ(D11);
DigitalOut dirZ(D12);
AnalogIn joyX(A0);
AnalogIn joyY(A1);
DigitalIn zUp(D6);
DigitalIn zDwn(D7);
float valX;
float valY;
int valZUp;
int valZDwn;
int activeX = 1;
int activeY = 1;
int activeZ = 1;
int contador = 0;
float pps = 800.0;
float periodo = 1.0/pps;
float tempo = periodo/2.0;
int main(){
printf("Starting...\r\n");
while(1){
valX = joyX;
valY = joyY;
valZUp = zUp;
valZDwn = zDwn;
if(valX > 0.7){
if(dirX){
dirX = 0;
}
activeX = 1;
}
else if(valX < 0.3){
if(!dirX){
dirX = 1;
}
activeX = 1;
}
else{
activeX = 0;
}
//----------------------------------------------------------------------
if(valY > 0.7){
if(!dirY){
dirY = 1;
}
activeY = 1;
}
else if(valY < 0.3){
if(dirY){
dirY = 0;
}
activeY = 1;
}
else{
activeY = 0;
}
//----------------------------------------------------------------------
if(!valZUp && valZDwn){
if(dirZ){
dirZ = 0;
}
activeZ = 1;
}
else if(!valZDwn && valZUp){
if(!dirZ){
dirZ = 1;
}
activeZ = 1;
}
else {
activeZ = 0;
}
//----------------------------------------------------------------------
stepX = activeX;
stepY = activeY;
stepZ = activeZ;
wait(tempo);
stepX = 0;
stepY = 0;
stepZ = 0;
wait(tempo);
}
}