PCF8574_Handler
drivers
drivers/PCF8574_Handler.h
driver
stable
stable
Driver PCF8574 I2C Expander Gestion d'un expander I2C PCF8574 Fonctionnalités : /
Méthodes publiques
| Méthode | Description | Paramètres | Retour |
|---|---|---|---|
|
PCF8574_Handler()
PCF8574_Handler(uint8_t address = 0x20);
|
Constructeur Initialise l'objet handler pour le PCF8574 / | address: : adresse I2C de l'expander (défaut : 0x20) / | |
|
begin()
begin();
|
Méthode begin() Initialise le driver PCF8574. Configure tous les canaux en entrée. / | truetrue si l'initialisation réussit, false sinon / |
|
|
read()
read(uint8_t channel);
|
Lecture d'un canal Lit l'état d'un canal numérique spécifique. / | channel: : numéro du canal à lire (0 à 7) | valeurvaleur HIGH (1) ou LOW (0), ou -1 si canal invalide / |
|
isReady()
isReady() const;
|
Statut du driver / | truetrue si le driver est correctement initialisé / |
Méthodes privées
begin(115200);;
println("Erreur d'initialisation du PCF8574");;
while (1);;
read(PCF8574_INPUT_CHANNEL);;
print("Canal ");;
print(PCF8574_INPUT_CHANNEL);;
print(" : ");;
println(state == HIGH ? "HIGH" : "LOW");;
delay(500);;
Variables membres
uint8_t _address;
PCF8574 _pcf;
bool _ready;
Code source
#pragma once
#include <PCF8574_library.h>
#include "../Settings.h"
#include "../StatusDevice.h"
namespace crepp::drivers {
/*
* =========================
* Driver PCF8574 I2C Expander
* -------------------------
* Gestion d'un expander I2C PCF8574
*
* @badge driver
* @badge stable
*
* Fonctionnalités :
* - Initialisation de l'expander
* - Lecture des états des canaux numériques (0 à 7)
* =========================
*/
class PCF8574_Handler {
public:
/*
* =========================
* Constructeur
* =========================
* Initialise l'objet handler pour le PCF8574
* @param address : adresse I2C de l'expander (défaut : 0x20)
*/
PCF8574_Handler(uint8_t address = 0x20);
/*
* =========================
* Méthode begin()
* =========================
* Initialise le driver PCF8574.
* Configure tous les canaux en entrée.
* @return true si l'initialisation réussit, false sinon
*/
bool begin();
/*
* =========================
* Lecture d'un canal
* =========================
* Lit l'état d'un canal numérique spécifique.
* @param channel : numéro du canal à lire (0 à 7)
* @return valeur HIGH (1) ou LOW (0), ou -1 si canal invalide
*/
int16_t read(uint8_t channel);
/*
* =========================
* Statut du driver
* =========================
* @return true si le driver est correctement initialisé
*/
bool isReady() const;
private:
static constexpr uint8_t MAX_CHANNELS = 8; ///< Nombre de canaux du PCF8574
uint8_t _address; ///< Adresse I2C de l'expander
PCF8574 _pcf; ///< Instance de la bibliothèque PCF8574
bool _ready; ///< Indique si le driver est initialisé
};
/*
@example
@include
#include <crepp/drivers/PCF8574_Handler.h>
@end_include
@macro
#define PCF8574_INPUT_CHANNEL 0
@end_macro
@instance
crepp::drivers::PCF8574_Handler pcf;
@end_instance
@setup
Serial.begin(115200);
if (!pcf.begin()) {
Serial.println("Erreur d'initialisation du PCF8574");
while (1);
}
@end_setup
@loop
int16_t state = pcf.read(PCF8574_INPUT_CHANNEL);
Serial.print("Canal ");
Serial.print(PCF8574_INPUT_CHANNEL);
Serial.print(" : ");
Serial.println(state == HIGH ? "HIGH" : "LOW");
delay(500);
@end_loop
@end_example
*/
} // namespace crepp::drivers