Lauren Taylor / Mbed 2 deprecated phototransistor

Dependencies:   mbed

Committer:
_laurentaylorrr
Date:
Thu Mar 08 18:17:55 2018 +0000
Revision:
0:46b2c955924b
Child:
1:279fcab0c394
Just reads phototransistor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
_laurentaylorrr 0:46b2c955924b 1 #include "mbed.h"
_laurentaylorrr 0:46b2c955924b 2 AnalogIn lightSensor(p20);
_laurentaylorrr 0:46b2c955924b 3 Serial pc(USBTX,USBRX);
_laurentaylorrr 0:46b2c955924b 4 int main() {
_laurentaylorrr 0:46b2c955924b 5 float x;
_laurentaylorrr 0:46b2c955924b 6 int n = 10;
_laurentaylorrr 0:46b2c955924b 7 while(1) {
_laurentaylorrr 0:46b2c955924b 8 // Average n readings of the light sensor
_laurentaylorrr 0:46b2c955924b 9 x = 0;
_laurentaylorrr 0:46b2c955924b 10 for (int i = 0; i<n; i++)
_laurentaylorrr 0:46b2c955924b 11 x = x + lightSensor;
_laurentaylorrr 0:46b2c955924b 12 x = x/n;
_laurentaylorrr 0:46b2c955924b 13 pc.printf("%.4f\r\n", x);
_laurentaylorrr 0:46b2c955924b 14 wait(0.2);
_laurentaylorrr 0:46b2c955924b 15 }
_laurentaylorrr 0:46b2c955924b 16 }