Wireless
Dependencies: C12832 MMA7660 RPCInterface TextLCD mbed
Fork of RPC_Serial by
Diff: main.cpp
- Revision:
- 1:e245b0b4d96c
- Parent:
- 0:3ffd66df9efb
- Child:
- 2:f1553e2737c9
diff -r 3ffd66df9efb -r e245b0b4d96c main.cpp --- a/main.cpp Sat Apr 21 00:47:46 2012 +0000 +++ b/main.cpp Wed May 13 07:42:37 2015 +0000 @@ -1,25 +1,90 @@ +//Uses the measured z-acceleration to drive leds 2 and 3 of the mbed + #include "mbed.h" -#include "rpc.h" -Serial pc(USBTX, USBRX); -int main() { - // setup the classes that can be created dynamically - Base::add_rpc_class<AnalogIn>(); - Base::add_rpc_class<AnalogOut>(); - Base::add_rpc_class<DigitalIn>(); - Base::add_rpc_class<DigitalOut>(); - Base::add_rpc_class<DigitalInOut>(); - Base::add_rpc_class<PwmOut>(); - Base::add_rpc_class<Timer>(); - Base::add_rpc_class<SPI>(); - Base::add_rpc_class<BusOut>(); - Base::add_rpc_class<BusIn>(); - Base::add_rpc_class<BusInOut>(); - Base::add_rpc_class<Serial>(); - // receive commands, and send back the responses - char buf[256], outbuf[256]; +//accelerometer header file +#include "MMA7660.h" +//LCD screen header file +#include "C12832.h" +//include PRPC command file +#include "SerialRPCInterface.h" + +//default pin connections for LCD +C12832 lcd(p5, p7, p6, p8, p11); +//default pins for accelerometer +MMA7660 MMA(p28, p27); +// +float X = 0; +float Y = 0; +float Z = 0; +float ai1=0; +float ai2=0; +int alarm1 = 0; +int alarm2 = 0; +RPCVariable<float> rpc_ai1(&ai1,"ai1"); + +RPCVariable<float> rpc_ai2(&ai2,"ai2"); + +RPCVariable<int> rpc_alarm1(&alarm1,"alarm1"); +RPCVariable<int> rpc_alarm2(&alarm2,"alarm2"); +AnalogIn pot2(p19); +DigitalOut led(LED1); +AnalogIn pot1(p20); +DigitalOut led2(LED2); + +RPCVariable<float> RPCX(&X, "X"); +RPCVariable<float> RPCY(&Y, "Y"); +RPCVariable<float> RPCZ(&Z, "Z"); +SerialRPCInterface SerieleInterface(USBTX, USBRX); +DigitalOut connectionLed(LED1); +//pwm led 1 and 2 +PwmOut Zaxis_p(LED2); +PwmOut Zaxis_n(LED3); +//pwm signals for RGB LED +PwmOut r (p23); +PwmOut g (p24); +PwmOut b (p25); + +int main() { + + //clear lcd screen + lcd.cls(); + //update axis period + r.period(0.001); + //test connection to board + if (MMA.testConnection()) + connectionLed = 1; + while(1) { - pc.gets(buf, 256); - rpc(buf, outbuf); - pc.printf("%s\n", outbuf); + Zaxis_p = MMA.z(); + Zaxis_n = -MMA.z(); + r = MMA.x(); + g = MMA.y(); + b = MMA.z(); + lcd.locate(0,0); + lcd.printf("X as : %.2f", MMA.x()); + lcd.locate(0,10); + lcd.printf("Y as : %.2f", MMA.y()); + lcd.locate(0,20); + lcd.printf("Z as : %.2f", MMA.z()); + X = MMA.x(); + Y = MMA.y(); + Z = MMA.z(); + ai1 = pot2; + ai2 = pot1; + if(pot2 > 0.3) { + led = 1; + alarm1 = led; + } else { + led = 0; + alarm1 = led; + } + if(pot1 > 0.7) { + led2 = 1; + alarm2 = led2; + } else { + led2 = 0; + alarm2 = led2; + } } -} + +} \ No newline at end of file