11-19-2023, 08:38 AM
Ηι, Ι try to use an Arduino UNO R4 with a sonar sensor HC-SR04.
I get this error message : Compilation error: 'currentConnections' is not a member of 'PhyphoxBLE'
I send you my code
I get this error message : Compilation error: 'currentConnections' is not a member of 'PhyphoxBLE'
I send you my code
Code:
#include <ArduinoBLE.h>
#include <phyphoxBle.h>
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
char board_name[]="UnoUltraSonic";
unsigned long initial_time, first_time, first_difference_float ;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
pinMode(LED_BUILTIN, OUTPUT);
PhyphoxBLE::minConInterval = 6; //6 = 7.5ms
PhyphoxBLE::maxConInterval = 6; //6 = 7.5ms
PhyphoxBLE::slaveLatency = 0; //
PhyphoxBLE::timeout = 10; //10 = 100ms
PhyphoxBLE::start(board_name); // Το όνομα του board μπορεί να αλλάξει στην αρχή του προγράμματος
PhyphoxBLE::configHandler=&receivedData; // δείτε το παράδειγμα της βιβλιοθήκης Phyphox Arduino library
}
void receivedData(){ // δείτε το παράδειγμα της βιβλιοθήκης Phyphox Arduino library
if (PhyphoxBLE::currentConnections == 1){
initial_time = millis(); //ορίζει την αρχή του χρόνου
}
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
first_time = millis();
first_difference_float = ((float)first_time-(float)initial_time)/1000;
PhyphoxBLE::poll();
PhyphoxBLE::write(first_difference_float, sonar.ping_cm() );
}