Zlatan Čilić Lejla Agić

Dependencies:   TSI mbed

main.cpp

Committer:
tim004
Date:
2014-05-12
Revision:
0:5cb9ff1b9c43

File content as of revision 0:5cb9ff1b9c43:

#include "mbed.h"
#include "TSISensor.h"
#include <string>

PwmOut crvena(LED1);
PwmOut zelena(LED2);
PwmOut plava(LED3);
Serial pc(USBTX, USBRX);
TSISensor tsi;
Ticker tsiTicker;
string buffer;
bool citanjeTSI(false);


void ocitajPC()
{
    while(pc.readable())
    {
        buffer.push_back(pc.getc());
    }
}

void ispisiTSI()
{
        pc.printf("%f\n", tsi.readPercentage());
}

void ocitajIzvrsi()
{
        //ocitajPC();
        
        buffer.push_back(pc.getc());
        if(buffer[0] == 'P')
        {
             tsiTicker.attach(&ispisiTSI, 1.0);
             buffer = "";
             return;
             //pc.printf("\n");
         }
        if(buffer[0] == 'Z')
        {
             tsiTicker.detach();
             buffer = "";
             return;
             // pc.printf("\n"); 
        }
        
        if(buffer[0] == 'R' || buffer[0] == 'G' || buffer[0] == 'B')
        {
           buffer.push_back(pc.getc());
           if(buffer[1] < '0' || buffer[1] > '9')
           {
                buffer = "";
                return;
            }
            buffer.push_back(pc.getc());
           if(buffer[2] < '0' || buffer[2] > '9')
           {
                buffer = "";
                return;
            }               
            
            float intenzitet(0);
            intenzitet = ((buffer[1] - '0') * 0.1 + (buffer[2] - '0') * 0.01);
            if(buffer[0] == 'R')
            {
                crvena = 1-intenzitet;
                zelena = 1;
                plava = 1;
            }
            else if(buffer[0] == 'G')
            {
                crvena = 1;
                zelena = 1-intenzitet;
                plava = 1;
            }
            else
            {
                crvena = 1;
                zelena = 1;
                plava = 1-intenzitet;
            }   
               
               
               
               
               buffer = "";
                return;
            }
        
        
        
        buffer = "";
        
        
}




 
int main() {
    plava = 1;
    crvena = 1;
    zelena = 1;
    while(1)
    {
        ocitajIzvrsi();
    }
       
}