Samir Bouaziz / Mbed 2 deprecated TSL230essai

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 ****************************************************
00003 Frequency is measured by interrupts.
00004 
00005 Wiring: TSL230       mBed
00006          p1(s0)      H (p39)
00007          p2(s1)      L (p1)
00008          p7(s2)      H (p39)
00009          p8(s3)      H (p39)
00010          p6(out)     p11
00011 les pattes du TSL230 qui reste :
00012 p3(OE), p4(GND) tied to ground. p5(Vcc) tied to 3V3.
00013 
00014 Author: Samir Bouaziz. october 2011.
00015 *********************(******************************
00016 */
00017 
00018 
00019 #include "mbed.h"
00020 #include "math.h"
00021 
00022 
00023 Serial pc(USBTX, USBRX);
00024 InterruptIn in(p11);
00025 Timer t,t2;
00026 
00027 float period = 0; // This is the period between interrupts in microseconds
00028 float freq = 0;
00029 volatile int demiper,n=0,per;
00030 
00031 void itup() {
00032    switch(n){
00033       case 0 :
00034                t.start();
00035                n++;
00036                break;
00037      // case 1 : 
00038       case 10: t.stop();
00039                per=t.read_us();
00040                n=0;
00041                t.reset();
00042                break;
00043       default : n++;
00044                 break;
00045     }
00046 }
00047 
00048 void itdown() {
00049     demiper=t.read_us();
00050     t.stop();
00051 }
00052 
00053 
00054 int main() {
00055 float mes;
00056 //    in.mode(PullUp); // Set the pin to Pull Down mode.
00057     in.rise(&itup);  // Set up the interrupt for rising edge
00058 //    in.fall(&itdown);  // Set up the interrupt for rising edge
00059     while (1) {
00060         wait(1);
00061         //freq= 100000.0/((float)per);
00062         mes=(10000./((float)per))/0.0069;
00063         pc.printf("%f %f\r\n",mes,10000000./((float)per));
00064 
00065     }
00066 }
00067 
00068 
00069