Détecter la direction de mouvement de main et la vitesse.
Peut être utilisé pour contrôler n’importe quel appareil... Je vous laisse l’imagination magique
Vous aurez besoin :
-1 * Arduino (Uno)
-3 ou 5 ou... Interrupteur IR (j’ai utilisé E18D80NK) (6€)
-fils.
-3 * 1 k résistances
-3 * LEDs.
Le code :
---------------------------------------
#define sIRA 10
#define sIRB 8
#define sIRC 9
#define LED1 3
#define LED2 4
#define DEL3 5
char des ordres [3] = {« 0 », « 0 », « 0 »} ;
int indexOrder = 0 ;
Vitesse de détection Ms
int Captspeed = 1 ;
long tA ;
tB long ;
tC de long ;
void setup() {}
Serial.Begin (9600) ;
pour (int i = 8; i < = 10; i ++)
pinMode (i, entrée) ;
pour (int i = 3; i < = 5; i ++)
pinMode (i, sortie) ;
}
void loop() {}
Commande de réinitialisation après 800 Msecond
Si (millis () % 1000 > 800)
ResetCommand() ;
Si nous avons 3 signaux, commande calculer
Si (tA > 0 & & tB > 0 & & tC > 0)
{
commande int = CalculateCommand() ;
Si (commande < = 0)
DoCommand(command) ;
}
cocher pour capteurs
if(indexOrder > 2)
indexOrder = 0 ;
int vA = digitalRead(sIRA) ;
Si (tA == 0 & & vA == 0) tA = millis() ;
int vB = digitalRead(sIRB) ;
Si (tB == 0 & & vB == 0) CT = millis() ;
int vC = digitalRead(sIRC) ;
Si (tC == 0 & & vC == 0) tC = millis() ;
Arrêter la commande
Si (vA == 0 & & vB == 0 & & vC == 0)
{
DoCommand(0) ;
}
Delay(Captspeed) ;
}
int CalculateCommand(void)
{
Serial.Print ("tA =") ;
Serial.println(TA) ;
Serial.Print ("to =") ;
Serial.println(TB) ;
Serial.Print (« tC = ") ;
Serial.println(TC) ;
Delay(1) ;
Si ((tA < = tB) & & tA < = tC)
retour -3;// FORWRD
Si ((CT < = tC) & & CT < = tA)
retour -2;// gauche
Si ((tC < = tB) & & tC < = tA)
-1 retour ; //RIGHT
Etc.
Return 1 ;
}
Sub DoCommand(int command)
{
interrupteur (commande)
{
case 0: Serial.println (« arrêté »), delay (500); break ;
affaire -1 : Serial.println ("tourner à droite"); digitalWrite(LED1,HIGH) ; retard (1000); break ;
affaire -2 : Serial.println ("tournez à gauche"); digitalWrite(LED2,HIGH) ; retard (1000); break ;
affaire -3 : Serial.println ("GO FORWARD"); digitalWrite(LED3,HIGH) ; retard (1000); break ;
affaire -4 : Serial.println ("GO BACK") ; retard (1000); break ;
par défaut : Serial.println ("commande non détectée"); break ;
}
ResetCommand() ;
}
Sub ResetCommand()
{
pour (int i = 3; i < = 5; i ++)
{
digitalWrite (i, faible); //ALL LEDs
}
tA = 0; //Reset temps A
tB = 0; //Reset temps B
tC = 0; //Reset temps C
}