Trouble with wireless relay control project

I’ve kind of had this project on the back burner for a while, can’t quite seem to figure out the loops in the example code for the nordic fob.
Basically heres my goal. I have the following parts
arduino uno

My goal is to plan on using the remote to turn the dust collector in my wood shop on and off. I have run the example code for the nordic fob and have it working, it reads to serial which button i hit (up, down, L, R) and the relay is easy to use, it works well, but I can’t seem to get them working a the same time.
My problem is something to do with how the code works for the nordic fob. The code has a main loop that constantly searches for a signal and then prints what the signal is. I’ve gotten the relay to work if i place some code inside the loop to set a pin high but only as long as I run a delay after that before the loop continues.
I would really like to implement some form of counter so that if i hit the button is sets the counter to 1 and as long as its 1 the pin is high and if i hit the button again (or possibly a different button) then the counter is set to zero and the pin is set to low.
since most of you are probably better than me at coding I was wondering what advice you might have to fix my problem
here is the example code that runs

"/* Copyright (C) 2012 J. Coliz maniacbug@ymail.com
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */
/** * Example Nordic FOB Receiver * * This is an example of how to use the RF24 class to receive signals from the * Sparkfun Nordic FOB. Thanks to Kirk Mower for providing test hardware. * * See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/ */
include <SPI.h>
include <RF24.h>
include "nRF24L01.h"
include "printf.h"
// // Hardware configuration //
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
// // Payload //
struct payload_t { uint8_t buttons; uint16_t id; uint8_t empty; };
const char* button_names[] = { "Up", "Down", "Left", "Right", "Center" }; const int num_buttons = 5;
// // Forward declarations //
uint16_t flip_endian(uint16_t in);
// // Setup //
void setup(void) { // // Print preamble //
Serial.begin(57600); printf_begin(); printf("\r\nRF24/examples/nordic_fob/\r\n");
// // Setup and configure rf radio according to the built-in parameters // of the FOB. //
radio.begin(); radio.setChannel(2); radio.setPayloadSize(4); radio.setAutoAck(false); radio.setCRCLength(RF24_CRC_8); radio.openReadingPipe(1,0xE7E7E7E7E7LL);
// // Start listening //
radio.startListening();
// // Dump the configuration of the rf unit for debugging //
radio.printDetails(); }
// // Loop //
void loop(void) { // // Receive each packet, dump it out //
// if there is data ready
if ( radio.available() )
{
  // Get the packet from the radio
  payload_t payload;
  radio.read( &payload, sizeof(payload) );

  // Print the ID of this message.  Note that the message
  // is sent 'big-endian', so we have to flip it.
printf("#%05u Buttons ",flip_endian(payload.id));
// Print the name of each button int i = num_buttons; while (i--) { if ( ! ( payload.buttons & _BV(i) ) ) { printf("%s ",button_names[i]); } }
// If no buttons, print None if ( payload.buttons == _BV(num_buttons) - 1 ) printf("None");
printf("\r\n"); } }
// // Helper functions //
// Change a big-endian word into a little-endian uint16_t flip_endian(uint16_t in) { uint16_t low = in >> 8; uint16_t high = in << 8;
return high | low; }
// vim:cin:ai:sts=2 sw=2 ft=cpp"

I have run the example code for the nordic fob and have it working, it reads to serial which button i hit (up, down, L, R)

It reads to serial? Generally, people read FROM or PRINT to the Serial Monitor.

here is the example code that runs

Comments don't need // on the end.

White space and proper indentation are needed.

One code statement per line.

That code is nearly impossible to read.

And, to top it off, it isn't the code you are having problems with. So, why did you post it?

I was wondering what advice you might have to fix my problem

Ok. Start by making the code readable.

Then, understand what the code is doing.

Then, make it do what you want (setting flags, etc.) at the appropriate time.

Then, after all the stuff with the radio traffic being dealt with, add some code to toggle, or not, the pins based on the flags.

The posted code doesn't even compile. There must have been a problem with newline conversion while copy-n-pasting. Look at the double quote at the beginning and the vim signature at the end.

I apologize for the issues pasting the code. I will double check it in a little bit and repost. I thought that it was copied and pasted from running code on my computer so it should be working.

ok, I double checked this. My code was this example sketch, I was hoping to be able to modify this sketch to do what i was wanting.

http://maniacbug.github.com/RF24/nordic_fob_8pde-example.html

here is the link to the main index for the rf24 library http://maniacbug.github.com/RF24/index.html

and this sketch runs (the nordic fob one) But i'm having a little trouble with how this system gathers data, I want to set it so there is a counter such that I can turn a relay or just an led to make things simpler on and off using the remote.

      // Print the name of each button 
      int i = num_buttons;
      while (i--)
      {
        if ( ! ( payload.buttons & _BV(i) ) )
        {
          printf("%s ",button_names[i]);
        }
      }

In here, in addition to printing the button name, set a flag to true if the button of interest is pressed/printed.

      printf("\r\n");
    }
}

In between the curly braces is the part that is "after all the stuff with the radio traffic being dealt with", so that is where you put the code to do whatever you want to do, based on the flag being set/cleared.

Thanks a bunch, I really for some reason have trouble keeping track of all of the loops. Took only a few minutes to get my code working after your help.

I did a writeup on this project if anyone was curious http://diyourfaceoff.com/diy-dust-collector-remote/

Stevovee,

Thank you so much. I've been working on a similar project and this is exactly the code I needed to get me going in the right direction.

Nick