tim007 tim007
/
PAI-LV8-Grupa7-Tim007-Zadatak1
Nedim Hozić Kenan Mahmutović
main.cpp@0:d62ace65b2b0, 2014-05-08 (annotated)
- Committer:
- tim007
- Date:
- Thu May 08 17:08:36 2014 +0000
- Revision:
- 0:d62ace65b2b0
PAI-Grupa7-Tim007-Zadatak1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim007 | 0:d62ace65b2b0 | 1 | #include "mbed.h" |
tim007 | 0:d62ace65b2b0 | 2 | #include <ctype.h> |
tim007 | 0:d62ace65b2b0 | 3 | #include "TSISensor.h" |
tim007 | 0:d62ace65b2b0 | 4 | |
tim007 | 0:d62ace65b2b0 | 5 | PwmOut led[3] = {LED1, LED2, LED3}; |
tim007 | 0:d62ace65b2b0 | 6 | |
tim007 | 0:d62ace65b2b0 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
tim007 | 0:d62ace65b2b0 | 8 | Ticker t; |
tim007 | 0:d62ace65b2b0 | 9 | |
tim007 | 0:d62ace65b2b0 | 10 | TSISensor tsi; |
tim007 | 0:d62ace65b2b0 | 11 | |
tim007 | 0:d62ace65b2b0 | 12 | void upaliDiodu(char c) |
tim007 | 0:d62ace65b2b0 | 13 | { |
tim007 | 0:d62ace65b2b0 | 14 | char prva = pc.getc(), druga = pc.getc(); |
tim007 | 0:d62ace65b2b0 | 15 | int jacina = (prva - '0')*10 + druga - '0'; |
tim007 | 0:d62ace65b2b0 | 16 | led[0] = 1.0; |
tim007 | 0:d62ace65b2b0 | 17 | led[1] = 1.0; |
tim007 | 0:d62ace65b2b0 | 18 | led[2] = 1.0; |
tim007 | 0:d62ace65b2b0 | 19 | if(c=='R') |
tim007 | 0:d62ace65b2b0 | 20 | led[0]=1.0-jacina/100.0; |
tim007 | 0:d62ace65b2b0 | 21 | else if(c=='G') |
tim007 | 0:d62ace65b2b0 | 22 | led[1]=1.0-jacina/100.0; |
tim007 | 0:d62ace65b2b0 | 23 | else if(c=='B') |
tim007 | 0:d62ace65b2b0 | 24 | led[2]=1.0-jacina/100.0; |
tim007 | 0:d62ace65b2b0 | 25 | } |
tim007 | 0:d62ace65b2b0 | 26 | |
tim007 | 0:d62ace65b2b0 | 27 | void ispisiSenzor() |
tim007 | 0:d62ace65b2b0 | 28 | { |
tim007 | 0:d62ace65b2b0 | 29 | printf("TSI: %.2f\n", tsi.readPercentage()); |
tim007 | 0:d62ace65b2b0 | 30 | } |
tim007 | 0:d62ace65b2b0 | 31 | |
tim007 | 0:d62ace65b2b0 | 32 | void ocitaj() |
tim007 | 0:d62ace65b2b0 | 33 | { |
tim007 | 0:d62ace65b2b0 | 34 | char c = pc.getc(); |
tim007 | 0:d62ace65b2b0 | 35 | if(c=='R' || c=='G' || c=='B') |
tim007 | 0:d62ace65b2b0 | 36 | upaliDiodu(c); |
tim007 | 0:d62ace65b2b0 | 37 | if(c=='P') t.attach(ispisiSenzor, 1.0); |
tim007 | 0:d62ace65b2b0 | 38 | if(c=='Z') t.detach(); |
tim007 | 0:d62ace65b2b0 | 39 | } |
tim007 | 0:d62ace65b2b0 | 40 | |
tim007 | 0:d62ace65b2b0 | 41 | int main() { |
tim007 | 0:d62ace65b2b0 | 42 | led[0]=1.0; led[1]=1.0; led[2]=1.0; |
tim007 | 0:d62ace65b2b0 | 43 | pc.attach(ocitaj); |
tim007 | 0:d62ace65b2b0 | 44 | while(1); |
tim007 | 0:d62ace65b2b0 | 45 | } |