/* Lien entre un Arduino Nano 33 BLE SENSE et phyphox * * CAPTEUR DE PROXIMITÉ INTÉGRÉ (puce APDS9960) * * Version 33 BLE SENSE (ABX00031) * doc : https://docs.arduino.cc/hardware/nano-33-ble-sense * * Arduino nano + Bluetooth * + capteur IMU = LSM9DS1 * + humidité & température = HTS221 * + pression = LPS22HB * + mouvements et luminosité = APDS9960 * + micro = MP34DT05 * * Basé sur le travail de Gautier Creutzer & Frédéric Bouquet, La Physique Autrement, Laboratoire de Physique des Solides, Université Paris-Saclay * Basé sur la bibli Phyphox Arduinio (phyphox team, the RWTH Aachen University) */ #include #include char board_name[] = "33BLE+SENSE"; // to change the name displayed by the board using BLE: no space and no special character float choice = 0.0; float proximity; unsigned long initial_time, first_time; float first_difference_float; unsigned int period = 50; const int ledPinR = 22; const int ledPinG = 23; const int ledPinB = 24; void receivedData(); // see Phyphox Arduino Library example void setup() { PhyphoxBLE::minConInterval = 6; //6 = 7.5ms PhyphoxBLE::maxConInterval = 6; //6 = 7.5ms PhyphoxBLE::slaveLatency = 0; // PhyphoxBLE::timeout = 10; //10 = 100ms pinMode(22, OUTPUT); pinMode(23, OUTPUT); pinMode(24, OUTPUT); digitalWrite(ledPinR, LOW); digitalWrite(ledPinG, HIGH); digitalWrite(ledPinB, HIGH); // APDS = Mouvement, couleur, lumière if (!APDS.begin()) { while (1); } PhyphoxBLE::start(board_name); // the name of the board can be changed at the beginning of the program PhyphoxBLE::configHandler=&receivedData; // see Phyphox Arduino library example } void loop() // depending on the config parameter sent by Phyphox, an experiment is chosen { Serial.println(PhyphoxBLE::currentConnections); if (PhyphoxBLE::currentConnections > 0){ // VERT = Connecté digitalWrite(ledPinR, HIGH); digitalWrite(ledPinG, LOW); digitalWrite(ledPinB, HIGH); }else{ // ROUGE = Pas de connexion digitalWrite(ledPinR, LOW); digitalWrite(ledPinG, HIGH); digitalWrite(ledPinB, HIGH); } if(choice == 1.0){ proximityChoice(); }else{ } } void receivedData(){ // see Phyphox Arduino Library example if (PhyphoxBLE::currentConnections == 1){ PhyphoxBLE::read(choice); // the "choice" variable is written by our Phyphox experiments initial_time = millis(); } } void proximityChoice() { if (APDS.proximityAvailable()) { first_time = millis(); proximity = APDS.readProximity(); // Read the proximity where: // - 0 => close // - 255 => far // - -1 => error first_difference_float = ((float)first_time-(float)initial_time)/1000; PhyphoxBLE::write(first_difference_float, proximity); // CH1 = temps écoulé // CH2 = proximité (0 à 255, -1 si erreur) } }