Go Down

Topic: PCF8574P BUTTON INPUT (Read 1 time) previous topic - next topic

wlewis

I just tried it out.. the PCF8574P ic serves as a way to achieve stable input. Very cool!

----------

#include <LiquidCrystal.h>
#include <Wire.h>
#include <avr/pgmspace.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int buttons = B00100000;//PCF8574 ID
byte buttonV;//Right,Down,Up,Left,A,B
unsigned long buttonT;
int start;
byte count;

void setup()
{
lcd.begin(20, 4);
Wire.begin();

Wire.beginTransmission(buttons);
Wire.send(255);
Wire.endTransmission();

}

void loop(){

buttonScan();
lcd.setCursor(0,0);

if(((buttonV>>0)&1)==0){lcd.print("0 "); lcd.print(buttonV, BIN); }
if(((buttonV>>1)&1)==0){lcd.print("1 "); lcd.print(buttonV, BIN); }
if(((buttonV>>2)&1)==0){lcd.print("2 "); lcd.print(buttonV, BIN); }
if(((buttonV>>3)&1)==0){lcd.print("3 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>4)&1)==0){lcd.print("4 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>5)&1)==0){lcd.print("5 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>6)&1)==0){lcd.print("6 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>7)&1)==0){lcd.print("7 "); lcd.print(buttonV, BIN); }  
}

void buttonScan(){
Wire.requestFrom(buttons,1);
if (Wire.available())
buttonV = Wire.receive();
}


connections on pcf8574:
SCL 14 --- 10K --- VCC+ (YOU MUST HAVE THESE 10K RESISTORS)
SDA 15 --- 10K --- VCC+                         "
PIN 16 ---- VCC +
PIN 1   ---- GND
    2   ---- GND
    3   ---- GND
PINS 4 - 12 (as follows:)

                            BTN
                           -------
ie. pin4  ------------        ------------ R 1K ----- + VCC
                                   |
                                   |
                                 GND

when button is pressed current is diverted to ground.

THIS WORKS!

I was unable to upload a schematic.png // hmm.. how do you upload images?

Go Up