Hello.
I'm doing a project that uses a flex sensor to trigger a push-pull solenoid by distance by using an NFR24L01 radio transceiver and two Arduino Nano.
Now the sensor and the radio transceiver work find but while I'm flexing the sensor it sends a batch of messages in continue. I just want the solenoid to be triggered once when the sensor is bent like if it was one off button.
I know that my code is wrong but i tried to understand the While, For, and Boolean variable and fonction unsuccessfully (It's hard for me because english is not my first language).
I will be very recognizing if someone can guide me! Thanks.
There is my code :
#include <SPI.h>
#include <printf.h>
#include <nRF24L01.h>
#include <RF24_config.h>
#include <RF24.h>
#define pinCE 7
#define pinCSN 8
#define tunnel "PIPE1"
RF24 radio(pinCE, pinCSN);
const byte adresse[6] = tunnel;
const char message[] = "Encore tomber";
const int FLEX_PIN = A0;
const float VCC = 4.98;
const float R_DIV = 47500.0;
const float STRAIGHT_RESISTANCE = 37300.0;
const float BEND_RESISTANCE = 90000.0;
void setup() {
Serial.begin(9600);
pinMode(FLEX_PIN, INPUT);
radio.begin();
radio.openWritingPipe(adresse);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_1MBPS);
radio.stopListening();
}
void loop() {
int flexADC = analogRead(FLEX_PIN);
float flexV = flexADC * VCC / 1023.0;
if (flexV < 2.50)
{ }
else
{
Serial.println("Hello world");
radio.write(&message, sizeof(message));
}
}