![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Wireless
Dependencies: C12832 MMA7660 RPCInterface TextLCD mbed
Fork of RPC_Serial by
Diff: main.cpp
- Revision:
- 2:f1553e2737c9
- Parent:
- 1:e245b0b4d96c
--- a/main.cpp Wed May 13 07:42:37 2015 +0000 +++ b/main.cpp Wed May 20 08:24:08 2015 +0000 @@ -1,90 +1,137 @@ -//Uses the measured z-acceleration to drive leds 2 and 3 of the mbed - #include "mbed.h" -//accelerometer header file -#include "MMA7660.h" -//LCD screen header file -#include "C12832.h" //include PRPC command file #include "SerialRPCInterface.h" +//LCD include +#include "TextLCD.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"); +SerialRPCInterface SerieleInterface(USBTX, USBRX); +Serial uart(p9, p10); //tx, rx +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut Pulsout(p28); +DigitalOut Transmit(p8); +AnalogIn Signaalsterkte(p19); +AnalogIn LDRin(p20); +DigitalIn Modepin(p11); +PwmOut PWMLed(p21); +TextLCD lcd(p30, p29, p28, p27, p26, p25, TextLCD::LCD20x4); // rs, e, d4-d7 -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); +char Mode; +float signaal; +int LDR; +char dataRX; +char crcRX; +char adresRX; +int dataOK; +int counter; +int sturen; +char adresTX; +char dataTX; +char crcTX; +int PWMLabview; +int timer; -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() { +RPCVariable<int> rpc_LDR(&LDR,"LDR"); +RPCVariable<float> rpc_signaal(&signaal,"signaal"); +RPCVariable<int> rpc_PWMLabview(&PWMLabview,"PWMLabview"); + +//Prototypes functies +char receive (char adreskarakter); +void transmit(char adresTX, char dataTX); - //clear lcd screen - lcd.cls(); - //update axis period - r.period(0.001); - //test connection to board - if (MMA.testConnection()) - connectionLed = 1; +//******************************************** +//*******************Main********************* +//******************************************** +int main() +{ + PWMLed.period_us(10); + uart.baud(4800); + if (Modepin) + { + myled1 = 1; + myled2 = 0; + Mode = 1; + } + else + { + myled1 = 0; + myled2 = 1; + Mode = 0; + } + lcd.cls(); + timer = 1000; + while (1) + { + //Pin aan GND is Labview + if(Mode == 1) + { + transmit('J',LDRin * 255); + } + else //Labview + { + signaal = (Signaalsterkte * 207); + if(signaal >= 100) + { + signaal = 100; + } + LDR = receive('J'); + + if(timer == 1000) + { + lcd.locate(0,0); + lcd.printf("Signaal: %.0f%c",signaal, 37); + lcd.locate(0,1); + lcd.printf("LDR: %i ",LDR); + timer = 0; + } + timer ++; + } + } +} + +char receive (char adreskarakter) +{ + if(uart.readable()) { + if (counter == 0) + { + adresRX = (uart.getc()); + + if(adresRX == adreskarakter) + { + counter ++; + } + else + { + counter = 0; + } + + } + else if (counter == 1) + { + dataRX = (uart.getc()); + counter ++; + } + else if (counter == 2) + { + crcRX = (uart.getc()); + counter = 0; + } + + if(adresRX == adreskarakter && (adresRX xor dataRX) == crcRX) + { + dataOK = int(dataRX); + } + } + return dataOK; +} + +void transmit(char adresTX, char dataTX) +{ + Transmit = 1; - while(1) { - 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; - } - } + crcTX = (adresTX xor dataTX); + uart.printf("%c%c%c", adresTX, dataTX, crcTX); -} \ No newline at end of file + Transmit = 0; +}