/* Carlos Soto check 2/11/10 Manejo LCD Expansor */ //Este programa maneja la LCD, y el expansor PCF8574 para el //manejo de ocho entradas por medio del protocolo i2c, además //de realizar la validación para el manejo de las cuatro entradas //que se tienen previstas para el HAPA. #include <Wire.h> int dd=50; #define expander B0100000 // Direccion del expansor alpha-num // 0 1 0 0 A2 A1 A0 // 0 1 0 0 0 0 0 // Note that the R/W bit is not part of this address. // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(13, 12, 11, 10, 9, 8); //Manejo de Entradas const int inPin01 = 4; const int inPin02 = 5; const int inPin03 = 6; const int inPin04 = 7; //Manejo de Entradas en setup int inState01 = 0; int inState02 = 0; int inState03 = 0; int inState04 = 0; void setup() { Wire.begin(); Serial.begin(9600); // set up the LCD's number of rows and columns: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("HAPA 001"); } void loop() { expanderWrite (B10000000); delay(dd); expanderWrite (B01000000); delay(dd); expanderWrite (B00100000); delay(dd); expanderWrite (B00010000); delay(dd); expanderWrite (B00001000); delay(dd); expanderWrite (B00000100); delay(dd); expanderWrite (B00000010); delay(dd); expanderWrite (B00000001); delay(dd); expanderWrite (B11111111); delay(dd); inState01 = digitalRead(inPin01); inState02 = digitalRead(inPin02); inState03 = digitalRead(inPin03); inState04 = digitalRead(inPin04); if (inState04 == LOW) { // turn LED on: lcd.setCursor(5, 1); // print the number of seconds since reset: lcd.print("cuatro"); } else if (inState03 == LOW) { // turn LED on: lcd.setCursor(5, 1); // print the number of seconds since reset: lcd.print("tres"); } else if (inState02 == LOW) { // turn LED on: lcd.setCursor(5, 1); // print the number of seconds since reset: lcd.print("dos"); } else if (inState01 == LOW) { // turn LED on: lcd.setCursor(5, 1); // print the number of seconds since reset: lcd.print("uno"); } else { // turn LED on: lcd.setCursor(5, 1); // print the number of seconds since reset: lcd.print(" "); } // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); } void expanderWrite(byte _data ) { Wire.beginTransmission(expander); Wire.send(_data); Wire.endTransmission(); }