Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- int readstate = 0;
- int addr[16];
- int cycle = 0;
- void setup() {
- Wire.begin(8); // join i2c bus with address #8
- Wire.onReceive(receiveEvent); // register event
- Serial.begin(9600); // start serial for output
- pinMode(2, OUTPUT);
- pinMode(3, OUTPUT);
- pinMode(4, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(7, OUTPUT);
- pinMode(8, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode(A0, OUTPUT);
- pinMode(A7, INPUT);
- }
- int receiveEvent() {
- if (Wire.available()) {
- addr[0] = Wire.read();
- addr[1] = Wire.read();
- addr[2] = Wire.read();
- addr[3] = Wire.read();
- addr[4] = Wire.read();
- addr[5] = Wire.read();
- addr[6] = Wire.read();
- addr[7] = Wire.read();
- addr[8] = Wire.read();
- addr[9] = Wire.read();
- addr[10] = Wire.read();
- addr[11] = Wire.read();
- addr[12] = Wire.read();
- addr[13] = Wire.read();
- addr[14] = Wire.read();
- addr[15] = Wire.read();
- addr[16] = Wire.read();
- }
- }
- void setallpinslow() {
- digitalWrite(2, LOW);
- digitalWrite(3, LOW);
- digitalWrite(4, LOW);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- digitalWrite(7, LOW);
- digitalWrite(8, LOW);
- digitalWrite(9, LOW);
- digitalWrite(10, LOW);
- }
- int convertvalue(int in) {
- switch (in) {
- case 48:
- Serial.print("0");
- break;
- case 49:
- Serial.print("1");
- break;
- default:
- Serial.print("Invalid value detected");
- break;
- }
- }
- void serialFlush() {
- while (Serial.available() > 0) {
- char t = Serial.read();
- }
- }
- int outputaddress() {
- convertvalue(addr[0]);
- convertvalue(addr[1]);
- convertvalue(addr[2]);
- convertvalue(addr[3]);
- convertvalue(addr[4]);
- convertvalue(addr[5]);
- convertvalue(addr[6]);
- convertvalue(addr[7]);
- convertvalue(addr[8]);
- convertvalue(addr[9]);
- convertvalue(addr[10]);
- convertvalue(addr[11]);
- convertvalue(addr[12]);
- convertvalue(addr[13]);
- convertvalue(addr[14]);
- convertvalue(addr[15]);
- convertvalue(addr[16]);
- Serial.print("\n");
- }
- void clk() {
- digitalWrite(A0, HIGH);
- delay(20);
- digitalWrite(A0, LOW);
- }
- void readstatus() {
- readstate = digitalRead(A7);
- Serial.print(readstate);
- Serial.print("\n");
- }
- void loop() {
- if (Serial.available()) {
- Serial.print("Executing 4 CLK \n");
- cycle = cycle + 1;
- Serial.print("Cycle:");
- Serial.print(cycle);
- Serial.print("\n");
- setallpinslow(); //testing for now
- outputaddress();
- readstatus();
- for (int i = 0; i <= 4; i++) {
- clk();
- }
- serialFlush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment