I'm working on a project in which I'm making two dolls. Suppose there are two people, one holding each doll. When one person hugs his doll, the other doll will move its arms to hug the other person. If the other person hugs the doll back, then the first doll will hug the first person, and so on and so forth.
I'm using servos to control the arm rotations and FSRs to sense the force of the hugging. I'll also be using a Lilypad to control each doll. I've got that part covered, pretty much. However, I'm using nRF24L01+ transceivers to make the Lilypads communicate with each other. I've made the transceivers work, using this tutorial: Getting Started with nRF24L01+ on Arduino | maniacbug and the RF24 library. However, I'm not sure how to make the transceivers communicate specific commands to each other. I want to make it so that when the FSRs in one doll reach a specific threshold, the transceiver tells the servos in the other doll to move. How would I go about doing that?
If you only ever want to trigger one action, then it doesn't matter what you send; the receipt of any message could be taken as the command to do the action.
The nRF24L01+ transceivers are bidirectional so you would have identical code on both sides which are configured in some way to tell each one which address to use. That could be by a value saved in EEPROM, or an input pin pulled low by a jumper. However you do it, you need to give each Arduino some way to figure out which one it is out of the pair.
Each Arduino will listen to the RF24 interface. If it receives a message, it carries out the action. Each Arduino will also poll the FSR at regular intervals; if it detects a 'hug' then it will stop listening to the radio, send a message to the other Arduino and resume listening again.
The nRF24L01+ transceivers are bidirectional so you would have identical code on both sides which are configured in some way to tell each one which address to use. That could be by a value saved in EEPROM, or an input pin pulled low by a jumper. However you do it, you need to give each Arduino some way to figure out which one it is out of the pair.
Each Arduino will listen to the RF24 interface. If it receives a message, it carries out the action. Each Arduino will also poll the FSR at regular intervals; if it detects a 'hug' then it will stop listening to the radio, send a message to the other Arduino and resume listening again.
How exactly would I do all of that? I've managed to get the transceivers communicating with each other, but I just don't know how to get them to do specific things.
If that tests TRUE, it means it received "something" which you could use by itself to trigger your action. Or if you need to know what 'something' is:
OK = radio.read( something, len_something);
OK will just be an indactor that read was successful. But len_something number of bytes received will be in variable something.
on the transmit side:
bool ok = radio.write( something, len_something );
Of course, there is a bit more to it than that, but that is the core of it. You send something on one side, and receive it on the other. Look at the led_remote example in the RF24 library