Introduction: LC-2000(PA)-P2P Remote Control

This document gives an example of how to control the LED by PC, and solve some of the doubts raised, I will also do a video uploaded to the Internet, welcome Click to watch.

Step 1: System Structure

In this dome, we didn’t change the hardware connection, we just change the way we control the LED pin.

There are two issues must first explain. First, about the pair, in previous demo, we use the modules that we have paired, so there are some phenomena that you can’t see, so I make this dome to show you clearly.

before the module been paired, the power indicator light is lighting , so you can clearly distinguish the status of the module.

Then we press the pairing button on the Master-side, it turn to the pairing state, press again, the module turn out of the pairing state. Similarly, we have to look at the changes in Slave-side.

So when there is no connection,Light stays on.

Pairing is completed, the lamp of the two sides are light off.

In the way, How can we distinguish whether the pairing is is succeed or not?

It’s very simple, just press the DTR button of Master, if the reset lamp of the UNO Core is flashing, the paring is succeed.

it's the first issue I want to tell you.

Step 2:

The second issues is about the upload. The RF-UNO-CORE can upload by wired upload or wireless upload. The Precaution is when you upload by wired, you can’t use the wireless way, and the wireless connect must be disconnect, or when you upload by wireless way, the UC-2102 witch connected on the UNO-CORE must be remove, all in all, you just can choose one way to upload and the other connection must be disconnect. Here's a little trick, when you set the UNO-CORE to pair mode, the wireless connection is be destroyed, so you can upload by wired way.

It's a little convoluted but I'm sure you can understand.

Step 3: The Demo

Now, we start our demo. First, we connect a LED on 5 feet.

Then, we analysis the code, first, define the LED pin, we didn’t use the Timer library, we use the serial value to control the LED.

The variables we use in the demo, most of them are the serial variables.

The set up function, initialize the LED pin’s state and initialize the serial port baud rate, set the baud rate to 115200bps.

In the loop function, we just need to call the LED control function.

When the timer count value over, we will flip LED.

The code is shared in the last, so let we upload the program.

Step 4: The Serial Debugging Tool's Sets

Open serial debugging tool and set the following sets.

ComNum is set to the port of UC-2102.

Set the baud rate to 115200bps.

Be sure you have tick “SendNew”.

Finally, fill the send data “SET_LED”, click send, and you will find the LED is in you control.

Well, the demo is done, and we wait for you to join.

Step 5: The Code

#define PIN_LED 5

bool g_PktFristFlag = false;

bool g_PktRecvFlag = false;

char g_LedState = false;

unsigned int g_RecvCount = 0;

char g_RecvBuff[80];

void setup() {

// put your setup code here, to run once:

pinMode( PIN_LED, OUTPUT );

digitalWrite( PIN_LED, LOW );

Serial.begin(115200);

}

void loop() {

// put your main code here, to run repeatedly:

ledSet();

}

void serialEvent() {

while ( Serial.available() ) {

char inChar = Serial.read();

if ( inChar == '\r' ) {

g_PktFristFlag = true;

}

else if ( inChar == '\n' ) {

if ( g_PktFristFlag ) {

g_RecvBuff[g_RecvCount] = '\0';

g_PktRecvFlag = true;

}

}

else {

g_RecvBuff[g_RecvCount++] = inChar;

}

}

}

void ledSet(){

if(g_PktRecvFlag){

g_PktRecvFlag = false;

g_PktFristFlag = false;

ReadCommand();

g_RecvCount = 0;

}

}

void ReadCommand() {

char *pString = (char *)&g_RecvBuff[0];

char *masterStr = "";

unsigned int masterNum;

if ( 0 == strncmp( pString, "SET_LED", 7 ) ) {

g_LedState = !g_LedState;

if ( g_LedState ) {

digitalWrite( PIN_LED, HIGH );

}

else {

digitalWrite( PIN_LED, LOW );

}

}

}

Step 6: There Is the Video

if you want to know more about the LC-2000 series, please click:www.inhaos.com