Code to test sensor.

Dependencies:   SI1143 TextLCD mbed

Committer:
GAT27
Date:
Thu Oct 17 22:34:00 2013 +0000
Revision:
0:03bf686bd26a
Child:
1:a4c6fbb79eba
Simple test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GAT27 0:03bf686bd26a 1 #include "mbed.h"
GAT27 0:03bf686bd26a 2 #include "SI1143.h"
GAT27 0:03bf686bd26a 3
GAT27 0:03bf686bd26a 4 SI1143 sensor(p28, p27);
GAT27 0:03bf686bd26a 5
GAT27 0:03bf686bd26a 6 DigitalOut led1(LED1);
GAT27 0:03bf686bd26a 7 DigitalOut led2(LED2);
GAT27 0:03bf686bd26a 8 DigitalOut led3(LED3);
GAT27 0:03bf686bd26a 9
GAT27 0:03bf686bd26a 10 int main()
GAT27 0:03bf686bd26a 11 {
GAT27 0:03bf686bd26a 12 int sense1,sense2,sense3;
GAT27 0:03bf686bd26a 13
GAT27 0:03bf686bd26a 14 // Setup the baseline
GAT27 0:03bf686bd26a 15 sensor.bias();
GAT27 0:03bf686bd26a 16 wait(1);
GAT27 0:03bf686bd26a 17
GAT27 0:03bf686bd26a 18 while(1)
GAT27 0:03bf686bd26a 19 {
GAT27 0:03bf686bd26a 20 // Read each led sensor
GAT27 0:03bf686bd26a 21 sense1 = sensor.sample(1);
GAT27 0:03bf686bd26a 22 sense2 = sensor.sample(2);
GAT27 0:03bf686bd26a 23 sense3 = sensor.sample(3);
GAT27 0:03bf686bd26a 24
GAT27 0:03bf686bd26a 25 // Can be changed for different sensitivity
GAT27 0:03bf686bd26a 26 if (sense1 > 80 || sense2 > 80 || sense3 > 80)
GAT27 0:03bf686bd26a 27 {
GAT27 0:03bf686bd26a 28 if (sense1 > sense2 && sense1 > sense3)
GAT27 0:03bf686bd26a 29 {
GAT27 0:03bf686bd26a 30 led1=1;
GAT27 0:03bf686bd26a 31 led2=0;
GAT27 0:03bf686bd26a 32 led3=0;
GAT27 0:03bf686bd26a 33 }
GAT27 0:03bf686bd26a 34
GAT27 0:03bf686bd26a 35 else if(sense2 > sense1 && sense2 > sense3)
GAT27 0:03bf686bd26a 36 {
GAT27 0:03bf686bd26a 37 led1=0;
GAT27 0:03bf686bd26a 38 led2=1;
GAT27 0:03bf686bd26a 39 led3=0;
GAT27 0:03bf686bd26a 40 }
GAT27 0:03bf686bd26a 41
GAT27 0:03bf686bd26a 42 else if(sense3 > sense1 && sense3 > sense2)
GAT27 0:03bf686bd26a 43 {
GAT27 0:03bf686bd26a 44 led1=0;
GAT27 0:03bf686bd26a 45 led2=0;
GAT27 0:03bf686bd26a 46 led3=1;
GAT27 0:03bf686bd26a 47 }
GAT27 0:03bf686bd26a 48 }
GAT27 0:03bf686bd26a 49
GAT27 0:03bf686bd26a 50 else
GAT27 0:03bf686bd26a 51 {
GAT27 0:03bf686bd26a 52 led1=0;
GAT27 0:03bf686bd26a 53 led2=0;
GAT27 0:03bf686bd26a 54 led3=0;
GAT27 0:03bf686bd26a 55 }
GAT27 0:03bf686bd26a 56
GAT27 0:03bf686bd26a 57 //Numeriacl output through terminal
GAT27 0:03bf686bd26a 58 printf("%d-%d-%d\r\n",sense1,sense2,sense3);
GAT27 0:03bf686bd26a 59 }
GAT27 0:03bf686bd26a 60 }