Lab 6 code.
Dependencies: mbed
Fork of WaG by
main.cpp.orig@56:048b30c9f2a1, 2018-04-06 (annotated)
- Committer:
- spm71
- Date:
- Fri Apr 06 18:25:19 2018 +0000
- Revision:
- 56:048b30c9f2a1
- Parent:
- 45:54d18ab80fd1
Final update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phn10 | 45:54d18ab80fd1 | 1 | /****************************************************************************** |
phn10 | 45:54d18ab80fd1 | 2 | * EECS 397 |
phn10 | 45:54d18ab80fd1 | 3 | * |
phn10 | 45:54d18ab80fd1 | 4 | * Assignment Name: Lab 6: WaG |
phn10 | 45:54d18ab80fd1 | 5 | * |
phn10 | 45:54d18ab80fd1 | 6 | * Authors: Sam Morrison and Phong Nguyen |
phn10 | 45:54d18ab80fd1 | 7 | * File name: main.cpp |
phn10 | 45:54d18ab80fd1 | 8 | * Purpose: Configures the dispaly for 4-digit display or motor control |
phn10 | 45:54d18ab80fd1 | 9 | * |
phn10 | 45:54d18ab80fd1 | 10 | * Created: 03/01/2018 |
phn10 | 45:54d18ab80fd1 | 11 | * Last Modified: 03/29/2018 |
phn10 | 45:54d18ab80fd1 | 12 | * |
phn10 | 45:54d18ab80fd1 | 13 | ******************************************************************************/ |
phn10 | 45:54d18ab80fd1 | 14 | #include "mbed.h" |
phn10 | 45:54d18ab80fd1 | 15 | #include "io_pins.h" |
phn10 | 45:54d18ab80fd1 | 16 | #include "display.h" |
phn10 | 45:54d18ab80fd1 | 17 | #include "spi.h" |
phn10 | 45:54d18ab80fd1 | 18 | #include "stepper.h" |
phn10 | 45:54d18ab80fd1 | 19 | #include "utility.h" |
phn10 | 45:54d18ab80fd1 | 20 | #include "analog.h" |
phn10 | 45:54d18ab80fd1 | 21 | #include "laser.h" |
phn10 | 45:54d18ab80fd1 | 22 | #include <stdlib.h> |
phn10 | 45:54d18ab80fd1 | 23 | #include <stdio.h> |
phn10 | 45:54d18ab80fd1 | 24 | #include <string.h> |
phn10 | 45:54d18ab80fd1 | 25 | |
phn10 | 45:54d18ab80fd1 | 26 | SPI wag_spi(MOSI, MISO, SCLK); |
phn10 | 45:54d18ab80fd1 | 27 | Serial pc(USBTX, USBRX); |
phn10 | 45:54d18ab80fd1 | 28 | DigitalIn jog_cw(UI_JOG_RIGHT_BUTTON); |
phn10 | 45:54d18ab80fd1 | 29 | DigitalIn jog_ccw(UI_JOG_LEFT_BUTTON); |
phn10 | 45:54d18ab80fd1 | 30 | DigitalIn my_button(USER_BUTTON); |
phn10 | 45:54d18ab80fd1 | 31 | DigitalIn start_button(UI_START_BUTTON); |
phn10 | 45:54d18ab80fd1 | 32 | DigitalIn cal_button(UI_CAL_BUTTON); |
phn10 | 45:54d18ab80fd1 | 33 | DigitalIn station_select(UI_STATION_SELECT); |
phn10 | 45:54d18ab80fd1 | 34 | DigitalIn home_sensor(STP_HOME_SENSOR); |
phn10 | 45:54d18ab80fd1 | 35 | DigitalOut laser(LZR_ENABLE); |
phn10 | 45:54d18ab80fd1 | 36 | AnalogIn mux_out (MUX_OUT); |
phn10 | 45:54d18ab80fd1 | 37 | BusOut mux_select(MUX_S0, MUX_S1, MUX_S2, MUX_S3); |
phn10 | 45:54d18ab80fd1 | 38 | |
phn10 | 45:54d18ab80fd1 | 39 | |
phn10 | 45:54d18ab80fd1 | 40 | |
phn10 | 45:54d18ab80fd1 | 41 | struct spi_cfg as1107{ |
phn10 | 45:54d18ab80fd1 | 42 | SPI_AS1107_ID, |
phn10 | 45:54d18ab80fd1 | 43 | DSP_AS1107_NCS, |
phn10 | 45:54d18ab80fd1 | 44 | SPI_NO_ID, |
phn10 | 45:54d18ab80fd1 | 45 | AS1107_SPI_FREQ, |
phn10 | 45:54d18ab80fd1 | 46 | AS1107_SPI_NO_BITS, |
phn10 | 45:54d18ab80fd1 | 47 | }; |
phn10 | 45:54d18ab80fd1 | 48 | |
phn10 | 45:54d18ab80fd1 | 49 | |
phn10 | 45:54d18ab80fd1 | 50 | int main(void) { |
phn10 | 45:54d18ab80fd1 | 51 | initial_setup(as1107); |
phn10 | 45:54d18ab80fd1 | 52 | |
phn10 | 45:54d18ab80fd1 | 53 | //set all digits to zero |
phn10 | 45:54d18ab80fd1 | 54 | spi_send(as1107, 0x0100); |
phn10 | 45:54d18ab80fd1 | 55 | spi_send(as1107, 0x0200); |
phn10 | 45:54d18ab80fd1 | 56 | spi_send(as1107, 0x0300); |
phn10 | 45:54d18ab80fd1 | 57 | spi_send(as1107, 0x0400); |
phn10 | 45:54d18ab80fd1 | 58 | |
phn10 | 45:54d18ab80fd1 | 59 | pc.printf("Press user button to test.\n"); |
phn10 | 45:54d18ab80fd1 | 60 | |
phn10 | 45:54d18ab80fd1 | 61 | //test_target_leds(); |
phn10 | 45:54d18ab80fd1 | 62 | //pc.printf("LED's tested"); |
phn10 | 45:54d18ab80fd1 | 63 | |
phn10 | 45:54d18ab80fd1 | 64 | //test_phototransistors(); |
phn10 | 45:54d18ab80fd1 | 65 | //pc.printf("Phototransistors tested"); |
phn10 | 45:54d18ab80fd1 | 66 | |
phn10 | 45:54d18ab80fd1 | 67 | step_test(); |
phn10 | 45:54d18ab80fd1 | 68 | pc.printf("Step motor tested."); |
phn10 | 45:54d18ab80fd1 | 69 | |
phn10 | 45:54d18ab80fd1 | 70 | while (uti_chk_ubutton() == 0); |
phn10 | 45:54d18ab80fd1 | 71 | pc.printf("test begin\n"); |
phn10 | 45:54d18ab80fd1 | 72 | lzr_init(); |
phn10 | 45:54d18ab80fd1 | 73 | while (uti_chk_ubutton() == 0) { |
phn10 | 45:54d18ab80fd1 | 74 | lzr_on(); |
phn10 | 45:54d18ab80fd1 | 75 | wait(0.5); |
phn10 | 45:54d18ab80fd1 | 76 | lzr_off(); |
phn10 | 45:54d18ab80fd1 | 77 | wait(0.5); |
phn10 | 45:54d18ab80fd1 | 78 | } |
phn10 | 45:54d18ab80fd1 | 79 | lzr_init(); |
phn10 | 45:54d18ab80fd1 | 80 | } |