Last active
October 22, 2016 19:56
-
-
Save yue82/410648a383cc2b6a4d5b9a4d14fd3ce6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
AnalogIn sensor[] = {dp19, dp20, dp21}; | |
BusOut mdA(dp7, dp6); | |
BusOut mdB(dp9, dp8); | |
Serial pc(USBTX, USBRX); | |
int sensor2bin(float sensor_var, float threshold) | |
{ | |
if(sensor_var > threshold) { | |
return 1; | |
} else{ | |
return 0; | |
} | |
} | |
int main() | |
{ | |
float s[3] = {0.0, 0.0, 0.0}; | |
float ts = 0.3; | |
mdA = 0b11; | |
mdB = 0b11; | |
while(1) { | |
for (int i = 0; i < 3; i++){ | |
s[i] = sensor[i].read(); | |
pc.printf("%d: %d\r\n", i, sensor2bin(s[i], ts)); | |
} | |
pc.printf("%f %f %f\r\n", s[0], s[1], s[2]); | |
wait(1.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment