#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>

int pins[9] = {PB0, PA14, PB3, PA13, PB13, PD2, PB14, PD0, PB15};
String pins_name[9] = {"PB0", "PA14", "PB3", "PA13", "PB13", "PD2", "PB14", "PD0", "PB15"};

int buttonPin = PA4; 
int ledGreen = PA8;   
int ledRed = PB7;
int ledBlue = PB12;    
bool buttonPressed = false; 

#define SDA_PIN A4
#define SCL_PIN A5

#define I2C_ADDR 0x27 

#define LCD_COLS 16
#define LCD_ROWS 2

LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLS, LCD_ROWS);

void setup() {
  Wire.begin(SDA_PIN, SCL_PIN);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello, World!"); 
  pinMode(buttonPin, INPUT_PULLUP); 
  pinMode(ledGreen, OUTPUT);        
  pinMode(ledRed, OUTPUT);     
  pinMode(ledBlue, OUTPUT);      

  digitalWrite(ledGreen, LOW); 
  digitalWrite(ledRed, LOW); 
  digitalWrite(ledBlue, HIGH);     

  lcd.print("Appuyez sur le bouton pour démarrer le test...");
}

int currentButtonState = HIGH;
int lastButtonState = HIGH;

void loop() {
  currentButtonState = digitalRead(buttonPin);
  if (currentButtonState == LOW && lastButtonState == HIGH) {
    digitalWrite(ledGreen , LOW);
digitalWrite(ledRed , LOW);
    lcd.print("Test en cours...");

    for (int i = 0; i < sizeof(pins) / sizeof(pins[0]); i++) {
      pinMode(pins[i], INPUT_PULLUP); 
    }
int i=0 ;
    for ( i = 0; i < 8; i++) {
      lcd.print("Test numéro : ");
      lcd.print(i + 1);
      pinMode(pins[i], OUTPUT);
      digitalWrite(pins[i], LOW);
      delay(1);
      lcd.print("Test Court-circuit entre ");
      lcd.print(pins_name[i]);
      lcd.print(" et ");
      lcd.println(pins_name[i + 1]);
      if (digitalRead(pins[i + 1]) == LOW) {
        lcd.print("i = ");
        lcd.println(i);
        
        break;
      } 
      pinMode(pins[i], INPUT_PULLUP);
      delay(1); 
    }
     Serial.println(i);
   if(i == 8 )
   {
   digitalWrite(ledGreen , HIGH);
   }
   else
   digitalWrite(ledRed , HIGH);
    // fin de test

  }
  lastButtonState = currentButtonState;
  delay(20);
}
Loading
st-nucleo-c031c6