Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
-atualização dos examples do MPU6050
-criação dos examples do PCF8574 (leitura e escrite)
-criação do metodo de leitura PCF8574
  • Loading branch information
JoaquimFlavio committed Sep 17, 2018
1 parent 11c792c commit 3016184
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 23 deletions.
15 changes: 9 additions & 6 deletions examples/GY521_MPU6050/GY521_MPU6050.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 <GuaraTeca_Hardware.h>
//Inclusão da biblioteca para I2C.
#include <Wire.h>

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

Expand Down
41 changes: 41 additions & 0 deletions examples/PCF8574/Escrita/Escrita.ino
Original file line number Diff line number Diff line change
@@ -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 <GuaraTeca_Hardware.h>
//Inclusão da biblioteca para I2C.
#include <Wire.h>

//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);
}
}
52 changes: 52 additions & 0 deletions examples/PCF8574/Leitura/Leitura.ino
Original file line number Diff line number Diff line change
@@ -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 <GuaraTeca_Hardware.h>
//Inclusão da biblioteca para I2C.
#include <Wire.h>

//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");
}
}
10 changes: 9 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ sentido1_PonteH KEYWORD2
sentido2_PonteH KEYWORD2
trava_PonteH KEYWORD2
controleDeCorrente_PonteH KEYWORD2
desliga_PonteH KEYWORD2
desliga_PonteH KEYWORD2

PCF8574 KEYWORD1 PCF8574
SN74HC595 KEYWORD1 SN74HC595

inicia KEYWORD2
estadoPino KEYWORD2
sentido2 KEYWORD2
leitura KEYWORD2
38 changes: 24 additions & 14 deletions src/GuaraTeca_CI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,51 @@ 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);
digitalWrite(enable, LOW);
}*/
}
void SN74HC595::estadoPino(uint8_t pino, uint8_t estado){
if(estado) buf = buf|(1<<pino);
else buf = buf&~(1<<pino);
if(estado) this->buf = this->buf|(1<<pino);
else this->buf = this->buf&~(1<<pino);

digitalWrite(_ST_CP, LOW);
shiftOut(_DS, _SH_CP, MSBFIRST, buf);
digitalWrite(_ST_CP, HIGH);
digitalWrite(this->_ST_CP, LOW);
shiftOut (this->_DS, this->_SH_CP, MSBFIRST, this->buf);
digitalWrite(this->_ST_CP, HIGH);
}

//CI: PCF8574___________________________________________________________________
PCF8574::PCF8574(uint8_t endereco){
this->_endereco = endereco;
}
void PCF8574::estadoPino(uint8_t pino, bool estado){
if (estado) buf = buf|(1<<pino);
else buf = buf&~(1<<pino);
if (estado) this->buf = this->buf|(1<<pino);
else this->buf = this->buf&~(1<<pino);

Wire.beginTransmission(_endereco);
Wire.write(buf);
Wire.beginTransmission(this->_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;
}

Expand Down
1 change: 1 addition & 0 deletions src/GuaraTeca_Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/GuaraTeca_Sensores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//com este programa. Se não, veja <http://www.gnu.org/licenses/>--------*

#include <GuaraTeca_Hardware.h>
#include <Wire.h>
#include <math.h>

//Sensor Agua Funcoes________________________________________
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3016184

Please sign in to comment.