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:
- 74:8881f4aeb174
- Parent:
- 73:e8f7ee59d3e5
- Child:
- 75:49e69031799c
diff -r e8f7ee59d3e5 -r 8881f4aeb174 wag.cpp
--- a/wag.cpp Mon Apr 23 21:41:15 2018 +0000
+++ b/wag.cpp Tue Apr 24 16:26:38 2018 +0000
@@ -30,7 +30,8 @@
void gnoll(int sensor_no, float * sensor_values)
{
- int hit, miss = 0;
+ int hit = 0;
+ int miss = 0;
int a_num;
int led_command;
int msec;
@@ -39,7 +40,8 @@
if (sensor_no == 0)
whacker_no = 8;
-
+
+
srand(time(NULL));
for (int i = 0; i < 15; i++) {
pc.printf("Round %d\n", i + 1);
@@ -50,13 +52,14 @@
wait(LASER_DELAY); // wait for laser to activate
ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // scan all sensors
- wait(LASER_DELAY);
+ wait(LED_DELAY);
if (sensor_values[sensor_no + a_num] * 3.3 > PTTHRESH) { // confirm that the sensor is high
led_command = 0x0500 + led_values[a_num]; // create SPI command for LED
- pc.printf("led_command: %d\n", led_command);
+ //pc.printf("led_command: %d\n", led_command);
spi_send(as1107, led_command); // light up LED
- pc.printf("done sent");
+ //pc.printf("done sent\n");
+ wait(LED_DELAY);
// NOTE: must put a wait() here or else the led won't light up
} else {
pc.printf("sensor value: %f\n" ,sensor_values[sensor_no + a_num] * 3.3);
@@ -84,6 +87,7 @@
else {
for (int j = 0 + whacker_no; j < 8 + whacker_no; j++) { // go through all whacker sensors
if (sensor_values[i + whacker_no] * 3.3 > PTTHRESH and j != a_num) { // check if wrong sensor hit
+ pc.printf("Sensor: %d. Sensor value:%f\n", j, sensor_values[i + whacker_no] * 3.3);
pc.printf("Wrong sensor hit.\n");
i = 15; // ends volley
ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // scan all sensors
@@ -96,6 +100,7 @@
}
lzr_off();
spi_send(as1107, 0x0500);
+ pc.printf("Hit: %d. Miss: %d.", hit, miss);
update_score(hit, miss);
}
}
@@ -120,12 +125,15 @@
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
+ int msec = 0;
+ clock_t start;
+ clock_t difference;
if (sensor_no == 0) gnoll_no = 8;
if (sensor_no == 8) gnoll_no = 0;
// start timer for sensor reading
- t.start();
+ start = clock();
// keep reading until one of the sensor get laser pointed in
while (!sensor_registered) {
@@ -143,8 +151,9 @@
}
// if (reading sensor timer expired) display error and freeze
- t.stop();
- if (t.read() > WHACK_EXPIRED_TIMER) {
+ difference = clock() - start;
+ msec = difference * 1000 / CLOCKS_PER_SEC;
+ if (msec > WHACK_EXPIRED_TIMER) {
pc.printf("Error: Reading timer expired. See whack() function.\n");
while (1);
}
@@ -156,7 +165,7 @@
// turn on whacker's laser
lzr_on();
- t.start();
+ start = clock();
sensor_registered = false;
// sense which sensor the whack laser point to and turn it on
@@ -174,8 +183,9 @@
}
// if timer expire display error and freeze
- t.stop();
- if (t.read() > WHACK_EXPIRED_TIMER) {
+ difference = clock() - start;
+ msec = difference * 1000 / CLOCKS_PER_SEC;
+ if (msec > WHACK_EXPIRED_TIMER) {
pc.printf("Error: Reading timer expired. See whack() function.\n");
while(1);
}
@@ -196,7 +206,6 @@
// turn off LED display
spi_send(as1107, 0x0500);
-
}
void update_score(int hit, int miss)
@@ -214,6 +223,7 @@
d3 = miss % 10;
d4 = (miss - d3)/10;
}
+ pc.printf("d1: %d -- d3: %d\n", d1, d3);
spi_send(as1107, 0x0100 + d1);
spi_send(as1107, 0x0200 + d2);
spi_send(as1107, 0x0300 + d3);
