tim003 tim003
/
LAB8_Grupa5_Tim003_Zadatak1
Amer Ratkovic Emir Mujacic
main.cpp@0:a81f84926340, 2014-05-08 (annotated)
- Committer:
- tim003
- Date:
- Thu May 08 13:16:01 2014 +0000
- Revision:
- 0:a81f84926340
LAB8-PAI-GRUPA5-TIM003-ZADATAK1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim003 | 0:a81f84926340 | 1 | #include "mbed.h" |
tim003 | 0:a81f84926340 | 2 | #include "TSISensor.h" |
tim003 | 0:a81f84926340 | 3 | |
tim003 | 0:a81f84926340 | 4 | |
tim003 | 0:a81f84926340 | 5 | Serial pc(USBTX, USBRX); |
tim003 | 0:a81f84926340 | 6 | PwmOut red(LED_RED), green(LED_GREEN),blue(LED_BLUE); |
tim003 | 0:a81f84926340 | 7 | TSISensor tsi; |
tim003 | 0:a81f84926340 | 8 | |
tim003 | 0:a81f84926340 | 9 | Ticker t; |
tim003 | 0:a81f84926340 | 10 | |
tim003 | 0:a81f84926340 | 11 | void ispis() |
tim003 | 0:a81f84926340 | 12 | { |
tim003 | 0:a81f84926340 | 13 | pc.printf("\nTSI: %f",tsi.readPercentage()); |
tim003 | 0:a81f84926340 | 14 | } |
tim003 | 0:a81f84926340 | 15 | |
tim003 | 0:a81f84926340 | 16 | float brightness = 0.0; |
tim003 | 0:a81f84926340 | 17 | int main() { |
tim003 | 0:a81f84926340 | 18 | int brojac=0; |
tim003 | 0:a81f84926340 | 19 | red=1.; green=1.; blue=1.; |
tim003 | 0:a81f84926340 | 20 | pc.printf("Unesi XDD ili P ili Z:"); |
tim003 | 0:a81f84926340 | 21 | float svjetlo; |
tim003 | 0:a81f84926340 | 22 | while(1) { |
tim003 | 0:a81f84926340 | 23 | char a; |
tim003 | 0:a81f84926340 | 24 | a=pc.getc(); |
tim003 | 0:a81f84926340 | 25 | |
tim003 | 0:a81f84926340 | 26 | if(a=='R') |
tim003 | 0:a81f84926340 | 27 | { |
tim003 | 0:a81f84926340 | 28 | char b=pc.getc(); |
tim003 | 0:a81f84926340 | 29 | if(b>='0' && b<='9') |
tim003 | 0:a81f84926340 | 30 | { |
tim003 | 0:a81f84926340 | 31 | svjetlo=(b-48)*10; |
tim003 | 0:a81f84926340 | 32 | char c=pc.getc(); |
tim003 | 0:a81f84926340 | 33 | if(c>='0' && c<='9') |
tim003 | 0:a81f84926340 | 34 | { |
tim003 | 0:a81f84926340 | 35 | red=1; blue=1; green=1; |
tim003 | 0:a81f84926340 | 36 | svjetlo+=c-48; |
tim003 | 0:a81f84926340 | 37 | svjetlo=svjetlo/100.; |
tim003 | 0:a81f84926340 | 38 | svjetlo=1-svjetlo; |
tim003 | 0:a81f84926340 | 39 | red=svjetlo; |
tim003 | 0:a81f84926340 | 40 | } |
tim003 | 0:a81f84926340 | 41 | |
tim003 | 0:a81f84926340 | 42 | } |
tim003 | 0:a81f84926340 | 43 | } |
tim003 | 0:a81f84926340 | 44 | |
tim003 | 0:a81f84926340 | 45 | if(a=='G') |
tim003 | 0:a81f84926340 | 46 | { |
tim003 | 0:a81f84926340 | 47 | char b=pc.getc(); |
tim003 | 0:a81f84926340 | 48 | if(b>='0' && b<='9') |
tim003 | 0:a81f84926340 | 49 | { |
tim003 | 0:a81f84926340 | 50 | svjetlo=(b-48)*10; |
tim003 | 0:a81f84926340 | 51 | char c=pc.getc(); |
tim003 | 0:a81f84926340 | 52 | if(c>='0' && c<='9') |
tim003 | 0:a81f84926340 | 53 | { |
tim003 | 0:a81f84926340 | 54 | red=1; blue=1; green=1; |
tim003 | 0:a81f84926340 | 55 | svjetlo+=c-48; |
tim003 | 0:a81f84926340 | 56 | svjetlo=svjetlo/100.; |
tim003 | 0:a81f84926340 | 57 | svjetlo=1-svjetlo; |
tim003 | 0:a81f84926340 | 58 | green=svjetlo; |
tim003 | 0:a81f84926340 | 59 | } |
tim003 | 0:a81f84926340 | 60 | |
tim003 | 0:a81f84926340 | 61 | } |
tim003 | 0:a81f84926340 | 62 | } |
tim003 | 0:a81f84926340 | 63 | |
tim003 | 0:a81f84926340 | 64 | if(a=='B') |
tim003 | 0:a81f84926340 | 65 | { |
tim003 | 0:a81f84926340 | 66 | |
tim003 | 0:a81f84926340 | 67 | char b=pc.getc(); |
tim003 | 0:a81f84926340 | 68 | if(b>='0' && b<='9') |
tim003 | 0:a81f84926340 | 69 | { |
tim003 | 0:a81f84926340 | 70 | svjetlo=(b-48)*10; |
tim003 | 0:a81f84926340 | 71 | char c=pc.getc(); |
tim003 | 0:a81f84926340 | 72 | if(c>='0' && c<='9') |
tim003 | 0:a81f84926340 | 73 | { |
tim003 | 0:a81f84926340 | 74 | red=1; blue=1; green=1; |
tim003 | 0:a81f84926340 | 75 | svjetlo+=c-48; |
tim003 | 0:a81f84926340 | 76 | svjetlo=svjetlo/100.; |
tim003 | 0:a81f84926340 | 77 | svjetlo=1-svjetlo; |
tim003 | 0:a81f84926340 | 78 | blue=svjetlo; |
tim003 | 0:a81f84926340 | 79 | } |
tim003 | 0:a81f84926340 | 80 | |
tim003 | 0:a81f84926340 | 81 | } |
tim003 | 0:a81f84926340 | 82 | } |
tim003 | 0:a81f84926340 | 83 | |
tim003 | 0:a81f84926340 | 84 | |
tim003 | 0:a81f84926340 | 85 | if(a=='P') |
tim003 | 0:a81f84926340 | 86 | { |
tim003 | 0:a81f84926340 | 87 | red=1; blue=1; green=1; |
tim003 | 0:a81f84926340 | 88 | t.attach(&ispis,1); |
tim003 | 0:a81f84926340 | 89 | } |
tim003 | 0:a81f84926340 | 90 | |
tim003 | 0:a81f84926340 | 91 | if(a=='Z') |
tim003 | 0:a81f84926340 | 92 | { |
tim003 | 0:a81f84926340 | 93 | red=1; blue=1; green=1; |
tim003 | 0:a81f84926340 | 94 | t.detach(); |
tim003 | 0:a81f84926340 | 95 | } |
tim003 | 0:a81f84926340 | 96 | |
tim003 | 0:a81f84926340 | 97 | |
tim003 | 0:a81f84926340 | 98 | } |
tim003 | 0:a81f84926340 | 99 | } |