Bom eu tentei utilizar o PCF8574 para fazer a leitura de pushbuttons mas encontrei um tutorial que possibilita apenas a leitura de 1 botão. O que preciso modificar no código para que seja feita a leitura de todos os 8 pinos? Código:

#include <Wire.h>
#define expander 0x20
 
void setup() {
  Wire.begin();
  Serial.begin(9600);
  expanderWrite(B11111111);
  pinMode(13, OUTPUT);
}
 
void loop() {
  byte pin_number = 0; //check status of pin 0
 
  /* querying the pcf8574 returns a byte. each bit is the current status of each of
  the 8 pins. 0 = low, 1 = high */
  byte returnByte = expanderRead();
 
  // we can use a funciton called bitread to get the status of any bit in the byte
  // pin number starts at 0
  boolean bitStatus = bitRead(returnByte, pin_number);
 
  if(bitStatus == 1) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
 
  Serial.println(bitStatus, BIN);
 
  delay(500);
}
 
void expanderWrite(byte _data ) {
  Wire.beginTransmission(expander);
  Wire.send(_data);
  Wire.endTransmission();
}
 
byte expanderRead() {
  byte _data;
  Wire.requestFrom(expander, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}

Exibições: 350

Responder esta

Respostas a este tópico

Vou sugerir ao amigo para usar o 74hc165.

É bem facil de usar e pode inclusive detectar varios btn pressionados ao mesmo tempo.

De uma procurada, mesmo aqui no forum, que tem muita coisa escrita sobre ele, esquemas, fontes, etc...

[]´s

Jota

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço