GroupA / Mbed 2 deprecated WaG_final

Dependencies:   mbed

Fork of Lab_6_WaG by GroupA

Committer:
spm71
Date:
Thu Mar 08 17:16:18 2018 +0000
Revision:
22:09dd6977576b
Parent:
21:88f9f280931b
Child:
23:3da1d39c1ae9
Final code rework

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spm71 0:ee6e5c60dd2d 1 /******************************************************************************
spm71 0:ee6e5c60dd2d 2 * EECS 397
spm71 0:ee6e5c60dd2d 3 *
spm71 18:0e281922212c 4 * Assignment Name: Lab 5: WaG
spm71 0:ee6e5c60dd2d 5 *
spm71 0:ee6e5c60dd2d 6 * Authors: Sam Morrison and Phong Nguyen
phn10 16:dfa9eb1a808d 7 * File name: main.cpp
spm71 22:09dd6977576b 8 * Purpose: Configures the dispaly for 4-digit display or motor control
spm71 0:ee6e5c60dd2d 9 *
spm71 18:0e281922212c 10 * Created: 03/01/2018
spm71 22:09dd6977576b 11 * Last Modified: 03/08/2018
spm71 0:ee6e5c60dd2d 12 *
spm71 0:ee6e5c60dd2d 13 ******************************************************************************/
spm71 0:ee6e5c60dd2d 14 #include "mbed.h"
phn10 8:d8bc78bda829 15 #include "io_pins.h"
phn10 8:d8bc78bda829 16 #include "display.h"
spm71 20:d23bcd97f2c5 17 #include "spi.h"
spm71 20:d23bcd97f2c5 18 #include "stepper.h"
spm71 0:ee6e5c60dd2d 19 #include <stdlib.h>
spm71 0:ee6e5c60dd2d 20 #include <stdio.h>
spm71 0:ee6e5c60dd2d 21 #include <string.h>
spm71 0:ee6e5c60dd2d 22
spm71 18:0e281922212c 23 SPI wag_spi(MOSI, MISO, SCLK);
spm71 0:ee6e5c60dd2d 24 Serial pc(USBTX, USBRX);
spm71 21:88f9f280931b 25 DigitalIn jog_cw(PF_14);
spm71 22:09dd6977576b 26 DigitalIn jog_ccw(PE_13);
spm71 0:ee6e5c60dd2d 27
spm71 20:d23bcd97f2c5 28 struct spi_cfg as1107{
spm71 20:d23bcd97f2c5 29 SPI_AS1107_ID,
spm71 20:d23bcd97f2c5 30 DSP_AS1107_NCS,
spm71 20:d23bcd97f2c5 31 SPI_NO_ID,
spm71 20:d23bcd97f2c5 32 AS1107_SPI_FREQ,
spm71 20:d23bcd97f2c5 33 AS1107_SPI_NO_BITS,
spm71 20:d23bcd97f2c5 34 };
spm71 20:d23bcd97f2c5 35
spm71 22:09dd6977576b 36
spm71 0:ee6e5c60dd2d 37 int main(void) {
spm71 20:d23bcd97f2c5 38 initial_setup(as1107);
phn10 11:6751b9406142 39 char bcd[4];
spm71 20:d23bcd97f2c5 40 char input;
spm71 20:d23bcd97f2c5 41 int display_number;
spm71 20:d23bcd97f2c5 42
spm71 20:d23bcd97f2c5 43 pc.printf("Enter 1 for display test, 2 for stepper test\n");
spm71 20:d23bcd97f2c5 44 input = getchar();
spm71 20:d23bcd97f2c5 45 while (input < 49 or input > 50) { //ask for input until 0-9 is selected
spm71 20:d23bcd97f2c5 46 pc.printf("Enter 1 for display test, 2 for stepper test\n");
spm71 20:d23bcd97f2c5 47 input = getchar();
spm71 20:d23bcd97f2c5 48 }
spm71 20:d23bcd97f2c5 49
spm71 20:d23bcd97f2c5 50 if (input == 49) {
spm71 20:d23bcd97f2c5 51 while(1) { //clears bcd array
spm71 20:d23bcd97f2c5 52 for (int i = 0; i < 4; i++)
spm71 20:d23bcd97f2c5 53 bcd[i] = 0;
spm71 20:d23bcd97f2c5 54 display_number = 0;
spm71 20:d23bcd97f2c5 55 pc.printf("Select a digit between 0 and 9999:\n");
spm71 20:d23bcd97f2c5 56 pc.scanf("%d", &display_number);
phn10 11:6751b9406142 57
spm71 20:d23bcd97f2c5 58 while (display_number < 0 or display_number > 9999) { //ask for input until 0-9999 is selected
spm71 20:d23bcd97f2c5 59 pc.printf("You entered a number out of range\n");
spm71 20:d23bcd97f2c5 60 pc.printf("Select a digit between 0 and 9999:\n");
spm71 20:d23bcd97f2c5 61 display_number = 0;
spm71 20:d23bcd97f2c5 62 pc.scanf("%d", &display_number);
spm71 20:d23bcd97f2c5 63 }
spm71 2:b444464ebe67 64
spm71 14:be27f6e21a8a 65
spm71 20:d23bcd97f2c5 66 printf("you entered: %d\n", display_number);
spm71 20:d23bcd97f2c5 67 bin2bcd_array(display_number, bcd);
spm71 0:ee6e5c60dd2d 68
spm71 20:d23bcd97f2c5 69 send_command_to_display(bcd);
spm71 20:d23bcd97f2c5 70 }
spm71 20:d23bcd97f2c5 71 }
spm71 20:d23bcd97f2c5 72 else {
spm71 20:d23bcd97f2c5 73 jog_cw.mode(PullUp);
spm71 20:d23bcd97f2c5 74 jog_ccw.mode(PullUp);
spm71 22:09dd6977576b 75 stp_step(1);
spm71 20:d23bcd97f2c5 76 pc.printf("Press a pushbutton to turn step motor\n");
spm71 20:d23bcd97f2c5 77 while(1) {
spm71 20:d23bcd97f2c5 78 if (jog_ccw == 0) {
spm71 22:09dd6977576b 79 //pc.printf("turning CCW\n");
spm71 20:d23bcd97f2c5 80 stp_step(STP_CCW);
spm71 20:d23bcd97f2c5 81 }
spm71 20:d23bcd97f2c5 82 if (jog_cw == 0) {
spm71 22:09dd6977576b 83 //pc.printf("turning CW\n");
spm71 20:d23bcd97f2c5 84 stp_step(STP_CW);
spm71 20:d23bcd97f2c5 85 }
spm71 20:d23bcd97f2c5 86 }
spm71 0:ee6e5c60dd2d 87 }
phn10 7:161fe3793ddb 88 }