Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino IDE demo source code for KC868-E16S]--#02-KC868-E16S-8574-DI
#1
Thumbs Up 
[Arduino IDE demo source code for KC868-E16S]--#02-KC868-E16S-8574-DI
   

Code:
/*KC868-E16S pcf8574 -digital input code*/
#include "Arduino.h"
#include "PCF8574.h"

// Set i2c address
PCF8574 pcf8574_IN1(0x22,16,15);
PCF8574 pcf8574_IN2(0x24,16,15);
void setup()
{
    Serial.begin(115200);
    delay(1000);

  pcf8574_IN1.begin();
  pcf8574_IN2.begin();


pcf8574_IN1.pinMode(P0, INPUT);
pcf8574_IN1.pinMode(P1, INPUT);
pcf8574_IN1.pinMode(P2, INPUT);
pcf8574_IN1.pinMode(P3, INPUT);
pcf8574_IN1.pinMode(P4, INPUT);
pcf8574_IN1.pinMode(P5, INPUT);
pcf8574_IN1.pinMode(P6, INPUT);
pcf8574_IN1.pinMode(P7, INPUT);

pcf8574_IN2.pinMode(P0, INPUT);
pcf8574_IN2.pinMode(P1, INPUT);
pcf8574_IN2.pinMode(P2, INPUT);
pcf8574_IN2.pinMode(P3, INPUT);
pcf8574_IN2.pinMode(P4, INPUT);
pcf8574_IN2.pinMode(P5, INPUT);
pcf8574_IN2.pinMode(P6, INPUT);
pcf8574_IN2.pinMode(P7, INPUT);
}

void loop()
{
   if (pcf8574_IN1.digitalRead(P0)==0)  {Serial.println("KEY1 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P1)==0)  {Serial.println("KEY2 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P2)==0)  {Serial.println("KEY3 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P3)==0)  {Serial.println("KEY4 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P4)==0)  {Serial.println("KEY5 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P5)==0)  {Serial.println("KEY6 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P6)==0)  {Serial.println("KEY7 PRESSED");}delay(100);
   if (pcf8574_IN1.digitalRead(P7)==0)  {Serial.println("KEY8 PRESSED");}delay(100);
   
   if (pcf8574_IN2.digitalRead(P0)==0)  {Serial.println("KEY9 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P1)==0)  {Serial.println("KEY10 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P2)==0)  {Serial.println("KEY11 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P3)==0)  {Serial.println("KEY12 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P4)==0)  {Serial.println("KEY13 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P5)==0)  {Serial.println("KEY14 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P6)==0)  {Serial.println("KEY15 PRESSED");}delay(100);
   if (pcf8574_IN2.digitalRead(P7)==0)  {Serial.println("KEY16 PRESSED");}delay(100);   

 
}
   


Attached Files
.zip   KC868-E16S-8574-DI.zip (Size: 783 bytes / Downloads: 239)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)