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"