Working laser maze comparator. Solar cells need to be connected with ground and the +ve line connected to A0 - A4. These correspond to the output on D6-D2 respectively. Reseting the nucleo takes a base reading of the solar cells. This base reading is used, along with the #define OFFSET value to either output a 0 or a 1 if the solar cell value is over the first reading + offset.
Diff: main.cpp
- Revision:
- 2:87c34bb330c2
- Parent:
- 1:59475336cb66
--- a/main.cpp Mon Jan 08 18:19:51 2018 +0000 +++ b/main.cpp Thu Nov 29 12:43:39 2018 +0000 @@ -26,14 +26,16 @@ //array of digital channels DigitalOut doutChannels[CHANNEL_COUNT] = {Dout0, Dout1, Dout2, Dout3, Dout4}; +Serial pc(PA_11, PA_12); int main() { //read value of analog channels float meas; - + pc.printf("Hello World !\n"); //calibrate to ambient light, adding offset to find the thresholds for(int i = 0; i < CHANNEL_COUNT; i++) { initialValues[i] = (ainChannels[i].read() * 3300) + OFFSET; + //pc.printf("initial %d = %.0f mV\n", i, initialValues[i]); } while(1) { @@ -42,7 +44,7 @@ //find channels current value meas = ainChannels[i].read(); // Converts and read the analog input value (value from 0.0 to 1.0) meas = meas * 3300; // Change the value to be in the 0 to 3300 range - printf("measure %d = %.0f mV\n", i, meas); + pc.printf("measure %d = %.0f mV\n", i, meas); if (meas > initialValues[i]) { // If the value is greater than 2V then switch the LED on doutChannels[i] = 1; }