mirror of
https://github.com/AlbiYourBestFriend/hackathon2025.git
synced 2025-10-29 14:35:59 +00:00
rendu git
This commit is contained in:
parent
612613484b
commit
7a204b2ddd
67
Arduinoscript/Arduinoscript.ino
Normal file
67
Arduinoscript/Arduinoscript.ino
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include <Arduino_HS300x.h>
|
||||||
|
#include <Arduino_APDS9960.h>
|
||||||
|
#include <HCSR04.h>
|
||||||
|
#include <PDM.h>
|
||||||
|
|
||||||
|
#define SAMPLE_BUFFER_SIZE 512
|
||||||
|
short sampleBuffer[SAMPLE_BUFFER_SIZE];
|
||||||
|
volatile int samplesRead = 0;
|
||||||
|
static const char channels = 1;
|
||||||
|
static const int frequency = 16000;
|
||||||
|
|
||||||
|
// Ultrasonic instructions
|
||||||
|
byte triggerPin = 11;
|
||||||
|
byte echoPin = 12;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
if (!HS300x.begin()) {
|
||||||
|
Serial.println("Failed to initialize humidity temperature sensor!");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
PDM.onReceive(onPDMdata);
|
||||||
|
if (!PDM.begin(channels, frequency)) {
|
||||||
|
Serial.println("Failed to start PDM!");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
HCSR04.begin(triggerPin, echoPin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
float temperature = HS300x.readTemperature();
|
||||||
|
int volume = getVolume();
|
||||||
|
double* distances = HCSR04.measureDistanceCm();
|
||||||
|
String output = String(temperature) + "|" + String(distances[0]) + "|" + String(volume);
|
||||||
|
Serial.println(output);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getVolume()
|
||||||
|
{
|
||||||
|
int maxVolume = 0; // Initialize variable to store the maximum volume
|
||||||
|
int sum = 0;
|
||||||
|
|
||||||
|
if (samplesRead > 0) {
|
||||||
|
for (int i = 0; i < samplesRead; i++) {
|
||||||
|
int sampleAbs = abs(sampleBuffer[i]);
|
||||||
|
if (sampleAbs > maxVolume) {
|
||||||
|
maxVolume = sampleAbs; // Update max volume if a higher value is found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
samplesRead = 0; // Reset after processing
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPDMdata()
|
||||||
|
{
|
||||||
|
int bytesAvailable = PDM.available();
|
||||||
|
if (bytesAvailable) {
|
||||||
|
PDM.read(sampleBuffer, bytesAvailable);
|
||||||
|
samplesRead = bytesAvailable / 2; // Update the number of samples read
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,4 +17,7 @@ JS library (server):
|
|||||||
- socket-io (permet de communiquer entre serveur et client grace a des events)
|
- socket-io (permet de communiquer entre serveur et client grace a des events)
|
||||||
- socket-io-client
|
- socket-io-client
|
||||||
- express (un framework basés sur les applications web)
|
- express (un framework basés sur les applications web)
|
||||||
- node:http
|
- node:http
|
||||||
|
|
||||||
|
|
||||||
|
Cablage arduino : 
|
||||||
BIN
img/cable.png
Normal file
BIN
img/cable.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue
Block a user