Aida Pločo Tarik Demirović

Dependencies:   TSI mbed

Committer:
tim003
Date:
Mon May 05 07:35:49 2014 +0000
Revision:
0:31590ed52245
LV8-Grupa1-Tim003-Zadatak1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tim003 0:31590ed52245 1 #include "mbed.h"
tim003 0:31590ed52245 2 #include "TSISensor.h"
tim003 0:31590ed52245 3
tim003 0:31590ed52245 4 PwmOut r(LED1);
tim003 0:31590ed52245 5 PwmOut g(LED2);
tim003 0:31590ed52245 6 PwmOut b(LED3);
tim003 0:31590ed52245 7
tim003 0:31590ed52245 8 Serial pc(USBTX, USBRX);
tim003 0:31590ed52245 9
tim003 0:31590ed52245 10 TSISensor tsi;
tim003 0:31590ed52245 11 Ticker t1;
tim003 0:31590ed52245 12
tim003 0:31590ed52245 13 char buf[150];
tim003 0:31590ed52245 14 int i = 0;
tim003 0:31590ed52245 15
tim003 0:31590ed52245 16 void ispisiTSI()
tim003 0:31590ed52245 17 {
tim003 0:31590ed52245 18 pc.printf("\nTSI: %f", tsi.readPercentage());
tim003 0:31590ed52245 19 }
tim003 0:31590ed52245 20
tim003 0:31590ed52245 21 void upaliLedicu(char ledica, float intenzitet)
tim003 0:31590ed52245 22 {
tim003 0:31590ed52245 23 if(ledica == 'R')
tim003 0:31590ed52245 24 {
tim003 0:31590ed52245 25 r = 1.0 - intenzitet;
tim003 0:31590ed52245 26 g = 1.0;
tim003 0:31590ed52245 27 b = 1.0;
tim003 0:31590ed52245 28 }
tim003 0:31590ed52245 29
tim003 0:31590ed52245 30 if(ledica == 'G')
tim003 0:31590ed52245 31 {
tim003 0:31590ed52245 32 r = 1.0;
tim003 0:31590ed52245 33 g = 1.0 - intenzitet;
tim003 0:31590ed52245 34 b = 1.0;
tim003 0:31590ed52245 35 }
tim003 0:31590ed52245 36
tim003 0:31590ed52245 37 if(ledica == 'B')
tim003 0:31590ed52245 38 {
tim003 0:31590ed52245 39 r = 1.0;
tim003 0:31590ed52245 40 g = 1.0;
tim003 0:31590ed52245 41 b = 1.0 - intenzitet;
tim003 0:31590ed52245 42 }
tim003 0:31590ed52245 43 }
tim003 0:31590ed52245 44
tim003 0:31590ed52245 45 void ocitaj()
tim003 0:31590ed52245 46 {
tim003 0:31590ed52245 47
tim003 0:31590ed52245 48 buf[i] = pc.getc();
tim003 0:31590ed52245 49 i++;
tim003 0:31590ed52245 50
tim003 0:31590ed52245 51
tim003 0:31590ed52245 52 if((buf[0] == 'R' or buf[0] == 'G' or buf[0] == 'B') and buf[1] >= '0' and buf[1] <= '9' and buf[2] >= '0' and buf[2] <= '9' and i == 3)
tim003 0:31590ed52245 53 {
tim003 0:31590ed52245 54 char ledica = buf[0];
tim003 0:31590ed52245 55 float intenzitet = ((buf[1] - 48)*10 + buf[2] - 48)/100.0;
tim003 0:31590ed52245 56 upaliLedicu(ledica, intenzitet);
tim003 0:31590ed52245 57 i = 0;
tim003 0:31590ed52245 58 }
tim003 0:31590ed52245 59
tim003 0:31590ed52245 60 if(buf[0] == 'P' and i == 1)
tim003 0:31590ed52245 61 {
tim003 0:31590ed52245 62 i = 0;
tim003 0:31590ed52245 63 t1.attach(&ispisiTSI, 1);
tim003 0:31590ed52245 64 }
tim003 0:31590ed52245 65
tim003 0:31590ed52245 66 if(buf[0] == 'Z' and i == 1)
tim003 0:31590ed52245 67 {
tim003 0:31590ed52245 68 i = 0;
tim003 0:31590ed52245 69 t1.detach();
tim003 0:31590ed52245 70 }
tim003 0:31590ed52245 71 }
tim003 0:31590ed52245 72
tim003 0:31590ed52245 73 int main() {
tim003 0:31590ed52245 74 r = 1.0;
tim003 0:31590ed52245 75 g = 1.0;
tim003 0:31590ed52245 76 b = 1.0;
tim003 0:31590ed52245 77 pc.attach(&ocitaj);
tim003 0:31590ed52245 78 }