Lauren Taylor / Mbed 2 deprecated phototransistor

Dependencies:   mbed

main.cpp

Committer:
oldmanturtle
Date:
2018-03-08
Revision:
2:c76b070c2a55
Parent:
1:279fcab0c394
Child:
3:9d9628bd3514

File content as of revision 2:c76b070c2a55:

#include "mbed.h" 
AnalogIn lightSensor(p20); 
DigitalOut ledRed(p25);
DigitalOut ledBlue(p26);


Serial pc(USBTX,USBRX); 
int main() { 
    float x; 
    int n = 10; 
    while(1) {
        ledRed = 1; 
        // Average n readings of the light sensor 
        x = 0; 
        for (int i = 0; i<n; i++) 
            x = x + lightSensor; 
        x = x/n;
        pc.printf("%.4f\r\n", x);
        ledRed = 0; 
        // Average n readings of the light sensor 
        x = 0; 
        for (int i = 0; i<n; i++) 
            x = x + lightSensor; 
        x = x/n;
        pc.printf("%.4f\r\n", x);
        wait(0.2); 
    } 
}