PCF8574 I/O 확장 I2C 모듈 -조이스틱, 버저 장착
(PCF8574 I/O Expander with Joystick, Buzzer)
개요
- 본 제품은 PCF8574 I2C I/O 확장 모듈입니다.
- 모듈에 조이스틱과 버저가 장착되어 있는 제품으로 MCU의 I2C 인터페이스를 이용하여 조이스틱 및 버저 그리고 다른 모듈을 연결하여 사용이 가능하게 디자인된 제품입니다.
- P0(좌), P1(하), P2(스위치 누름), P3(우), P4(상)는 조이스틱에 연결이 되어 있으며, 조이스틱의 common 핀은 VCC나 Gnd에 연결이 가능합니다. 보드상의 점퍼를 이용하여 조이스틱 연결을 끊을 수 있게 디자인되었습니다.
- P5는 버저에 연결되어 있으며, 동일하게 보드상의 점퍼를 이용하여 연결을 끊을 수 있게 디자인되었습니다.
- P6과 P7은 아무것에도 연결되어 있지 않습니다.
- 또한 4개의 아날로그 입력을 지원하는데, AIN0, AIN1은 연결되어 있지 않고, AIN2는 아날로그 센서입력 포트에 연결되어 있습니다. (포토셀 위치) 점퍼로 연결을 끊을 수 있습니다.
- AIN3는 포텐셔미터가 연결되어 있습니다. 테스트용으로 사용이 가능하며 점퍼로 연결을 끊을 수 있습니다.
특징
- n/a
문서
- schematic
- 아두이노 예제
//I2C device found at address 0x20 ! //8574 //I2C device found at address 0x48 ! #include "PCF8574.h" #include <Wire.h> byte top = 0b11111110; byte left = 0b11111101; byte pres = 0b11111011; byte down = 0b11110111; byte right = 0b11101111; // adjust addresses if needed PCF8574 PCF_01(0x20); #define PCF8591 (0x48) byte adcvalue0, adcvalue1, adcvalue2, adcvalue3; void setup() { Serial.begin(115200); Wire.begin(); } void loop() { PCF_8574_read_joystick_write_buzzer(); // this one not working !! please use another sketch! //PCF_8591_write(); // DAC, dim LED // sensor AIN3, pot trim on AIN2 //PCF_8591_read(); //ADC //PCF_8574_read_joystick(); //PCF_8574_write_buzzer(1000); // fucntion beep buzzer every one second }
void PCF_8574_read_joystick_write_buzzer() { PCF_01.begin(); int x = PCF_01.read8(); Serial.print("Read "); Serial.println(x, BIN); //Serial.println(x, HEX); delay(100); if (x == top) { Serial.println("detect - top"); } if (x == left) { // short beep Serial.println("detect - left"); PCF_01.write(5, 0); delay(200); PCF_01.write(5, 1); } if (x == pres) { Serial.println("detect - pres"); PCF_01.write(5, 0); delay(1000); PCF_01.write(5, 1); } if (x == down) { Serial.println("detect - down"); PCF_01.write(5, 0); delay(200); PCF_01.write(5, 1); delay(200); PCF_01.write(5, 0); delay(200); PCF_01.write(5, 1); } if (x == right) { Serial.println("detect - right"); PCF_01.write(5, 0); delay(50); PCF_01.write(5, 1); delay(50); PCF_01.write(5, 0); delay(50); PCF_01.write(5, 1); delay(50); PCF_01.write(5, 0); delay(50); PCF_01.write(5, 1); delay(50); PCF_01.write(5, 0); delay(50); PCF_01.write(5, 1); } }
void PCF_8591_write() { for (int i = 0; i < 256; i++) { Wire.beginTransmission(PCF8591); // wake up PCF8591 Wire.write(0x40); // control byte - turn on DAC (binary 1000000) Wire.write(i); // value to send to DAC Wire.endTransmission(); // end tranmission delay(5); } for (int i = 255; i >= 0; --i) { Wire.beginTransmission(PCF8591); // wake up PCF8591 Wire.write(0x40); // control byte - turn on DAC (binary 1000000) Wire.write(i); // value to send to DAC Wire.endTransmission(); // end tranmission delay(5); } } void PCF_8591_read () { Wire.beginTransmission(PCF8591); Wire.write(0x04); Wire.endTransmission(); Wire.requestFrom(PCF8591, 5); adcvalue0 = Wire.read(); // first byete is old data of last time read adcvalue0 = Wire.read(); adcvalue1 = Wire.read(); adcvalue2 = Wire.read(); adcvalue3 = Wire.read(); Serial.print("AIN3: "); Serial.print(adcvalue0); Serial.print(" ,"); Serial.print("AIN0: "); Serial.print(adcvalue1); // sensor Serial.print(" ,"); Serial.print("AIN1: "); Serial.print(adcvalue2); Serial.print(" ,"); Serial.print("AIN2: "); Serial.print(adcvalue3); // Trim pot Serial.println(); delay(1000); } void PCF_8574_read_joystick () { PCF_01.begin(); int x = PCF_01.read8(); Serial.print("Read "); Serial.println(x, BIN); //Serial.println(x, HEX); delay(500); if (x == top) { Serial.println("detect - top"); } if (x == left) { Serial.println("detect - left"); } if (x == pres) { Serial.println("detect - pres"); } if (x == down) { Serial.println("detect - down"); } if (x == right) { Serial.println("detect - right"); } } void PCF_8574_write_buzzer(int d) { PCF_01.begin(); PCF_01.write(5, 1); delay(d); PCF_01.write(5, 0); delay(d); }