GroupA / Mbed 2 deprecated WaG_final

Dependencies:   mbed

Fork of Lab_6_WaG by GroupA

Revision:
1:1b05289d0bf5
Parent:
0:ee6e5c60dd2d
Child:
2:b444464ebe67
--- a/main.cpp	Tue Feb 20 16:39:34 2018 +0000
+++ b/main.cpp	Tue Feb 20 17:17:55 2018 +0000
@@ -20,6 +20,9 @@
 SPI spi(PA_7, PA_6, PA_5);
 Serial pc(USBTX, USBRX);
 
+bool num_range(char input[5]);
+char to_command(char input, int place);
+
 int main(void) {
     SS = 1; 
     
@@ -66,34 +69,53 @@
     spi.write(0x0500); //set digit 5 to 0
     
     float command = 0x0100;
-    char input[4];
-    char command_text[10] = "0x0";
+    char input[5];
+    //char command_text[10] = "0x0";
     while(1) {
         pc.printf("Select a digit between 0 and 9999:\n");
-        input = getchar();
-        while (input < 48 or input > 57) { //ask for input until 0-9 is selected
+        scanf("%5s", input);
+        while (num_range(input) == false) { //ask for input until 0-9999 is selected
             pc.printf("Select a digit between 0 and 9999:\n");
-            scanf("%d", &input);
+            scanf("%5s", input);
         }
         
+        /*
         command_text[3] = place + '0';
         command_text[4] = '0';
         command_text[5] = input;
         
         command = atof(command_text); //converts string to float
+        */
         
         pc.printf("command: %s\n", command_text);
         
         
         SS = 0;
-        spi.write(command);
+        spi.write(command); // need to cycle 4 times
         SS = 1;
         //pc.printf("command: &f\n", commmand);
     }
+    
     /*
     SS = 0;
     spi.write(0x0100); //set digit 0 to 0
     SS = 1;
     */
 }
+
+bool num_range(char input[5]) {
+     bool result = true;
+     for (int i = 1; i < 6; i++) {
+        if (i > 4)
+            if (input[i] != 0) //checks for number larger than 9999
+                result = false; 
+        if (input[i] < 48 or input[i] > 57) //checks for digits outside 0-9
+            result = false;
+     }
+     return result;
+}
+
+char to_command(char input, int place) {
+    
+}
     
\ No newline at end of file