
Mbed Code for ECE4180Project
Dependencies: 4DGL-uLCD-SE RPCInterface mbed
Fork of rpc_mbed by
Revision 1:6e3272a3d9d0, committed 2018-05-02
- Comitter:
- bjs9
- Date:
- Wed May 02 03:40:27 2018 +0000
- Parent:
- 0:3c342a2555ef
- Child:
- 2:cf74d941dba8
- Commit message:
- ECE4180MbedProject
Changed in this revision
RGB_LED.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RGB_LED.h Wed May 02 03:40:27 2018 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" + +class RGBLed +{ +public: + RGBLed(PinName redpin, PinName greenpin, PinName bluepin); + void write(float red,float green, float blue); +private: + PwmOut _redpin; + PwmOut _greenpin; + PwmOut _bluepin; +}; + +RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin) + : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin) +{ + //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker) + _redpin.period(0.0005); +} + +void RGBLed::write(float red,float green, float blue) +{ + _redpin = red; + _greenpin = green; + _bluepin = blue; +} +//class could be moved to include file + + +//Sestup RGB led using PWM pins and class \ No newline at end of file
--- a/main.cpp Tue May 01 07:46:31 2018 +0000 +++ b/main.cpp Wed May 02 03:40:27 2018 +0000 @@ -2,6 +2,7 @@ #include "mbed_rpc.h" #include "uLCD_4DGL.h" #include <ctype.h> +#include "RGB_LED.h" /** * This example program has been updated to use the RPC implementation in the new mbed libraries. @@ -11,6 +12,7 @@ //Use the RPC enabled wrapped class - see RpcClasses.h for more info Serial pc(USBTX, USBRX); PinName tx, rx, rst; +RGBLed myRGBled(p22,p23,p24); uLCD_4DGL uLCD(p28, p27, p29); char text; //string screen; @@ -18,8 +20,8 @@ void clearLCD(Arguments *in, Reply *out); RPCFunction rpcClear(&clearLCD, "clearLCD"); -void printLCD(Arguments *in, Reply *out); -RPCFunction rpcPrint(&printLCD, "printLCD"); +void printLCDAndLightRGB(Arguments *in, Reply *out); +RPCFunction rpcPrintLCDAndLightRGB(&printLCDAndLightRGB, "printLCDAndLightRGB"); int main() { @@ -38,9 +40,23 @@ //out->putData("Successfully created uLCD object!"); } -void printLCD(Arguments *in, Reply *out) +void printLCDAndLightRGB(Arguments *in, Reply *out) { + uLCD.cls(); char * text = in->getArg<char *>(); - uLCD.puts(text); - uLCD.puts("\n"); + int value = strlen(text); + if(text[0] == '1'){ + myRGBled.write(0,1.0f,0); + uLCD.printf("Tweet is found!\n"); + uLCD.printf("\n"); + } else if(text[0] == '0'){ + myRGBled.write(0,0,1.0f); + } + text[0] = '-'; + for(int i = 0; i< value; i++) { + if(text[i] == '|') { + text[i] = ' '; + } + } + uLCD.printf(text); } \ No newline at end of file