Bonjour,
J'utilise deux codes différents, le schéma électrique reste le même mais il y a une nette différence de temps d'acquisition des input par l'arduino.
Le code rapide est celui-là
#include <CapacitiveSensor.h>
//ce code va de pair avec un circuit ayant une résistance totale pour le capteur de 7MOhms
const int NombreLEDTotal = 10; // the number of LEDs in the bar graph
const long numReadings = 10;
int PotarSeuilHaut = A1;
int ledPins[] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // an array of pin numbers to which LEDs are attached
long readings[numReadings];
long index = 0;
long total = 0;
long valeurMoyenne = 0;
CapacitiveSensor BPtactile = CapacitiveSensor(3,2);
void setup() {
// loop over the pin array and set them all to output:
BPtactile.set_CS_AutocaL_Millis(0xFFFFFFFF);
Serial.begin(115200);
for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0;
for (int LEDActuelle = 0; LEDActuelle < NombreLEDTotal; LEDActuelle++) {
pinMode(ledPins[LEDActuelle], OUTPUT);
}
pinMode(PotarSeuilHaut,INPUT);
}
void loop() {
int SeuilHaut;
SeuilHaut = analogRead(PotarSeuilHaut);
int mapSeuilHaut;
mapSeuilHaut = map(SeuilHaut,0,1023,100,30000);
long start = millis();
long total1 = BPtactile.capacitiveSensor(30);
total = total - readings[index];
readings[index] = total1;
total = total + readings[index];
index = index + 1;
if (index >= numReadings){
index = 0;
}
valeurMoyenne = total / numReadings;
Serial.print(millis() - start);
Serial.print("\t");
Serial.print("Seuil Haut : ");
Serial.print(SeuilHaut);
Serial.print("\t");
Serial.print("valeur moyenne : ");
Serial.println(valeurMoyenne);
delay(10);
int sensibiliteCapteur = valeurMoyenne;
int NiveauDeLED = map(sensibiliteCapteur, 0, mapSeuilHaut, 0, NombreLEDTotal);
Serial.print("\t");
Serial.print("nombre de LED : ");
Serial.print(NiveauDeLED);
for (int LEDActuelle = 0; LEDActuelle < NombreLEDTotal; LEDActuelle++) {
if (LEDActuelle < NiveauDeLED) {
digitalWrite(ledPins[LEDActuelle], LOW);
}
else { digitalWrite(ledPins[LEDActuelle], HIGH);
}
}
}
Et ça donne ça sur le moniteur

Tandis que le lent c'est celui-ci
#include <CapacitiveSensor.h>
const int EVBuse = 5;
CapacitiveSensor capSenseBPBuse = CapacitiveSensor(3,2);
CapacitiveSensor capSenseATGen = CapacitiveSensor(11,13);
bool etatBPBuse = false;
int long total1 = 0;
int long ATGen = 0;
byte autorisationBuse = 0;
byte etatPrecedentBPBuse = 0;
byte allumageBuse = 0;
const long numReadings = 10;
long readings[numReadings];
long index = 0;
long total = 0;
long valeurMoyenne = 0;
void setup() {
pinMode(EVBuse, OUTPUT);
PORTD &=~ _BV(PD5);
for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0;
Serial.begin(115200);
}
void loop() {
//lissage mesure du capteur
long start = millis();
long total1 = capSenseBPBuse.capacitiveSensor(30);
total = total - readings[index];
readings[index] = total1;
total = total + readings[index];
index = index + 1;
if (index >= numReadings){
index = 0;
}
valeurMoyenne = total / numReadings;
Serial.print("\t valeur moyenne : ");
Serial.print(valeurMoyenne);
int seuil = 50;
if(valeurMoyenne > seuil){
etatBPBuse = true;
}
else{
etatBPBuse = false;
}
delay(1);
if(etatBPBuse != etatPrecedentBPBuse){
if(etatBPBuse == true){
allumageBuse = !allumageBuse;
}
if(allumageBuse == 1){
PORTD |= _BV(PD5);
}
else{
PORTD &=~ _BV(PD5);
}
}
etatPrecedentBPBuse = etatBPBuse;
ATGen = capSenseATGen.capacitiveSensor(30);
if(ATGen > seuil){
PORTD &=~ _BV(PD5);
}
Serial.print("\t etatBPBuse : ");
Serial.print(etatBPBuse);
Serial.print("\t allumageBuse : ");
Serial.println(allumageBuse);
delay (10);
}
Et ça donne ça :

J'ai beau avoir mis la même vitesse d'acquisition du port Serial à 115200 ça ne change rien. Le code lent c'est juste le code rapide mais avec une fonction d'auto-maintient et d'allumage/extinction de la LED avec un même bouton.