With this code you will be able to blink LED1 when you push a graphical button. I use RPC and RTOS librairies on Mbed LPC1768. On python I use mbedRPC, and Tkinter.

Dependencies:   mbed-rpc mbed-rtos mbed

Fork of Blinking_RPC by thomas cassera

Committer:
Thom_cass
Date:
Sun Jul 30 12:06:24 2017 +0000
Revision:
1:589beced7ccc
Parent:
0:fcc2576568f1
With this code you will be able to link a mbed variable to a python variable.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thom_cass 0:fcc2576568f1 1 /*
Thom_cass 0:fcc2576568f1 2 Serial communication between NXP LPC1768 and a PC (Linux), with RPC librairie and a python script
Thom_cass 0:fcc2576568f1 3 */
Thom_cass 0:fcc2576568f1 4
Thom_cass 0:fcc2576568f1 5
Thom_cass 0:fcc2576568f1 6 #include"mbed.h"
Thom_cass 0:fcc2576568f1 7
Thom_cass 0:fcc2576568f1 8 #include "mbed_rpc.h"
Thom_cass 0:fcc2576568f1 9 #include <RPCVariable.h>
Thom_cass 0:fcc2576568f1 10 #include "rtos.h"
Thom_cass 0:fcc2576568f1 11
Thom_cass 0:fcc2576568f1 12 //------------------------init variable-----------------------------------------
Thom_cass 0:fcc2576568f1 13 //------------------------------------------------------------------------------
Thom_cass 0:fcc2576568f1 14 Serial pc(USBTX, USBRX); //serial comm with USB
Thom_cass 0:fcc2576568f1 15
Thom_cass 0:fcc2576568f1 16 DigitalOut Led1(LED1); //Led1 will be use for this example
Thom_cass 0:fcc2576568f1 17
Thom_cass 0:fcc2576568f1 18 int Blink = 0; //init Blink to 0
Thom_cass 0:fcc2576568f1 19 RPCVariable<int> rpc_Blink(&Blink, "Blink_RPC"); //RPCVariable<'FORMAT'> NAME(&'VARIABLE',"ALIAS")
Thom_cass 0:fcc2576568f1 20
Thom_cass 0:fcc2576568f1 21 Thread Serial_thrd; //we will need a thread for serial comm update
Thom_cass 0:fcc2576568f1 22
Thom_cass 0:fcc2576568f1 23 //------------------------------------------------------------------------------
Thom_cass 0:fcc2576568f1 24 void comm_serie()
Thom_cass 0:fcc2576568f1 25 {
Thom_cass 0:fcc2576568f1 26 //The mbed RPC classes are now wrapped to create an RPC enabled version - see RpcClasses.h so don't add to base class
Thom_cass 0:fcc2576568f1 27
Thom_cass 0:fcc2576568f1 28 // receive commands, and send back the responses
Thom_cass 0:fcc2576568f1 29 char buf[256], outbuf[256];
Thom_cass 0:fcc2576568f1 30
Thom_cass 0:fcc2576568f1 31 while(1) {
Thom_cass 0:fcc2576568f1 32 pc.gets(buf, 256);
Thom_cass 0:fcc2576568f1 33 //Call the static call method on the RPC class
Thom_cass 0:fcc2576568f1 34 RPC::call(buf, outbuf);
Thom_cass 0:fcc2576568f1 35 pc.printf("%s\n", outbuf);
Thom_cass 0:fcc2576568f1 36 }
Thom_cass 0:fcc2576568f1 37 }
Thom_cass 0:fcc2576568f1 38
Thom_cass 0:fcc2576568f1 39
Thom_cass 0:fcc2576568f1 40
Thom_cass 0:fcc2576568f1 41 int main()
Thom_cass 0:fcc2576568f1 42 {
Thom_cass 0:fcc2576568f1 43 Serial_thrd.start(comm_serie); //start the serial comm
Thom_cass 0:fcc2576568f1 44
Thom_cass 0:fcc2576568f1 45 while(1)
Thom_cass 0:fcc2576568f1 46 {
Thom_cass 0:fcc2576568f1 47 if(Blink == 0) //if Blink_RPC is 0, then Led1 no blinking
Thom_cass 0:fcc2576568f1 48 {
Thom_cass 0:fcc2576568f1 49 Led1 = 1;
Thom_cass 0:fcc2576568f1 50
Thom_cass 0:fcc2576568f1 51 }
Thom_cass 0:fcc2576568f1 52 else if(Blink ==1) //if BLink_RPC is 1 , then Led1 is blinking
Thom_cass 0:fcc2576568f1 53 {
Thom_cass 0:fcc2576568f1 54 Led1 = 1;
Thom_cass 0:fcc2576568f1 55 wait(0.2);
Thom_cass 0:fcc2576568f1 56 Led1=0;
Thom_cass 0:fcc2576568f1 57 wait(0.2);
Thom_cass 0:fcc2576568f1 58 }
Thom_cass 0:fcc2576568f1 59 }
Thom_cass 0:fcc2576568f1 60 }
Thom_cass 0:fcc2576568f1 61