Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Original code from webpage
- https://elger.org/wiki/projects/i2c_pcf8574_8bit_port_expander
- Modified for 8 inputs and outputs + show info at LCD1602
- (c)2020 Martin Blaha - elektronek.cz
- */
- #include <Wire.h>
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- byte iInput=0;
- byte iOutput=0;
- void setup()
- {
- Wire.begin();
- lcd.begin(16, 2);
- lcd.setCursor ( 0, 0 );
- lcd.print("Vyber vstupu");
- }
- void loop()
- {
- Wire.requestFrom(33,1);// Begin transmission to PCF8574 with the buttons
- if(Wire.available()) // If bytes are available to be recieved
- {
- iInput = Wire.read();// Read a byte
- }
- if(iInput<255) //If the value less than 255
- {
- lcd.setCursor ( 0, 1 );
- if (iInput==254) // P0
- {
- iOutput = 1;
- lcd.print("Vstup 1");
- };
- if (iInput==253) // P1
- {
- iOutput = 2;
- lcd.print("Vstup 2");
- };
- if (iInput==251) // P2
- {
- iOutput = 4;
- lcd.print("Vstup 3");
- };
- if (iInput==247) // P3
- {
- iOutput = 8;
- lcd.print("Vstup 4");
- };
- if (iInput==239) // P4
- {
- iOutput = 16;
- lcd.print("Vstup 5");
- };
- if (iInput==223) // P5
- {
- iOutput = 32;
- lcd.print("Vstup 6");
- };
- if (iInput==191) // P6
- {
- iOutput = 64;
- lcd.print("Vstup 7");
- };
- if (iInput==127) // P7
- {
- iOutput = 128;
- lcd.print("Vstup 8");
- };
- }
- Wire.beginTransmission(32); //Begin transmission to PCF8574 (with the LEDs)
- Wire.write(iOutput); //Send data to PCF8574 (with the LEDs)
- Wire.endTransmission(); //End Transmission to PCF8574 (with the LEDs)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement