Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organizando bibliotecas #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Funções especiais (KEYWORD1)
#######################################

Brasilino KEYWORD1
iniciarSerial KEYWORD1
lerSerial KEYWORD1
escreverSerialn KEYWORD1
Expand Down
5 changes: 3 additions & 2 deletions src/Brasilino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ double temperatura(int valorAnalogico)
return temp;
}

/* ULTRASSOM */

/* ULTRASSOM
Ultrassom::Ultrassom(int tp, int ep)
{
pinMode(tp, OUTPUT);
Expand Down Expand Up @@ -66,5 +67,5 @@ long Ultrassom::Medir()
{
Temporizando();
return duracao / 29 / 2;
}
}*/
// Não apagar antes disso
5 changes: 3 additions & 2 deletions src/Brasilino.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#ifndef Brasilino_h
#define Brasilino_h

#include "Ultrassom/BrasilinoUltrassom.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
Expand Down Expand Up @@ -103,6 +103,7 @@ dobro temperatura(int RawADC);

/* Ultrassom */
/* Este trecho e' baseado na biblioteca ultrassonic.h de J. Rodrigo e emcontra-se disponivel originalmente em: https://github.com/JRodrigoTech/Ultrasonic-HC-SR04 */
/*
class Ultrassom
{
public:
Expand All @@ -115,6 +116,6 @@ class Ultrassom
int echo_pino;
long tempo_limite;
long duracao;
};
};*/
#endif
// Não apagar antes disto.
17 changes: 17 additions & 0 deletions src/Ultrassom/BrasilinoUltrassom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Este trecho e' baseado na biblioteca ultrassonic.h de J. Rodrigo e emcontra-se disponivel originalmente em: https://github.com/JRodrigoTech/Ultrasonic-HC-SR04 */
#ifndef BrasilinoUltrassom_h
#define BrasilinoUltrassom_h
class Ultrassom
{
public:
Ultrassom(int tp, int ep);
long Temporizando();
long Medir();

private:
int trig_pino;
int echo_pino;
long tempo_limite;
long duracao;
};
#endif
33 changes: 33 additions & 0 deletions src/Ultrassom/Ultrassom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "BrasilinoUltrassom.h"
#include "Arduino.h"
/* ULTRASSOM */
Ultrassom::Ultrassom(int tp, int ep)
{
pinMode(tp, OUTPUT);
pinMode(ep, INPUT);
trig_pino = tp;
echo_pino = ep;
tempo_limite = 3000; // 3000 µs = 50cm // 30000 µs = 5 m // Configurado para funcionar ate 50 cm.
}

long Ultrassom::Temporizando()
{
digitalWrite(trig_pino, LOW);
delayMicroseconds(2);
digitalWrite(trig_pino, HIGH);
delayMicroseconds(10);
digitalWrite(trig_pino, LOW);

duracao = pulseIn(echo_pino, HIGH, tempo_limite);

if(duracao == 0)
duracao = tempo_limite;

return duracao;
}

long Ultrassom::Medir()
{
Temporizando();
return duracao / 29 / 2;
}