Studio hhjjj workshop

Participation

위키 공동 편집을 원하시는 분은 다음 이메일로 자기소개를 부탁드립니다.
Send me an email to participate in workshop wiki.

songhojun@gmail.com

SensorComm Board

최근 사이트 활동

라이선스 안내

Creative Commons License
본 사이트의 모든 저작물크리에이티브 커먼즈 저작자표시-동일조건변경허락 2.0 대한민국 라이선스에 따라 이용할 수 있습니다.

Research‎ > ‎

597 ID Checker


//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;

}