Modèle:Code

De Wiki de bureau d'études PeiP
Révision datée du 23 mars 2020 à 10:13 par Epoitevi (discussion | contributions) (Page créée avec « #include <stdio.h> #include <stdlib.h> #include <time.h> #define LED1 0 #define LED2 1 #define LED3 2 #define LED4 3 #define LED5 4 #define LED6 5 #define LED7 6 int Tabl... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
  1. include <stdio.h>
  2. include <stdlib.h>
  3. include <time.h>
  1. define LED1 0
  2. define LED2 1
  3. define LED3 2
  4. define LED4 3
  5. define LED5 4
  6. define LED6 5
  7. define LED7 6

int Tableaupin[7]= {5,4,1,3,6,2,0}; int BROCHE_BOUTON=7;

void setup() {

// initialisation
Serial.begin(9600);
pinMode(Tableaupin[LED1], OUTPUT);
pinMode(Tableaupin[LED2], OUTPUT);
pinMode(Tableaupin[LED3], OUTPUT);
pinMode(Tableaupin[LED4], OUTPUT);
pinMode(Tableaupin[LED5], OUTPUT);
pinMode(Tableaupin[LED6], OUTPUT);
pinMode(Tableaupin[LED7], OUTPUT);
pinMode(BROCHE_BOUTON,INPUT_PULLUP);
digitalWrite(Tableaupin[LED1],HIGH);
delay(200);
digitalWrite(Tableaupin[LED1],LOW);
digitalWrite(Tableaupin[LED2],HIGH);
delay(200);
digitalWrite(Tableaupin[LED2],LOW);
digitalWrite(Tableaupin[LED3],HIGH);
delay(200);
digitalWrite(Tableaupin[LED3],LOW);
digitalWrite(Tableaupin[LED4],HIGH);
delay(200);
digitalWrite(Tableaupin[LED4],LOW);
digitalWrite(Tableaupin[LED5],HIGH);
delay(200);
digitalWrite(Tableaupin[LED5],LOW);
digitalWrite(Tableaupin[LED6],HIGH);
delay(200);
digitalWrite(Tableaupin[LED6],LOW);
digitalWrite(Tableaupin[LED7],HIGH);
delay(200);
digitalWrite(Tableaupin[LED7],LOW);
randomSeed(analogRead(0));

}


int random_a_b(int a,int b) //fonction qui renvoie un nombre entre a inclus et b exclus { return random()%(b-a) +a; }

//fct nombre de leds allumées

void de1T() {

 digitalWrite(Tableaupin[LED4],HIGH);
 delay(1000);

} void de2T() {

 digitalWrite(Tableaupin[LED3],HIGH);
 digitalWrite(Tableaupin[LED5],HIGH);
 delay(1000);

} void de3T() {

 digitalWrite(Tableaupin[LED3],HIGH);
 digitalWrite(Tableaupin[LED4],HIGH);
 digitalWrite(Tableaupin[LED5],HIGH);
 delay(1000);

} void de4T() {

 digitalWrite(Tableaupin[LED1],HIGH);
 digitalWrite(Tableaupin[LED3],HIGH);
 digitalWrite(Tableaupin[LED5],HIGH);
 digitalWrite(Tableaupin[LED7],HIGH);
 delay(1000);

} void de5T() {

 digitalWrite(Tableaupin[LED1],HIGH);
 digitalWrite(Tableaupin[LED3],HIGH);
 digitalWrite(Tableaupin[LED4],HIGH);
 digitalWrite(Tableaupin[LED5],HIGH);
 digitalWrite(Tableaupin[LED7],HIGH);
 delay(1000);

} void de6T() {

 digitalWrite(Tableaupin[LED1],HIGH);
 digitalWrite(Tableaupin[LED2],HIGH);
 digitalWrite(Tableaupin[LED3],HIGH);
 digitalWrite(Tableaupin[LED5],HIGH);
 digitalWrite(Tableaupin[LED6],HIGH);
 digitalWrite(Tableaupin[LED7],HIGH);
 delay(1000);

}

// fonct eteint lampe

void de6F() {

 digitalWrite(Tableaupin[LED1],LOW);
 digitalWrite(Tableaupin[LED2],LOW);
 digitalWrite(Tableaupin[LED3],LOW);
 digitalWrite(Tableaupin[LED4],LOW);
 digitalWrite(Tableaupin[LED5],LOW);
 digitalWrite(Tableaupin[LED6],LOW);
 digitalWrite(Tableaupin[LED7],LOW);

}

//fonction d'affichage resultat final

void loop() {

 int LED;
// partie selection dé
 if (digitalRead(BROCHE_BOUTON) == HIGH){
 LED=random_a_b(0,6);
 de6F();
 }
 unsigned char test=(digitalRead(BROCHE_BOUTON)==LOW);
 switch (LED)
 {
   case 0:
     if (test) de1T(); break;
   case 1:
     if (test) de2T(); break;
   case 2:
     if (test) de3T(); break;
   case 3:
     if (test) de4T(); break;
   case 4:
     if (test) de5T(); break;
   case 5:
     if (test) de6T(); break;
 }


}