SHARE
TWEET

Untitled

a guest May 27th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2.  
  3. int count = 0;
  4. void setup() {
  5.   //Pin setup
  6.   pinMode(2, OUTPUT);    //CLOCK
  7.   pinMode(3, INPUT);    //Input Register 2
  8.   pinMode(4, OUTPUT);   //Data Register 2
  9.   pinMode(5, INPUT);   //Output Register 1
  10.   pinMode(6, OUTPUT);   //Data Register 1
  11.   pinMode(7, INPUT); //buttonOne input
  12.   pinMode(8, INPUT); //buttonTwo input
  13.   pinMode(9, INPUT); //buttonThree input
  14.   pinMode(10, INPUT); //buttonCheck input
  15.  
  16.   //Pin start data
  17.   digitalWrite(4, LOW); //Register 2 low so it starts in state 00
  18.   digitalWrite(6, LOW); //Register 1 low so it starts in state 00
  19.   digitalWrite(2, HIGH); //Set the first state in the registers
  20.   delay(250);
  21.   digitalWrite(2, LOW); //Clock low so no data can be entered anymore
  22.  
  23.   //Serial Monitor
  24.   Serial.begin(9600);
  25.   Serial.println("14CORE | PCF8574AP IO EXPANSION TEST CODE");
  26.   Serial.println("-----------------------------------------");
  27.   Serial.println("Begin...");
  28.  
  29.   //Wire
  30.   Wire.begin();
  31. }
  32.  
  33. void loop() {
  34.   if(count == 1){
  35.     digitalWrite(4, LOW);
  36.     digitalWrite(6, LOW); //State 00
  37.     digitalWrite(2, HIGH); //Set the state in the registers
  38.     delay(250);
  39.     digitalWrite(2, LOW); //Clock low so no data can be entered anymore
  40.     Wire.beginTransmission (0x38); //Set P0 pin to logic level HIGH
  41.     Wire.write((byte)0b00000000); //Send byte to write BYTE(P7-P6-P5-P4-P3-P2-P1-P0)
  42.     Wire.endTransmission(); //Set to end transmission
  43.   }else if(count == 5){
  44.     digitalWrite(4, HIGH);
  45.     digitalWrite(6, LOW); //State 01
  46.     digitalWrite(2, HIGH); //Set the state in the registers
  47.     delay(250);
  48.     digitalWrite(2, LOW); //Clock low so no data can be entered anymore
  49.     Wire.beginTransmission (0x38); //Set P0 pin to logic level HIGH
  50.     Wire.write((byte)0b10000000); //Send byte to write BYTE(P7-P6-P5-P4-P3-P2-P1-P0)
  51.     Wire.endTransmission(); //Set to end transmission
  52.   }else if(count == 10){
  53.     digitalWrite(4, LOW);
  54.     digitalWrite(6, HIGH); //State 10
  55.     digitalWrite(2, HIGH); //Set the state in the registers
  56.     delay(250);
  57.     digitalWrite(2, LOW); //Clock low so no data can be entered anymore
  58.     Wire.beginTransmission (0x38); //Set P0 pin to logic level HIGH
  59.     Wire.write((byte)0b11000000); //Send byte to write BYTE(P7-P6-P5-P4-P3-P2-P1-P0)
  60.     Wire.endTransmission(); //Set to end transmission
  61.   }else if(count == 15){
  62.     digitalWrite(4, HIGH);
  63.     digitalWrite(6, HIGH); //State 11
  64.     digitalWrite(2, HIGH); //Set the state in the registers
  65.     delay(250);
  66.     digitalWrite(2, LOW); //Clock low so no data can be entered anymore
  67.     Wire.beginTransmission (0x38); //Set P0 pin to logic level HIGH
  68.     Wire.write((byte)0b11100000); //Send byte to write BYTE(P7-P6-P5-P4-P3-P2-P1-P0)
  69.     Wire.endTransmission(); //Set to end transmission
  70.     count = 0;
  71.   }
  72.   int buttonOneState = digitalRead(7);
  73.   int buttonTwoState = digitalRead(8);
  74.   int buttonThreeState = digitalRead(9);
  75.   int buttonCheckState = digitalRead(10);
  76.   delay(1000);
  77.   Serial.println("-----------------------------------------");
  78.   Serial.println("Buttons:");
  79.   Serial.println("buttonOneState: ");
  80.   Serial.println(buttonOneState);
  81.   Serial.println("buttonTwoState: ");
  82.   Serial.println(buttonTwoState);
  83.   Serial.println("buttonThreeState: ");
  84.   Serial.println(buttonThreeState);
  85.   Serial.println("buttonCheckState: ");
  86.   Serial.println(buttonCheckState);
  87.   count++;
  88.  
  89.  
  90. //  digitalWrite(2, HIGH);     //CLOCK
  91. //  Wire.beginTransmission (0x38); //Set P0 pin to logic level HIGH
  92. //  Wire.write((byte)0b00001110); //Send byte to write 0b00000001
  93. //  Wire.endTransmission(); //Set to end transmission
  94. //  delay(1000);
  95. //  digitalWrite(2, LOW);    //CLOCK
  96. //  Wire.beginTransmission (0x38); //Set P0 pin to logic level HIGH
  97. //  Wire.write((byte)0b00000000); //Send byte to write 0b00000001
  98. //  Wire.endTransmission(); //Set to end transmission
  99. //  delay(1000);
  100. //  digitalWrite(4, HIGH);
  101. //  digitalWrite(6, HIGH);
  102. //  int registerOneState = digitalRead(6);
  103. //  int registerTwoState = digitalRead(3);
  104. //  Serial.println(registerOneState);
  105. //  Serial.println(registerTwoState);
  106.  
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top