Zoom:

Lundi 

Mardi

Mercredi

Jeudi

Vendredi

 

Câblage de la carte Arduino avec la LED: 2 montages possibles

Exo 1:

/*
  Blink at ISTY

  Turns 3 LED on for one second, then off for one second, repeatedly.
  I tested this program at ISTY
  25/01/2024
*/

const int led_verte=13, led_orange=12, led_rouge=11;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(led_rouge, OUTPUT);
  pinMode(led_verte, OUTPUT);
  pinMode(led_orange, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(led_rouge, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(led_verte, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(led_rouge, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  digitalWrite(led_verte, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Exo 2:

/*
  Blink at ISTY

  A pushbutton turns 3 LED on or off
  I tested this program at ISTY
  25/01/2024
*/

//paramétrage des entrées
const int bp=10;

//paramétrage des sorties
const int led_verte=13, led_orange=12, led_rouge=11;


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin bp as an input.
  pinMode(bp, INPUT_PULLUP);
  
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(led_rouge, OUTPUT);
  pinMode(led_verte, OUTPUT);
  pinMode(led_orange, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  if (digitalRead(bp) == HIGH)
  {
      digitalWrite(led_rouge, HIGH);   
      digitalWrite(led_verte, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(100);
    }
  }
  else
  {
  digitalWrite(led_rouge, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  digitalWrite(led_verte, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  }
}

 

 

Challenge avec un test de BP:

// ==========================
// Définition des broches
// ==========================
const int ledRouge  = 13;
const int ledOrange = 12;
const int ledVerte  = 11;

const int boutonPin = 2;   // fil/bouton poussoir sur pin 2

// ==========================
// Variables temps
// ==========================
unsigned long previousRouge = 0;
unsigned long previousVerte = 0;

bool etatRouge = false;
bool etatVerte = false;

void setup() {
  pinMode(ledRouge, OUTPUT);
  pinMode(ledOrange, OUTPUT);
  pinMode(ledVerte, OUTPUT);

  pinMode(boutonPin, INPUT_PULLUP);  
  // Contact fermé = LOW
}

void loop() {

  unsigned long currentMillis = millis();

  // ==========================
  // LED Rouge : clignote toutes les 1 seconde
  // ==========================
  if (currentMillis - previousRouge >= 1000) {
    previousRouge = currentMillis;
    etatRouge = !etatRouge;
    digitalWrite(ledRouge, etatRouge);
  }

  // ==========================
  // Lecture contact (bouton)
  // ==========================
  bool contactFerme = (digitalRead(boutonPin) == LOW);

  // ==========================
  // Si contact fermé
  // ==========================
  if (contactFerme) {

    // Orange ON
    digitalWrite(ledOrange, HIGH);

    // Verte clignote toutes les 100 ms
    if (currentMillis - previousVerte >= 100) {
      previousVerte = currentMillis;
      etatVerte = !etatVerte;
      digitalWrite(ledVerte, etatVerte);
    }

  }
  // ==========================
  // Si contact ouvert
  // ==========================
  else {
    digitalWrite(ledOrange, LOW);
    digitalWrite(ledVerte, LOW);
    etatVerte = false;
  }
}