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
Diff: wag.cpp
- Revision:
- 65:b8f3339b9268
- Parent:
- 63:8fcb1cc55e18
- Parent:
- 64:72f7f5757f0d
- Child:
- 66:70efa618c378
--- a/wag.cpp Tue Apr 17 16:15:21 2018 +0000 +++ b/wag.cpp Thu Apr 19 00:14:15 2018 +0000 @@ -15,23 +15,30 @@ #include "mbed.h" #include "io_pins.h" #include "wag.h" +#include "spi.h" #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <timer.h> extern Timer t; +extern spi_cfg as1107; +extern int stp_sensor_pos[TGT_SENSOR_QUAN]; + int led_values[8] = {1, 2, 4, 8, 16, 32, 64, 128}; + void gnoll(int sensor_no, float sensor_values[]) { int hit, miss = 0; int a_num; int led_command; + int whacker_no = 0; if (sensor_no == 0) whacker_no = 8; + int sensor_no = 0; //change to match station + for (int i = 0; i < 15; i++) { pc.printf("Round %d\n", i + 1); a_num = rand() % 8; // create random number 0-7 @@ -83,15 +90,28 @@ } } +/* + * void whack(int sensor_no, float * sensor_values) + * Description: function for whacker + * + * Inputs: + * Parameters: + * int sensor_no: the + * float * sensor_values: an float array that stores 16 sensor values + * Globals: + * + * Outputs: + * Returns: void +*/ void whack(int sensor_no, float * sensor_values) { bool sensor_registered = false; int gnoll_sensor_indicator = 0; // the order of sensor that gnoller's laser points to - int whack_sensor_indicaotr = 0; // the order of sensor that whacker's laser points to + int whack_sensor_indicator = 0; // the order of sensor that whacker's laser points to int gnoll_no = 0; int led_command = 0; // led command to display the indicator LED in whacker - if (sensor_no == 0) whack_no = 8; - if (sensor_no == 8) whack_no = 0; + if (sensor_no == 0) gnoll_no = 8; + if (sensor_no == 8) gnoll_no = 0; // start timer for sensor reading t.start(); @@ -104,7 +124,7 @@ // scan all gnoll sensors for (int i = 0; i < TGT_SENSOR_QUAN; i++) { // detect which gnoll sensor get lasered on - if (sensor_values[i + gnoll_no] > THRESHOLD_SIGNAL) + if (sensor_values[i + gnoll_no] * 3.3f > PTTHRESH) sensor_registered = true; gnoll_sensor_indicator = i; } @@ -133,7 +153,7 @@ // scan all whack sensors for (int i = 0; i < TGT_SENSOR_QUAN; i++) { // detect which gnoll sensor get lasered on - if (sensor_values[i + sensor_no] > THRESHOLD_SIGNAL) + if (sensor_values[i + sensor_no] * 3.3f > PTTHRESH) sensor_registered = true; whack_sensor_indicator = i; } @@ -147,14 +167,14 @@ } // activate corresponding indicator in whack LED row - led_command = 0x0500 + led_values[whack_sensor_indicator]); + led_command = 0x0500 + led_values[whack_sensor_indicator]; spi_send(as1107, led_command); // waiting for gnoll laser to turn off to turn off do { // scan all 16 sensors into sensor_values array ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); - } while (sensor_values[gnoll_sensor_indicator + gnoll_no] > PT_THRESHOLD); + } while (sensor_values[gnoll_sensor_indicator + gnoll_no] * 3.3f > PTTHRESH); // turn off laer gnoll lzr_off();