diff --git a/examples/GY521_MPU6050/GY521_MPU6050.ino b/examples/GY521_MPU6050/GY521_MPU6050.ino index 705fa62..4ae0516 100644 --- a/examples/GY521_MPU6050/GY521_MPU6050.ino +++ b/examples/GY521_MPU6050/GY521_MPU6050.ino @@ -9,26 +9,29 @@ * !!!!Conectar nas portas I2C do micro-controlador * * Autor: Joaquim Flávio A Q Gomes___________________ - * Data: 06/2018_____________________________________ + * Data: 09/2018_____________________________________ */ //Inclusão da biblioteca. #include +//Inclusão da biblioteca para I2C. +#include //Definimos o endereço do sensor no barramento I2C. #define enderecoPadrao 0x68 -//Definimos a variavel que irá armazenar os dados. +//Definimos o aray que irá armazenar os dados. int dados[7]; void setup() { //Inicialização do monitor Serial em 9600. Serial.begin(9600); + //Inicializamos a biblioteca para I2C. + Wire.begin(); /* - * Inicializamos o sensor de condutividade em liquidos - * e solidos (sensor agua) no endereço previamente - * definidodo barramento I2C. - */ + * Inicializamos o sensor giroscopio/acelerometro no + * endereço previamente definidodo no barramento I2C. + */ inicia_GY521_MPU6050(enderecoPadrao); } diff --git a/examples/PCF8574/Escrita/Escrita.ino b/examples/PCF8574/Escrita/Escrita.ino new file mode 100644 index 0000000..71a0342 --- /dev/null +++ b/examples/PCF8574/Escrita/Escrita.ino @@ -0,0 +1,41 @@ +/* + * Guarateca_Hardware *** by *** Guarabots___________ + * + * [CI: PCF8574 e semelhantes] + * + * Utilização das funçoes de manipulação do registrador + * de deslocamento (PCF8574). + * + * !!!!Conectar nas portas I2C do micro-controlador + * + * Autor: Joaquim Flávio A Q Gomes___________________ + * Data: 09/2018_____________________________________ + */ + +//Inclusão da biblioteca. +#include +//Inclusão da biblioteca para I2C. +#include + +//Declaramos o objeto e definimos seu endereço. +PCF8574 expansor(0x3F); + +void setup() { + //Inicialização do monitor Serial em 9600. + Serial.begin(9600); + //Inicializamos a biblioteca para I2C. + Wire.begin(); +} + +void loop() { + /* + * Utilizamos o metodo "estadoPino(pino, endereço)" para + * alterar o estado do pino: HIGH/LOW. + */ + for(int i=0;i<8;i++){ + expansor.estadoPino(i, HIGH); + delay(500); + expansor.estadoPino(i, LOW); + delay(500); + } +} diff --git a/examples/PCF8574/Leitura/Leitura.ino b/examples/PCF8574/Leitura/Leitura.ino new file mode 100644 index 0000000..581f61e --- /dev/null +++ b/examples/PCF8574/Leitura/Leitura.ino @@ -0,0 +1,52 @@ +/* + * Guarateca_Hardware *** by *** Guarabots___________ + * + * [CI: PCF8574 e semelhantes] + * + * Utilização das funçoes de manipulação do registrador + * de deslocamento (PCF8574). + * + * !!!!Conectar nas portas I2C do micro-controlador + * + * Autor: Joaquim Flávio A Q Gomes___________________ + * Data: 09/2018_____________________________________ + */ + +//Inclusão da biblioteca. +#include +//Inclusão da biblioteca para I2C. +#include + +//Declaramos o objeto e definimos seu endereço. +PCF8574 expansor(0x3F); + +void setup() { + //Inicialização do monitor Serial em 9600. + Serial.begin(9600); + //Inicializamos a biblioteca para I2C. + Wire.begin(); + /* + * Utilizamos o metodo "leitura(void)" para realizar a + * leitura do estado de todos os pinos. + * Esse metodo retorna um byte com todos os pinos lidos. + */ + Serial.println(expansor.leitura(), BIN); + /* + * O metodo "leitura(void)" tambem armazena o estado dos + * pino de forma individual, em um vetor do tipo "bool" + * cada posição deste vetor representa necessariamente o + * pino lido. ex: a leitura do pino 0 sera armazenada em + * "expansor.porta[0]". + */ + for(int i=0;i<8;i++){ + Serial.println(expansor.porta[i]?"HIGH":"LOW"); + } +} + +void loop() { + expansor.leitura(); + Serial.println("Leitura dos pinos: "); + for(int i=0;i<8;i++){ + Serial.println(expansor.porta[i]?"HIGH":"LOW"); + } +} diff --git a/keywords.txt b/keywords.txt index 8ac4455..873d617 100644 --- a/keywords.txt +++ b/keywords.txt @@ -42,4 +42,12 @@ sentido1_PonteH KEYWORD2 sentido2_PonteH KEYWORD2 trava_PonteH KEYWORD2 controleDeCorrente_PonteH KEYWORD2 -desliga_PonteH KEYWORD2 \ No newline at end of file +desliga_PonteH KEYWORD2 + +PCF8574 KEYWORD1 PCF8574 +SN74HC595 KEYWORD1 SN74HC595 + +inicia KEYWORD2 +estadoPino KEYWORD2 +sentido2 KEYWORD2 +leitura KEYWORD2 \ No newline at end of file diff --git a/src/GuaraTeca_CI.cpp b/src/GuaraTeca_CI.cpp index 525b83d..41c4214 100644 --- a/src/GuaraTeca_CI.cpp +++ b/src/GuaraTeca_CI.cpp @@ -25,9 +25,9 @@ SN74HC595::SN74HC595(uint8_t SH_CP, uint8_t ST_CP, uint8_t DS, uint8_t enable){ this->_DS = DS; } void SN74HC595::inicia(void){ - pinMode(_SH_CP, OUTPUT); - pinMode(_ST_CP, OUTPUT); - pinMode(_DS, OUTPUT); + pinMode(this->_SH_CP, OUTPUT); + pinMode(this->_ST_CP, OUTPUT); + pinMode(this->_DS, OUTPUT); /*if(enable != -1){ pinMode(enable, OUTPUT); @@ -35,12 +35,12 @@ void SN74HC595::inicia(void){ }*/ } void SN74HC595::estadoPino(uint8_t pino, uint8_t estado){ - if(estado) buf = buf|(1<buf = this->buf|(1<buf = this->buf&~(1<_ST_CP, LOW); + shiftOut (this->_DS, this->_SH_CP, MSBFIRST, this->buf); + digitalWrite(this->_ST_CP, HIGH); } //CI: PCF8574___________________________________________________________________ @@ -48,18 +48,28 @@ PCF8574::PCF8574(uint8_t endereco){ this->_endereco = endereco; } void PCF8574::estadoPino(uint8_t pino, bool estado){ - if (estado) buf = buf|(1<buf = this->buf|(1<buf = this->buf&~(1<_endereco); + Wire.write(this->buf); Wire.endTransmission(); } byte PCF8574::leitura(void){ //Solicita 1Byte de dados do endereço informado - Wire.requestFrom(_endereco, 1); - if (Wire.available()) return Wire.read(); + Wire.requestFrom(this->_endereco, 1); + + if (Wire.available()){ + byte r = Wire.read(); + byte a=1; + + for (int i = 0; i < 8; i++){ + this->porta[i] = byte(r & a) > 0 ? 1 : 0; + a*=2; + } + return r; + } return -1; } diff --git a/src/GuaraTeca_Hardware.h b/src/GuaraTeca_Hardware.h index 90af5a4..1628a9e 100644 --- a/src/GuaraTeca_Hardware.h +++ b/src/GuaraTeca_Hardware.h @@ -195,6 +195,7 @@ class PCF8574{ PCF8574(uint8_t endereco); void estadoPino (uint8_t pino, bool estado); byte leitura (void); + bool porta[8]; private: byte buf = 0; uint8_t _endereco; diff --git a/src/GuaraTeca_Sensores.cpp b/src/GuaraTeca_Sensores.cpp index 34c9fd6..f3fa5f2 100644 --- a/src/GuaraTeca_Sensores.cpp +++ b/src/GuaraTeca_Sensores.cpp @@ -16,7 +16,6 @@ //com este programa. Se não, veja --------* #include -#include #include //Sensor Agua Funcoes________________________________________ @@ -151,7 +150,6 @@ int estado_Botao(uint8_t pin){ } //Giroscopio/Acelerometro Funcoes_______________________________________________________________ void inicia_GY521_MPU6050(char endereco){ - //Wire.begin(); Wire.beginTransmission(endereco); Wire.write(0x6B); //Inicializa o MPU-6050