COLORKEY (2 / 5 étapes)

Étape 2: Comment fonctionne le COLORKEY ?

Afin de rendre l’objet fonctionnel, j’ai utilisé le câblage à réaliser la programmation objet.
Chaque couleur est un commutateur d’impulsion qui est relié au câblage. Quand 3 des 6 interrupteurs sont activés ; câblage automatiquement active une serrure électrique.

Voici le code de couleur-clé :

int switchrojo = 0 ;
int switchverde = 1 ;
int switchmorado = 2 ;
int switchazul = 3 ;
int switchamarillo = 4 ;
int switchnaranja = 5 ;
cerradura int = 8 ;
int presionadorojo = 0 ;
int presionadoverde = 0 ;
int presionadomorado = 0 ;
int presionadoazul = 0 ;
int presionadoamarillo = 0 ;
int presionadonaranja = 0 ;
int times_pressed = 0 ;
start_time long = 0 ;

void setup()
{
pinMode (switchrojo, entrée) ;
pinMode (switchverde, entrée) ;
pinMode (switchmorado, entrée) ;
pinMode (switchazul, entrée) ;
pinMode (switchamarillo, entrée) ;
pinMode (switchnaranja, entrée) ;
pinMode (cerradura, sortie) ;
Serial.Begin(9600) ;
pinMode (48, sortie) ;
digitalWrite (48, haut) ;
}

void loop() {}

if(digitalRead(switchrojo) == faible) {}
while(digitalRead(switchrojo) == faible) ;
presionadorojo = 1 ;
times_pressed ++ ;
}
if(digitalRead(switchverde) == faible) {}
while(digitalRead(switchverde) == faible) ;
presionadoverde = 1 ;
times_pressed ++ ;
}
if(digitalRead(switchazul) == faible) {}
while(digitalRead(switchazul) == faible) ;
presionadoazul = 1 ;
times_pressed ++ ;
}
if(digitalRead(switchmorado) == faible) {}
while(digitalRead(switchmorado) == faible) ;
presionadomorado = 1 ;
times_pressed ++ ;
}
if(digitalRead(switchamarillo) == faible) {}
while(digitalRead(switchamarillo) == faible) ;
presionadoamarillo = 1 ;
times_pressed ++ ;
}
if(digitalRead(switchnaranja) == faible) {}
while(digitalRead(switchnaranja) == faible) ;
presionadonaranja = 1 ;
}
if(Millis() - start_time > 5000) {}
times_pressed = 0 ;
presionadorojo = 0 ;
presionadoverde = 0 ;
presionadoazul = 0 ;
presionadomorado = 0 ;
presionadoamarillo = 0 ;
presionadonaranja = 0 ;
start_time = millis() ;
}
Si (times_pressed > = 3) {}

Si ((presionadorojo == 0) & &
(presionadoverde == 1) & &
(presionadomorado == 0) & &
(presionadoazul == 1) & &
(presionadoamarillo == 0) & &
(presionadonaranja == 1))
{
digitalWrite (cerradura, HIGH) ;
retarder (5000) ;
digitalWrite (cerradura, faible) ;
times_pressed = 0 ;
presionadorojo = 0 ;
presionadoverde = 0 ;
presionadoazul = 0 ;
presionadomorado = 0 ;
presionadoamarillo = 0 ;
presionadonaranja = 0 ;
start_time = millis() ;
}
}
Serial.Print (presionadorojo, DEC) ;
Serial.Print("") ;
Serial.Print (presionadoverde, DEC) ;
Serial.Print("") ;
Serial.Print (presionadoazul, DEC) ;
Serial.Print("") ;
Serial.Print (presionadomorado, DEC) ;
Serial.Print("") ;
Serial.Print (presionadoamarillo, DEC) ;
Serial.Print("") ;
Serial.println (presionadonaranja, DEC) ;

Serial.Print (times_pressed, DEC) ;
Serial.Print("") ;
Delay(100) ;
}

Articles Liés