#include <TinyWireM.h> //Adafruit
#include <TinyLiquidCrystal_I2C.h> //https://www.arduinolibraries.info/libraries/tiny-liquid-crystal_i2-c
#include "A85_PCF8574.h" //https://github.com/debsahu/A85_PCF8574
//#include <LiquidCrystal_I2C.h>
// SDA - P0 - 0 // CLK - P2 - 2
#define PCF8574_ADDRESS (0x20)
#define GPIO_ADDR 0x27
A85_PCF8574 myPCF8574;
TinyLiquidCrystal_I2C lcd(GPIO_ADDR,20,4);
int counter = 0;
int dir = 1;
bool a ;
unsigned int blinkMillis;
unsigned int buttonMillis;
void pattern1(){
myPCF8574.setBit(0,1); delay(1000);
myPCF8574.setBit(1,1); delay(1000);
myPCF8574.setBit(2,1); delay(1000);
myPCF8574.setBit(3,1); delay(1000);
myPCF8574.setBit(4,1); delay(1000);
myPCF8574.setBit(5,1); delay(1000);
myPCF8574.setBit(6,1); delay(1000);
myPCF8574.setBit(7,1); delay(1000);
myPCF8574.setBit(0,0); delay(1000);
myPCF8574.setBit(1,0); delay(1000);
myPCF8574.setBit(2,0); delay(1000);
myPCF8574.setBit(3,0); delay(1000);
myPCF8574.setBit(4,0); delay(1000);
myPCF8574.setBit(5,0); delay(1000);
myPCF8574.setBit(6,0); delay(1000);
myPCF8574.setBit(7,0); delay(1000);
}
void pattern2(){
myPCF8574.setByte(B11110000);
delay(1000);
myPCF8574.setByte(B00001111);
delay(1000);
}
void pattern3(){
myPCF8574.setByte(B10101010);
delay(1000);
myPCF8574.setByte(B01010101);
delay(1000);
}
void pattern4(){
allon();
delay(1000);
alloff();
}
void alloff(){
myPCF8574.setByte(B00000000);
}
void allon(){
myPCF8574.setByte(B11111111);
}
// Custom Chars
byte Arrow[8] = {
B00000,
B00100,
B00010,
B11111,
B00010,
B00100,
B00000,
B00000
};
void setup()
{
//TinyWireM.begin(); // initialize I2C lib
lcd.init(); // initialize the lcd
lcd.backlight(); // Print a message to the LCD.
lcd.createChar(0, Arrow);
lcd.clear();
lcd.setCursor(0, 0);
lcd.write(byte(0));
lcd.setCursor(1, 0);
lcd.print("1 Pulso - 250 ms");
lcd.setCursor(1, 1);
lcd.print("50 Pulsos - 7 ms");
lcd.setCursor(1, 2);
lcd.print("100 Pulsos - 3,5 ms");
lcd.setCursor(1, 3);
lcd.print("50 Pulsos - 1,45 s");
//delay (2000);
myPCF8574.begin(PCF8574_ADDRESS);
}
// The loop function is called in an endless loop
void loop()
{
//myPCF8574.setByte(B10111110);
// delay(1000);
//pattern1();
//allon();
//delay(1000);
//alloff();
//delay(1000);
// pattern2();
// delay(1000);
//pattern3();
// delay(1000);
// pattern4();
static bool state;
unsigned int currentMillis = millis();
if ((currentMillis - buttonMillis) >= 50) {
buttonMillis = currentMillis;
if (state != myPCF8574.getBit(7)) {
if( state) {
// toggle the LED
myPCF8574.setBit(0,!myPCF8574.getBit(7));
//digitalWrite(onboardLed, !digitalRead(onboardLed));
}
state = !state;
}
}
/*
a = myPCF8574.getBit(7);
if (a){
myPCF8574.setBit(0,1);
}
*/
}