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:
- 75:49e69031799c
- Parent:
- 74:8881f4aeb174
- Child:
- 76:7514ca07b45d
--- a/wag.cpp Tue Apr 24 16:26:38 2018 +0000 +++ b/wag.cpp Thu Apr 26 15:33:35 2018 +0000 @@ -75,7 +75,7 @@ clock_t difference = clock() - start; msec = difference * 1000 / CLOCKS_PER_SEC; //pc.printf("Time elapsed: %d. Time limit: %d\n", msec, VOLLEY_DELAY); - } while (msec < VOLLEY_DELAY and sensor_values[whacker_no + a_num] < PTTHRESH); // check if timer expired or if sensor hit + } while (msec < VOLLEY_DELAY and sensor_values[whacker_no + a_num] * 3.3 < PTTHRESH); // check if timer expired or if sensor hit if (sensor_values[whacker_no + a_num] * 3.3 > PTTHRESH) { hit++; // increment hit count @@ -135,77 +135,82 @@ // start timer for sensor reading start = clock(); - // keep reading until one of the sensor get laser pointed in - while (!sensor_registered) { - // scan all 16 sensors into sensor_values array - ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); - - // 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] * 3.3f > PTTHRESH) { - sensor_registered = true; - gnoll_sensor_indicator = i; - pc.printf("gnoll_sensor_indicator: %d\n", gnoll_sensor_indicator); + for (int i = 0; i < 15; i++) { + pc.printf("i: %d\n", i); + sensor_registered = false; + + // keep reading until one of the sensor get laser pointed in + while (!sensor_registered) { + // scan all 16 sensors into sensor_values array + ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); + + // 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] * 3.3f > PTTHRESH) { + sensor_registered = true; + gnoll_sensor_indicator = i; + pc.printf("gnoll_sensor_indicator: %d\n", gnoll_sensor_indicator); + } + } + + // if (reading sensor timer expired) display error and freeze + 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); } } - - // if (reading sensor timer expired) display error and freeze - 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); - } - } - - // point whack’s laser to the corresponding sensor on whack target array - turn_to_target(stp_sensor_pos[gnoll_no + gnoll_sensor_indicator ]); - - // turn on whacker's laser - lzr_on(); - - start = clock(); - sensor_registered = false; + + // point whack’s laser to the corresponding sensor on whack target array + turn_to_target(stp_sensor_pos[gnoll_no + gnoll_sensor_indicator ]); + + // turn on whacker's laser + lzr_on(); + + start = clock(); + sensor_registered = false; + + // sense which sensor the whack laser point to and turn it on + while (!sensor_registered) { + // scan all 16 sensors into sensor_values array + ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); - // sense which sensor the whack laser point to and turn it on - while (!sensor_registered) { - // scan all 16 sensors into sensor_values array - ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); - - for (int i = 0; i < TGT_SENSOR_QUAN; i++) { - // detect which gnoll sensor get lasered on - if (sensor_values[i + sensor_no] * 3.3f > PTTHRESH) { - sensor_registered = true; - whack_sensor_indicator = i; - pc.printf("gnoll_sensor_indicator: %d\n", gnoll_sensor_indicator); + for (int i = 0; i < TGT_SENSOR_QUAN; i++) { + // detect which gnoll sensor get lasered on + if (sensor_values[i + sensor_no] * 3.3f > PTTHRESH) { + sensor_registered = true; + whack_sensor_indicator = i; + pc.printf("gnoll_sensor_indicator: %d\n", gnoll_sensor_indicator); + } + } + + // if timer expire display error and freeze + 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); } } - - // if timer expire display error and freeze - 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); - } + + // activate corresponding indicator in whack LED row + 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] * 3.3f > PTTHRESH); + + // turn off laer gnoll + lzr_off(); + + // turn off LED display + spi_send(as1107, 0x0500); } - - // activate corresponding indicator in whack LED row - 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] * 3.3f > PTTHRESH); - - // turn off laer gnoll - lzr_off(); - - // turn off LED display - spi_send(as1107, 0x0500); } void update_score(int hit, int miss)