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 pixy pixy_test
Fork of aUtO_volume by
Revision 1:5302a23c97c4, committed 2015-11-24
- Comitter:
- jfields
- Date:
- Tue Nov 24 01:06:04 2015 +0000
- Parent:
- 0:6618ecb9567e
- Child:
- 2:1354ce60c0b9
- Commit message:
- a
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| pixy_test.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 18 21:03:06 2015 +0000
+++ b/main.cpp Tue Nov 24 01:06:04 2015 +0000
@@ -1,29 +1,52 @@
#include "mbed.h"
#include "Pixy.h"
+// init board
Pixy pixy(Pixy::SPI, p11, p12, p13);
Serial pc(USBTX, USBRX);
+// global vars
+int num_readings = 0;
+int total_y = 0;
+
+// funcs
+void get_volume(int i);
+
int main() {
+
+ // init pixy
pc.printf("ready\n\r");
pixy.setSerialOutput(&pc);
+
while (1) {
- static int i = 0;
- int j;
+
+ // get pixy data
uint16_t blocks;
-
blocks = pixy.getBlocks();
-
+
+ // store data
if (blocks) {
- i++;
-
- if (i % 50 == 0) {
- pc.printf("Detected %d:\n\r", blocks);
- for (j = 0; j < blocks; j++) {
- pc.printf(" block %d: ", j);
- pixy.blocks[j].print(pc);
- }
+ for (int j = 0; j < blocks; j++) {
+ get_volume(pixy.blocks[j].y);
}
}
- }
+ }
}
+
+void get_volume(int y) {
+
+ // update data
+ total_y += y;
+ num_readings++;
+
+ // output results
+ if (num_readings > 30) {
+ double average_y = total_y/num_readings;
+ double result = -42*average_y + 327;
+ pc.printf("y = %d, num_readings = %d, average = %d, mL = %d\r\n", y, num_readings, average_y, result);
+
+ // reset vars
+ num_readings = 0;
+ total_y = 0;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pixy_test.lib Tue Nov 24 01:06:04 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ese5191234/code/pixy_test/#6618ecb9567e
