[Conseil] Aide pour ordre val = 5

Bonjour , j'aimerais qu'avec mon arduino que lorsqu'elle recoit 3 fois 1 en 30 seconde sur une broche (D9) elle affiche sur le moniteur un 1.

Voici le programme de base

/*******************************************************************************/

/*macro definitions of magnetic pin and LED pin*/
#define MAGNECTIC_SWITCH 9
#define LED	13//the on board LED of the Arduino or Seeeduino

void setup()
{
 	pinMode(MAGNECTIC_SWITCH, INPUT);
	pinMode(LED,OUTPUT);
}
 
void loop() 
{
	if(isNearMagnet())//if the magnetic switch is near the magnet?
	{
		digitalWrite(LED,HIGH);
	}
	else
	{
		digitalWrite(LED,LOW);
	}
}


/*If the magnetic switch is near the magnet, it will return ture, */
/*otherwise it will return false								*/
boolean isNearMagnet()
{
	int sensorValue = digitalRead(MAGNECTIC_SWITCH);
	if(sensorValue == HIGH)//if the sensor value is HIGH?
	{
		return true;//yes,return ture
	}
	else
	{
		return false;//no,return false
	}
}

Oui c'est un capteur magnetic mais voila sa changer pas grande chose au programme

Et la c'est ce que j'ai tenter de faire mais sa ne marche pas

/*******************************************************************************/
const int MAGNECTIC_SWITCH = 9;    
const int LED =  13;
/*macro definitions of magnetic pin and LED pin*/

 int x;

long previousMillis = 0; 

void setup()
{
 	pinMode(MAGNECTIC_SWITCH, INPUT);
	pinMode(LED,OUTPUT);
  Serial.begin(9600);
}
 
void loop() 
{
  debut:
  
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > 10000) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   
  }
  
  while(currentMillis - previousMillis < 10000) {
  
	if(isNearMagnet())//if the magnetic switch is near the magnet?
	{
x = x + 1;
		
	}
	else
	{
	
	}
}
if(x = 5){
  Serial.print(1);
delay(1000);

x = 0;
goto debut;
}
}


/*If the magnetic switch is near the magnet, it will return ture, */
/*otherwise it will return false								*/
boolean isNearMagnet()
{
	int sensorValue = digitalRead(MAGNECTIC_SWITCH);
	if(sensorValue == HIGH)//if the sensor value is HIGH?
	{
		return true;//yes,return ture
	}
	else
	{
		return false;//no,return false
	}
}

Alors si vous avez des idées je suis preneur je galère un peu :confused:

hello
normal, tu ne rafraichi pas la variable CurrentMilli dans ta boucle while

teste ça

/*******************************************************************************/
const int MAGNECTIC_SWITCH = 9;
const int LED = 13;
/macro definitions of magnetic pin and LED pin/

int x;
unsigned long currentMillis=0;
unsigned long previousMillis = 0;

void setup()
{
pinMode(MAGNECTIC_SWITCH, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(57600);
}

void loop()
{
while (currentMillis - previousMillis < 10000)
{
currentMillis = millis();
if (isNearMagnet()) //if the magnetic switch is near the magnet?
{
x = x + 1;
}
}
//x=5;// à virer, car uniquement pour ctrl fonctionnement
if (x = 5)
{
Serial.print(1);
delay(1000);
}
x = 0;
previousMillis = currentMillis;
}

/*If the magnetic switch is near the magnet, it will return ture, */
/*otherwise it will return false */
boolean isNearMagnet()
{
int sensorValue = digitalRead(MAGNECTIC_SWITCH);
if (sensorValue == HIGH) //if the sensor value is HIGH?
{
return true;//yes,return ture
}
else
{
return false;//no,return false
}
}

J'ai essayer ton programme mais malheureusement toute les 10 secondes il affiche un 1 alors qu'il n'y a aucun aimant a coter du capteur et le capteur fonctionne bien avec le code de base. Et a aucun moment dans ton code j'ai vue un endroit remettant le compteur a 0 après qu'il ai dépasser les 10 secondes

exact
je suis reparti de ton code et je n'ai pas fais attention à ton "if x = 5;" qui aurait du etre "if x == 5;"
j'ai corrigé sur le code

c'est "previousMillis = currentMillis;" qui remet le compteur de temps à zéro
voici le code

const int MAGNECTIC_SWITCH = 9;
const int LED =  13;
/*macro definitions of magnetic pin and LED pin*/

int x;
unsigned long currentMillis=0;
unsigned long previousMillis = 0;

void setup()
{
  pinMode(MAGNECTIC_SWITCH, INPUT);
  pinMode(LED, OUTPUT);
  Serial.begin(57600);
}

void loop()
{
  while (currentMillis - previousMillis < 10000)
  {
    currentMillis = millis();
    if (isNearMagnet()) //if the magnetic switch is near the magnet?
    {
      x = x + 1;
    }
  }
  //x=5;// à virer, car uniquement pour ctrl fonctionnement
  if (x == 5)
  {
    Serial.print(1);
    delay(1000);
  }
  x = 0;
  previousMillis = currentMillis;
}


/*If the magnetic switch is near the magnet, it will return ture, */
/*otherwise it will return false                        */
boolean isNearMagnet()
{
  int sensorValue = digitalRead(MAGNECTIC_SWITCH);
  if (sensorValue == HIGH) //if the sensor value is HIGH?
  {
    return true;//yes,return ture
  }
  else
  {
    return false;//no,return false
  }
}