Board2

Dependencies:   mbed

Revision:
0:a2b61e577da7
Child:
1:3817c83cef51
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Mar 27 14:11:01 2019 +0000
@@ -0,0 +1,69 @@
+#include "mbed.h"
+#include <SPISlave.h>
+
+#define LOW = 0;
+#define HIGH = 1;
+Serial pc(USBTX, USBRX);
+
+SPISlave slave(PA_7, PA_6, PA_5, PA_15); //MOSI MISO CLK CS
+
+DigitalIn prox1(PA_14);
+
+struct stepper1{
+    DigitalOut PUL(PC_1); 
+    DigitalOut DR(PC_0); 
+}
+
+//DigitalOut PUL(PC_1); 
+//DigitalOut DR(PC_0);    //LOW=up, HIGH=down 
+
+bool start = false;
+int position = 0;
+char inputPos = 0;
+
+void drvStepper1(int step){
+    if(step >= 0){
+        for(char i=0; i<step; i++){
+            DR.stepper1 = 1;
+            PUL.stepper1 = 1;
+            wait_ms(1);
+            PUL.stepper1 = 0;
+            wait_ms(1);
+        }
+    }
+    else if(step < 0){
+        step = (-1)*step;
+        for(char i=0; i<step; i++){
+            DR.stepper1 = 0;
+            PUL.stepper1 = 1;
+            wait_ms(1);
+            PUL.stepper1 = 0;
+            wait_ms(1);
+        }
+    }
+}
+
+int main() {
+      pc.baud(9600);
+      slave.format(8,3);
+      slave.frequency(1000000);
+      slave.reply(0x00);              // Prime SPI with first reply
+    while(1) {
+        if(slave.receive()){
+            int data = slave.read();
+            if(data == 123){
+                slave1.reply(0x42); //send 'B'
+                start = true;
+            }
+        }
+        if(start == true){
+            if(prox1 == 0){
+                PUL.stepper1 = LOW;
+                wait_ms(1);
+            }
+            else{
+                drvStepper1(100);
+            }
+        }
+   }
+}