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:
- 69:1b7271bd4a75
- Parent:
- 68:9245d6ce176e
- Child:
- 71:6ced854bebb2
--- a/wag.cpp Thu Apr 19 15:49:06 2018 +0000 +++ b/wag.cpp Mon Apr 23 19:52:06 2018 +0000 @@ -42,17 +42,19 @@ for (int i = 0; i < 15; i++) { pc.printf("Round %d\n", i + 1); a_num = rand() % 8; // create random number 0-7 + pc.printf("Random number: %d. Stepper position: %d.", a_num, stp_sensor_pos[a_num]); turn_to_target(stp_sensor_pos[a_num]); // turn motor to random target lzr_on(); // turn laser on wait(LASER_DELAY); // wait for laser to activate ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // scan all sensors - if (sensor_values[sensor_no + a_num] > PTTHRESH) { // confirm that the sensor is high + 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 spi_send(as1107, led_command); // light up LED } else { + pc.printf("sensor value: %f\n" ,sensor_values[sensor_no + a_num] * 3.3); pc.printf("Error: sensor not activated. Shutting down.\n"); while(1); } @@ -64,22 +66,23 @@ ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // scan all sensors clock_t difference = clock() - start; msec = difference * 1000 / CLOCKS_PER_SEC; - } while (msec < VOLLEY_DELAY or sensor_values[whacker_no + a_num] < PTTHRESH); // check if timer expired or if sensor hit + //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 - if (sensor_values[whacker_no + a_num] > PTTHRESH) { + if (sensor_values[whacker_no + a_num] * 3.3 > PTTHRESH) { hit++; // increment hit count pc.printf("Hit\n"); - while(sensor_values[whacker_no + a_num] > PTTHRESH) + while(sensor_values[whacker_no + a_num] * 3.3 > PTTHRESH) ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // waits for whacker laser to turn off } else { for (int j = 0 + whacker_no; j < 8 + whacker_no; j++) { // go through all whacker sensors - if (sensor_values[i + whacker_no] > PTTHRESH and j != a_num) { // check if wrong sensor hit + if (sensor_values[i + whacker_no] * 3.3 > PTTHRESH and j != a_num) { // check if wrong sensor hit pc.printf("Wrong sensor hit.\n"); i = 15; // ends volley ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // scan all sensors - while(sensor_values[i + whacker_no] > PTTHRESH) + while(sensor_values[i + whacker_no] * 3.3 > PTTHRESH) ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2); // waits for whacker laser to turn off } }