tim008 tim008
/
LV08Z1_Tim008_Z1
Muslija Adnan Kiselica Aldin
Revision 0:178f5b5b629c, committed 2014-05-05
- Comitter:
- tim008
- Date:
- Mon May 05 07:32:37 2014 +0000
- Commit message:
- LV8_PAI_Tim008_Z1
Changed in this revision
diff -r 000000000000 -r 178f5b5b629c TSI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TSI.lib Mon May 05 07:32:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 000000000000 -r 178f5b5b629c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 05 07:32:37 2014 +0000 @@ -0,0 +1,104 @@ +#include "mbed.h" +#include "TSISensor.h" +#include <string> + +DigitalOut myled(LED1); + +Serial pc(USBTX, USBRX); + +PwmOut led1(LED1); +PwmOut led2(LED2); +PwmOut led3(LED3); + +string input; + +Ticker ticker; + +TSISensor tsi; + +void displayTSI() +{ + pc.printf("%f\n",tsi.readPercentage()); +} + +void turnOnLed(char color, int ipct) +{ + if(color!='R' && color!='G' && color!='B') + return; + pc.printf("%d\n",ipct); + led1=1; + led2=1; + led3=1; + float pct=float(ipct)/100; + + if(color=='R') + led1=1-pct; + else if(color=='G') + led2=1-pct; + else + led3=1-pct; +} + +void readFromPC() +{ + while(pc.readable()) + { + input.push_back(pc.getc()); + } +} + +void clearBuffer() +{ + input=""; +} + +void executeInstruction() +{ + int pct=0; + if(input.length()>3) + { + clearBuffer(); + return; + } + if(input.length()>=1) + if(input[input.length()-1]==13) + { + clearBuffer(); + printf("\r"); + } + if(input.length()==3){ + if((input[0]=='R' || input[0]=='G' || input[0]=='B') && input[1]>='0'&&input[1]<='9' && input[2]>='0'&&input[2]<='9') + { + pct=(input[1]-'0')*10+(input[2]-'0'); + turnOnLed(input[0],pct); + clearBuffer(); + pc.printf("\n"); + } + } + else if(input.length()==1){ + if(input[0]=='P') + { + ticker.attach(displayTSI,1.0); + pc.printf("\n"); + clearBuffer(); + } + else if(input[0]=='Z') + { + ticker.detach(); + pc.printf("\n"); + clearBuffer(); + } + + } +} + + +int main(){ + led1=1; + led2=2; + led3=3; + while(1) { + readFromPC(); + executeInstruction(); + } +}
diff -r 000000000000 -r 178f5b5b629c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 05 07:32:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776 \ No newline at end of file