//Arduino code //Shift Register 74HC597 //test by sookhyun & jiwon #define latchPin 13 #define dataPin 8 #define clockPin 12 //Channel Pin Configuration - Switch Pin 9 #define channelPin9 17 void setup() { //To check serial Serial.begin(9600); //74HC597 pinMode(dataPin, INPUT); pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); //Switch Pin 9 pinMode(channelPin9, INPUT); //DMX channel } void loop() { switchVar1 = shiftIn(dataPin, clockPin, latchPin); Serial.println(switchVar1); delay(100); } // address read int shiftIn(int myDataPin, int myClockPin, int latchPin) { //Latch On digitalWrite(latchPin,0); delayMicroseconds(20); digitalWrite(latchPin,1); int result = 0; int temp[8]; //Temporary space for collect switch signal for (int i = 0; i <= 7; i++) { digitalWrite(myClockPin, 0); //clock delayMicroseconds(2); //Check Switch Pin 1 ~ 8 if(digitalRead(myDataPin) == HIGH) temp[i] = 0; else temp[i] = 1; digitalWrite(myClockPin, 1); //clock } for(int i = 0; i < 7; i++) { result += temp[7 - i]; result = result << 1; } //Last Number result += temp[0]; //Check Switch Pin 9 if(digitalRead(channelPin9) == LOW) result += 256; return result; } |
