Lab 6 code.

Dependencies:   mbed

Fork of WaG by GroupA

Revision:
20:d23bcd97f2c5
Parent:
18:0e281922212c
Child:
21:88f9f280931b
diff -r ad514b1dd53f -r d23bcd97f2c5 main.cpp
--- a/main.cpp	Fri Mar 02 22:20:43 2018 +0000
+++ b/main.cpp	Tue Mar 06 17:25:48 2018 +0000
@@ -14,6 +14,8 @@
 #include "mbed.h"
 #include "io_pins.h"
 #include "display.h"
+#include "spi.h"
+#include "stepper.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -21,32 +23,64 @@
 int data_length = 16;
 int frequency = 1000000;
 
-DigitalOut SS(DSP_AS1107_NCS);
+//DigitalOut SS(DSP_AS1107_NCS);
 SPI wag_spi(MOSI, MISO, SCLK);
 Serial pc(USBTX, USBRX);
 
+struct spi_cfg as1107{
+    SPI_AS1107_ID,
+    DSP_AS1107_NCS,
+    SPI_NO_ID,
+    AS1107_SPI_FREQ,
+    AS1107_SPI_NO_BITS,
+};
+
 int main(void) {
-    initial_setup(SS, data_length, frequency);
+    initial_setup(as1107);
     char bcd[4];
-    int input;
-    while(1) { //clears bcd array
-        for (int i = 0; i < 4; i++)
-            bcd[i] = 0;
-        input = 0;
-        pc.printf("Select a digit between 0 and 9999:\n");
-        pc.scanf("%d", &input);
+    char input;
+    int display_number;
+    
+    pc.printf("Enter 1 for display test, 2 for stepper test\n");
+    input = getchar();
+    while (input < 49 or input > 50) { //ask for input until 0-9 is selected
+        pc.printf("Enter 1 for display test, 2 for stepper test\n");
+        input = getchar();
+    }
+    
+    if (input == 49) {
+        while(1) { //clears bcd array
+            for (int i = 0; i < 4; i++)
+                bcd[i] = 0;
+            display_number = 0;
+            pc.printf("Select a digit between 0 and 9999:\n");
+            pc.scanf("%d", &display_number);
         
-        while (input < 0 or input > 9999) { //ask for input until 0-9999 is selected
-            pc.printf("You entered a number out of range\n");
-            pc.printf("Select a digit between 0 and 9999:\n");
-            input = 0;
-            pc.scanf("%d", &input);
-        }
+            while (display_number < 0 or display_number > 9999) { //ask for input until 0-9999 is selected
+                pc.printf("You entered a number out of range\n");
+                pc.printf("Select a digit between 0 and 9999:\n");
+                display_number = 0;
+                pc.scanf("%d", &display_number);
+            }
         
         
-        printf("you entered: %d\n", input);
-        bin2bcd_array(input, bcd);
+            printf("you entered: %d\n", display_number);
+            bin2bcd_array(display_number, bcd);
         
-        send_command_to_display(bcd);
+            send_command_to_display(bcd);
+        }   
+    }
+    else {
+        jog_cw.mode(PullUp);
+        jog_ccw.mode(PullUp);
+        pc.printf("Press a pushbutton to turn step motor\n");
+        while(1) {
+            if (jog_ccw == 0) {
+                stp_step(STP_CCW);
+            }
+            if (jog_cw == 0) {
+                stp_step(STP_CW);
+            } 
+        }
     }
 }   
\ No newline at end of file