#include <UTFT.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
UTFT myGLCD(ITDB43,38,39,40,41);
volatile int NbTopsFan = 0;
int Calc;
int hallsensor = 22;
int sensorPin = A5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
// Parámetros de la gráfica
int xinicial = 16; int ybase = 215; // corresponde a la base de la gráfica de 0 l/min
int escala = 1; // número de pixeles entre cada grado centígrado
const int maxlecturas = 298; // Número máximo de datos en las bases de datos
float lectura[maxlecturas]; // lista o base de datos de las lecturas actuales
float lecturaprevia[maxlecturas]; // lista o base de datos de las lecturas previas
int j; // contador para recorrer los datos de la lista actual
char textBuff[20]; // Convierte valores numéricos a caracteres de texto
void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
pinMode(hallsensor, INPUT);
Serial.begin(9600);
attachInterrupt(22, rpm, RISING);
// Marco y marcadores para graficar temperaturas
myGLCD.setColor(255,0,0);
//Divisores eje X
for (int i=15; i<316; i+=10)
myGLCD.drawLine(i, 226, i, 231);
// Divisores eje Y
for (int i=75; i<226; i+=10)
myGLCD.drawLine(9, i, 14, i);
// Marco para gráfica
myGLCD.setColor(255,0,0); myGLCD.drawRect(15, 75, 315, 225);
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
myGLCD.print("ESPOCH", CENTER, 2);
myGLCD.setFont(SmallFont);
myGLCD.print("SENSOR DE FLUJO", 105, 22);
myGLCD.setFont(BigFont);
myGLCD.print("l/min",105,40);
// Genera base de datos inicial
lineabase();
}
void rpm ()
{
NbTopsFan++;
}
void leersensor()
{
rpm();
Calc = (NbTopsFan / 5.5);
Calc = random(0,130); // Borra esta linea, para que coloques los cálculos del sensor de flujo
}
//función para generar la base de datos inicial
void lineabase()
{
for (int i=0; i<maxlecturas; i++)
{
leersensor();
lectura[i] = Calc;
}
}
void grafica1()
{
for (int i=xinicial; i<maxlecturas; i++)
{
myGLCD.drawPixel(i+xinicial,ybase - Calc);
}
}
void grafica()
{
lecturaprevia[j]=lectura[j]; // almacena el dato actual
// Recorre una sola posición. Los datos de la lista se recorren de adelante hacia atrás, para dejar libre el último espacio
// de la lista
lectura[j] = lectura[j+1];
myGLCD.setColor(0,0,0); myGLCD.drawPixel(j+xinicial, ybase-escala*lecturaprevia[j]); //borra el pixel previo
myGLCD.setColor(0,255,0); myGLCD.drawPixel(j+xinicial, ybase-escala*lectura[j]); //grafica el pixel nuevo
j++;
// Continua recorriendo los datos hasta llegar al último de la lista, en el que se colocará la nueva lectura de
// del sensor
if (j==maxlecturas-1)
{
leersensor();
lecturaprevia[j]=lectura[j];
lectura[j] = Calc;
myGLCD.setColor(255,255,255); sprintf(textBuff, "%03d", Calc); myGLCD.print(textBuff,52,40);
myGLCD.setColor(0,0,0); myGLCD.drawPixel(j+xinicial, ybase-escala*lecturaprevia[j]); //borra el pixel previo
myGLCD.setColor(0,255,0); myGLCD.drawPixel(j+xinicial, ybase-escala*lectura[j]); //grafica el pixel nuevo
j=0;
}
}
void loop ()
{
grafica();
}