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.
Dependencies: mbed
Fork of Lab_6_WaG by
main.cpp@46:85c4b722baa7, 2018-03-30 (annotated)
- Committer:
- spm71
- Date:
- Fri Mar 30 20:25:25 2018 +0000
- Revision:
- 46:85c4b722baa7
- Parent:
- 45:54d18ab80fd1
- Child:
- 49:80d4ffabec16
Part 8
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| spm71 | 0:ee6e5c60dd2d | 1 | /****************************************************************************** |
| spm71 | 0:ee6e5c60dd2d | 2 | * EECS 397 |
| spm71 | 0:ee6e5c60dd2d | 3 | * |
| spm71 | 42:6cba679a4ee4 | 4 | * Assignment Name: Lab 6: 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 | 42:6cba679a4ee4 | 11 | * Last Modified: 03/29/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 | 23:3da1d39c1ae9 | 19 | #include "utility.h" |
| spm71 | 38:57af77435ae1 | 20 | #include "analog.h" |
| spm71 | 42:6cba679a4ee4 | 21 | #include "laser.h" |
| phn10 | 44:4c2ba5bbba67 | 22 | #include "wag.h" |
| spm71 | 0:ee6e5c60dd2d | 23 | #include <stdlib.h> |
| spm71 | 0:ee6e5c60dd2d | 24 | #include <stdio.h> |
| spm71 | 0:ee6e5c60dd2d | 25 | #include <string.h> |
| spm71 | 0:ee6e5c60dd2d | 26 | |
| spm71 | 18:0e281922212c | 27 | SPI wag_spi(MOSI, MISO, SCLK); |
| spm71 | 0:ee6e5c60dd2d | 28 | Serial pc(USBTX, USBRX); |
| spm71 | 25:896dbc85907e | 29 | DigitalIn jog_cw(UI_JOG_RIGHT_BUTTON); |
| spm71 | 25:896dbc85907e | 30 | DigitalIn jog_ccw(UI_JOG_LEFT_BUTTON); |
| spm71 | 23:3da1d39c1ae9 | 31 | DigitalIn my_button(USER_BUTTON); |
| spm71 | 25:896dbc85907e | 32 | DigitalIn start_button(UI_START_BUTTON); |
| spm71 | 25:896dbc85907e | 33 | DigitalIn cal_button(UI_CAL_BUTTON); |
| spm71 | 25:896dbc85907e | 34 | DigitalIn station_select(UI_STATION_SELECT); |
| spm71 | 41:9b293b14b845 | 35 | DigitalIn home_sensor(STP_HOME_SENSOR); |
| spm71 | 42:6cba679a4ee4 | 36 | DigitalOut laser(LZR_ENABLE); |
| phn10 | 32:4fe43fa66ce8 | 37 | AnalogIn mux_out (MUX_OUT); |
| phn10 | 27:3006f5abc0a5 | 38 | BusOut mux_select(MUX_S0, MUX_S1, MUX_S2, MUX_S3); |
| phn10 | 44:4c2ba5bbba67 | 39 | int station = -1; |
| phn10 | 44:4c2ba5bbba67 | 40 | int *cal_status = NOT_CALIBRATED; |
| spm71 | 39:abf211b17e3c | 41 | |
| spm71 | 20:d23bcd97f2c5 | 42 | struct spi_cfg as1107{ |
| spm71 | 39:abf211b17e3c | 43 | SPI_AS1107_ID, |
| spm71 | 39:abf211b17e3c | 44 | DSP_AS1107_NCS, |
| spm71 | 39:abf211b17e3c | 45 | SPI_NO_ID, |
| spm71 | 39:abf211b17e3c | 46 | AS1107_SPI_FREQ, |
| spm71 | 39:abf211b17e3c | 47 | AS1107_SPI_NO_BITS, |
| spm71 | 20:d23bcd97f2c5 | 48 | }; |
| spm71 | 20:d23bcd97f2c5 | 49 | |
| spm71 | 22:09dd6977576b | 50 | |
| spm71 | 0:ee6e5c60dd2d | 51 | int main(void) { |
| spm71 | 20:d23bcd97f2c5 | 52 | initial_setup(as1107); |
| spm71 | 20:d23bcd97f2c5 | 53 | |
| spm71 | 25:896dbc85907e | 54 | //set all digits to zero |
| spm71 | 31:0dc2b4a3eee6 | 55 | spi_send(as1107, 0x0100); |
| spm71 | 31:0dc2b4a3eee6 | 56 | spi_send(as1107, 0x0200); |
| spm71 | 31:0dc2b4a3eee6 | 57 | spi_send(as1107, 0x0300); |
| spm71 | 31:0dc2b4a3eee6 | 58 | spi_send(as1107, 0x0400); |
| spm71 | 25:896dbc85907e | 59 | |
| spm71 | 39:abf211b17e3c | 60 | pc.printf("Press user button to test.\n"); |
| phn10 | 40:4e82369f337c | 61 | |
| spm71 | 46:85c4b722baa7 | 62 | test_target_leds(); |
| spm71 | 46:85c4b722baa7 | 63 | pc.printf("LED's tested\n"); |
| phn10 | 40:4e82369f337c | 64 | |
| spm71 | 46:85c4b722baa7 | 65 | test_phototransistors(); |
| spm71 | 46:85c4b722baa7 | 66 | pc.printf("Phototransistors tested\n"); |
| spm71 | 41:9b293b14b845 | 67 | |
| spm71 | 41:9b293b14b845 | 68 | step_test(); |
| spm71 | 41:9b293b14b845 | 69 | pc.printf("Step motor tested."); |
| spm71 | 42:6cba679a4ee4 | 70 | |
| spm71 | 46:85c4b722baa7 | 71 | pc.printf("laser test\n"); |
| spm71 | 46:85c4b722baa7 | 72 | while(1){ |
| spm71 | 42:6cba679a4ee4 | 73 | lzr_on(); |
| spm71 | 42:6cba679a4ee4 | 74 | wait(0.5); |
| spm71 | 42:6cba679a4ee4 | 75 | lzr_off(); |
| spm71 | 42:6cba679a4ee4 | 76 | wait(0.5); |
| spm71 | 42:6cba679a4ee4 | 77 | } |
| spm71 | 46:85c4b722baa7 | 78 | /* |
| spm71 | 46:85c4b722baa7 | 79 | while (my_button.read() == 0); |
| spm71 | 46:85c4b722baa7 | 80 | pc.printf("test begin\n"); |
| spm71 | 43:3b7f326aa096 | 81 | lzr_init(); |
| spm71 | 46:85c4b722baa7 | 82 | while (my_button.read() == 0) { |
| spm71 | 46:85c4b722baa7 | 83 | lzr_on(); |
| spm71 | 46:85c4b722baa7 | 84 | wait(0.5); |
| spm71 | 46:85c4b722baa7 | 85 | lzr_off(); |
| spm71 | 46:85c4b722baa7 | 86 | wait(0.5); |
| spm71 | 46:85c4b722baa7 | 87 | } |
| spm71 | 46:85c4b722baa7 | 88 | lzr_init(); |
| spm71 | 46:85c4b722baa7 | 89 | */ |
| phn10 | 44:4c2ba5bbba67 | 90 | // determine if the wag is connected to station A or station B |
| phn10 | 44:4c2ba5bbba67 | 91 | station = station_select.read(); |
| spm71 | 39:abf211b17e3c | 92 | } |
