rohan gala
/
bigthingRec
BIGTHING
main.cpp@2:015a5a76bb82, 2016-03-15 (annotated)
- Committer:
- rohangala
- Date:
- Tue Mar 15 09:40:07 2016 +0000
- Revision:
- 2:015a5a76bb82
- Parent:
- 1:630aef63181c
pp without int;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rohangala | 0:98be6bf27557 | 1 | #include "mbed.h" |
rohangala | 0:98be6bf27557 | 2 | #include "stdio.h" |
rohangala | 1:630aef63181c | 3 | DigitalOut myled(LED1); |
rohangala | 0:98be6bf27557 | 4 | Serial pc(USBTX, USBRX); |
rohangala | 2:015a5a76bb82 | 5 | Serial micro(PTE0, PTE1); // tx, rx |
rohangala | 0:98be6bf27557 | 6 | char buff[]={'\0'}; |
rohangala | 2:015a5a76bb82 | 7 | AnalogIn ax(PTC1); |
rohangala | 2:015a5a76bb82 | 8 | |
rohangala | 2:015a5a76bb82 | 9 | float luxm(void) |
rohangala | 2:015a5a76bb82 | 10 | { |
rohangala | 2:015a5a76bb82 | 11 | AnalogIn ain(PTC2); |
rohangala | 2:015a5a76bb82 | 12 | |
rohangala | 2:015a5a76bb82 | 13 | float vr=0,lr=0; |
rohangala | 2:015a5a76bb82 | 14 | |
rohangala | 2:015a5a76bb82 | 15 | float vol[12]={0.36,0.61,0.8,0.9,1.23,1.45,1.81,2.06,2.62,2.81,3.02,3.25}; |
rohangala | 2:015a5a76bb82 | 16 | float lux[12]={27000,20000,16000,11000,4000,1500,833,578,201,104,40,23}; |
rohangala | 2:015a5a76bb82 | 17 | |
rohangala | 2:015a5a76bb82 | 18 | int i; |
rohangala | 2:015a5a76bb82 | 19 | float m=0; |
rohangala | 2:015a5a76bb82 | 20 | |
rohangala | 2:015a5a76bb82 | 21 | vr=ain*3.3; |
rohangala | 2:015a5a76bb82 | 22 | for(i=0; vr> vol[i];i++); |
rohangala | 2:015a5a76bb82 | 23 | m = ((lux[i]-lux[i+1])/(vol[i]-vol[i+1])); |
rohangala | 2:015a5a76bb82 | 24 | lr=lux[i+1]+(m*(vr-(vol[i+1]))); |
rohangala | 2:015a5a76bb82 | 25 | |
rohangala | 2:015a5a76bb82 | 26 | return lr; |
rohangala | 2:015a5a76bb82 | 27 | } |
rohangala | 2:015a5a76bb82 | 28 | |
rohangala | 2:015a5a76bb82 | 29 | |
rohangala | 2:015a5a76bb82 | 30 | |
rohangala | 0:98be6bf27557 | 31 | |
rohangala | 1:630aef63181c | 32 | uint8_t val; |
rohangala | 0:98be6bf27557 | 33 | |
rohangala | 0:98be6bf27557 | 34 | int main() |
rohangala | 2:015a5a76bb82 | 35 | { |
rohangala | 0:98be6bf27557 | 36 | |
rohangala | 0:98be6bf27557 | 37 | while(1) |
rohangala | 0:98be6bf27557 | 38 | { |
rohangala | 0:98be6bf27557 | 39 | if(micro.readable()) |
rohangala | 0:98be6bf27557 | 40 | { |
rohangala | 1:630aef63181c | 41 | val=(micro.getc()); |
rohangala | 1:630aef63181c | 42 | |
rohangala | 0:98be6bf27557 | 43 | |
rohangala | 1:630aef63181c | 44 | if(val == 0x00) |
rohangala | 1:630aef63181c | 45 | { |
rohangala | 1:630aef63181c | 46 | |
rohangala | 1:630aef63181c | 47 | |
rohangala | 2:015a5a76bb82 | 48 | pc.printf("%.2f ",luxm()); |
rohangala | 1:630aef63181c | 49 | |
rohangala | 1:630aef63181c | 50 | |
rohangala | 1:630aef63181c | 51 | } |
rohangala | 0:98be6bf27557 | 52 | |
rohangala | 1:630aef63181c | 53 | if(val == 0x01) |
rohangala | 1:630aef63181c | 54 | { |
rohangala | 1:630aef63181c | 55 | |
rohangala | 2:015a5a76bb82 | 56 | pc.printf("%.2f ",ax*3.3); |
rohangala | 1:630aef63181c | 57 | } |
rohangala | 0:98be6bf27557 | 58 | |
rohangala | 1:630aef63181c | 59 | val=0x00; |
rohangala | 1:630aef63181c | 60 | |
rohangala | 1:630aef63181c | 61 | wait(2); |
rohangala | 1:630aef63181c | 62 | myled=1; |
rohangala | 0:98be6bf27557 | 63 | } |
rohangala | 0:98be6bf27557 | 64 | } |
rohangala | 0:98be6bf27557 | 65 | } |