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.
Diff: main.cpp
- Revision:
- 4:48717b42eab2
- Parent:
- 3:eb9bd4131e95
- Child:
- 5:0cbf491f703d
--- a/main.cpp Thu Apr 26 17:16:54 2018 +0000
+++ b/main.cpp Wed May 02 19:56:10 2018 +0000
@@ -1,15 +1,105 @@
#include "mbed.h"
-DigitalOut step(D7);
-DigitalOut dir(D8);
+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(){
- dir = 1;
-
- while(1){
- step = 1;
- wait(1);
- step = 0;
- wait(1);
- }
+ 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);
+ }
}
\ No newline at end of file