
Sumejja Porča Edis Kunić
main.cpp@0:347b86312097, 2014-05-08 (annotated)
- Committer:
- tim008
- Date:
- Thu May 08 16:58:06 2014 +0000
- Revision:
- 0:347b86312097
LV08_Grupa7_Tim008_Z01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim008 | 0:347b86312097 | 1 | #include "mbed.h" |
tim008 | 0:347b86312097 | 2 | #include "TSISensor.h" |
tim008 | 0:347b86312097 | 3 | |
tim008 | 0:347b86312097 | 4 | Serial pc(USBTX, USBRX); // tx, rx |
tim008 | 0:347b86312097 | 5 | PwmOut ledR(LED1), ledG(LED2), ledB(LED3); |
tim008 | 0:347b86312097 | 6 | TSISensor tsi; |
tim008 | 0:347b86312097 | 7 | Ticker ticker; |
tim008 | 0:347b86312097 | 8 | |
tim008 | 0:347b86312097 | 9 | float brightness = 1.0; |
tim008 | 0:347b86312097 | 10 | |
tim008 | 0:347b86312097 | 11 | void printTSI() |
tim008 | 0:347b86312097 | 12 | { |
tim008 | 0:347b86312097 | 13 | pc.printf("Percentage of tsi is %.2f\n", tsi.readPercentage()*100.0); |
tim008 | 0:347b86312097 | 14 | } |
tim008 | 0:347b86312097 | 15 | |
tim008 | 0:347b86312097 | 16 | int getBrightness() |
tim008 | 0:347b86312097 | 17 | { |
tim008 | 0:347b86312097 | 18 | char c1 = pc.getc(); |
tim008 | 0:347b86312097 | 19 | if( c1 < '0' || c1 > '9' ) return -1; |
tim008 | 0:347b86312097 | 20 | char c2 = pc.getc(); |
tim008 | 0:347b86312097 | 21 | if (c2 < '0' || c2 > '9' ) return -1; |
tim008 | 0:347b86312097 | 22 | else return (c1 - '0') * 10 + c2 - '0'; |
tim008 | 0:347b86312097 | 23 | } |
tim008 | 0:347b86312097 | 24 | void getCommand() |
tim008 | 0:347b86312097 | 25 | { |
tim008 | 0:347b86312097 | 26 | char c = pc.getc(); |
tim008 | 0:347b86312097 | 27 | switch(c) |
tim008 | 0:347b86312097 | 28 | { |
tim008 | 0:347b86312097 | 29 | case 'R': |
tim008 | 0:347b86312097 | 30 | ledG = ledB = 1.0; |
tim008 | 0:347b86312097 | 31 | brightness = getBrightness(); |
tim008 | 0:347b86312097 | 32 | if(brightness == -1) return; |
tim008 | 0:347b86312097 | 33 | ledR = 1 - brightness / 100.0; |
tim008 | 0:347b86312097 | 34 | break; |
tim008 | 0:347b86312097 | 35 | case 'G': |
tim008 | 0:347b86312097 | 36 | ledR = ledB = 1.0; |
tim008 | 0:347b86312097 | 37 | brightness = getBrightness(); |
tim008 | 0:347b86312097 | 38 | if(brightness == -1) return; |
tim008 | 0:347b86312097 | 39 | ledG = 1 - brightness / 100.0; |
tim008 | 0:347b86312097 | 40 | break; |
tim008 | 0:347b86312097 | 41 | case 'B': |
tim008 | 0:347b86312097 | 42 | ledG = ledR = 1.0; |
tim008 | 0:347b86312097 | 43 | brightness = getBrightness(); |
tim008 | 0:347b86312097 | 44 | if(brightness == -1) return; |
tim008 | 0:347b86312097 | 45 | ledB = 1 - brightness / 100.0; |
tim008 | 0:347b86312097 | 46 | break; |
tim008 | 0:347b86312097 | 47 | case 'P': |
tim008 | 0:347b86312097 | 48 | ticker.attach(&printTSI, 1); |
tim008 | 0:347b86312097 | 49 | break; |
tim008 | 0:347b86312097 | 50 | case 'Z': |
tim008 | 0:347b86312097 | 51 | ticker.detach(); |
tim008 | 0:347b86312097 | 52 | break; |
tim008 | 0:347b86312097 | 53 | default: |
tim008 | 0:347b86312097 | 54 | return; |
tim008 | 0:347b86312097 | 55 | } |
tim008 | 0:347b86312097 | 56 | } |
tim008 | 0:347b86312097 | 57 | |
tim008 | 0:347b86312097 | 58 | int main() { |
tim008 | 0:347b86312097 | 59 | pc.printf("Press XDD -> X to turn R/G/B diode up and DD to adjust its brightness,or P to start measuring TSI and Z to stop it\n"); |
tim008 | 0:347b86312097 | 60 | ledR = ledG = ledB = 1.0; |
tim008 | 0:347b86312097 | 61 | pc.attach(&getCommand); |
tim008 | 0:347b86312097 | 62 | while(1) { |
tim008 | 0:347b86312097 | 63 | } |
tim008 | 0:347b86312097 | 64 | } |