Hi !!
Now i made som progress with my remote, i want to send the buttonState with the NRF24 to my reciever, and was wondering if the simplest way is to make an int (buttonState) and send the buttonState 0,1,2,3. I want to use an 300 millis to reset the buttonState to 0 when Noclick.
Is there som function in Moba that is easier to use?
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <MobaTools.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//-----------------------------
#define CE_PIN 7
#define CSN_PIN 8
const byte buttonPins[] = {2};
//-----------------------------
const byte slaveAddress[5] = {'R','x','A','A','A'}; // Radio Adress
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
float dataToSend = 123.456;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 100; // send once per second
//----------------------------
byte function = 1; // function
int buttonState = 0;
//----------------------------
// Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)
// Check I2C device address and correct line below (by default address is 0x29 or 0x28)
// id, address
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
//------------------------------------------------
// create MobaTools objects
MoToButtons myButtons( buttonPins, 1, 20, 3000 ); // manage buttons(s), longpress is 3 seconds
MoToTimebase printTimer; // Timer to print in regular intervals without blocking sketch
//------------------------------------------------
void setup()
{
Serial.begin(9600);
printTimer.setBasetime( 500 ); // print values every second
radio.begin();
radio.setPALevel(RF24_PA_LOW);
//radio.setDataRate( RF24_250KBPS );
radio.setRetries(3,5); // delay, count
radio.openWritingPipe(slaveAddress);
!bno.begin(); // Initialise the sensor
bno.setExtCrystalUse(true); // Initialise the sensor
}
void loop()
{
//------------------------------------------------
sensors_event_t event; // Get a new sensor event
bno.getEvent(&event); // Get a new sensor event
dataToSend = event.orientation.x, 0; // Declare what to send
//------------------------------------------------
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
prevMillis = millis();
}
//------------------------------------------------
myButtons.processButtons();
// select function mode by button presses
if ( myButtons.longPress(0) ) { // Set referecepoint when looking forward and motor is manually positioned forward. (Function 4)
Serial.println( "Longpress" );
function = 4;
buttonState = 3
}
switch ( myButtons.clicked(0) ) {
case NOCLICK:
if ( buttonState > 0 wait reset to 0 every 300ms ? // How do i reset this ir is there an MOBA function to use?
break;
case DOUBLECLICK: // Activate headtracking (Function 3)
Serial.println( "Doubleclick" );
function = 3;
buttonState = 2;
break;
case SINGLECLICK: // Return to refrencepoint (Function 1)
Serial.println( "Singleclick" );
function = 1;
buttonState = 1;
break;
}
if ( printTimer.tick() ) {
// debug printing every second
Serial.print(" HeadTrackAngleRaw: "); Serial.print(event.orientation.x, 0);
Serial.print(" dataToSend "); Serial.print(dataToSend);
Serial.print(" buttonState "); Serial.println(buttonState);
}
}
void send() {
bool rslt;
rslt = radio.write( &dataToSend, sizeof(dataToSend) );
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
}
Best Regards