Você está na página 1de 5

#define LCDWidth 240 //define screen width,height

#define LCDHeight 320


#define _Digole_Serial_UART_ //To tell compiler compile the special communication
only,

#include <DigoleSerial.h>
//--------UART setup
#if defined(_Digole_Serial_UART_)
DigoleSerialDisp mydisp(&Serial, 38400); //UART:Arduino UNO: Pin 1(TX)on arduino to
RX on module
#endif
//--------I2C setup
#if defined(_Digole_Serial_I2C_)

#include <Wire.h>
DigoleSerialDisp mydisp(&Wire, '\x27'); //I2C:Arduino UNO: SDA (data line) is on
analog input pin 4, and SCL (clock line) is on analog input pin 5 on UNO and
Duemilanove
#endif
//--------SPI setup
#if defined(_Digole_Serial_SPI_)
DigoleSerialDisp mydisp(8, 9, 10, 11); //SPI:Pin 8: data, 9:clock, 10: SS, 11:SI.
you can assign 255 to SS, and hard ground SS pin on module
#endif

//define draw window


#define DW_X 5
#define DW_Y 8
#define DW_W (LCDWidth - 10)
#define DW_H (LCDHeight - 10)

#include <Bounce.h>

#define AumentoMan 3
#define DiminuirMan 4
#define Sensor 5
#define Reset 6
#define DEBOUNCE_TIME 5 // Tempo em 5 ms
Bounce aumentar = Bounce(AumentoMan,DEBOUNCE_TIME);
Bounce diminuir = Bounce(DiminuirMan,DEBOUNCE_TIME);
Bounce sensor = Bounce(Sensor,DEBOUNCE_TIME);
Bounce reset = Bounce(Reset,DEBOUNCE_TIME);
int ContadorTotal; // Varivel de integrao total
int Contador ; // Varivel de integrao parcial
int Aux ;
const int AlarmeSonoro = 13; //Pino 13 rel para acionamento de sirene

unsigned char i;
int c,d;

void setup() {
/****************************
* Zerando contadores
***************************/
pinMode(AlarmeSonoro, OUTPUT);
pinMode(AumentoMan, INPUT_PULLUP);
pinMode(DiminuirMan, INPUT_PULLUP);
pinMode(Sensor, INPUT_PULLUP);
pinMode(Reset, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Producao");
Contador == 0;
ContadorTotal ==0;
Aux ==0;
Sensor==0;
/***************************
*
*/

// Inicializao de variaveis de entrada:

mydisp.begin(); //initiate serial port


mydisp.setBgColor(255); //set another back ground color
mydisp.clearScreen(); //CLear screen
mydisp.setColor(0);
for (i = 0; i < 4; i++)
{
mydisp.setRotation(i);
mydisp.drawStr(0, 0, "TOTALIZADOR"); //print string at 3,0 in draw window

}
delay(1000);
mydisp.setRotation(0); //change screen direction to 1, screen width and screen
height exchanged
mydisp.setDrawWindow(DW_X, DW_Y, DW_W, DW_H); //set a draw window left/top:5,8,
Height=LCDHeight-15, width=LCDWidth-10
mydisp.setColor(255);
unsigned char j=0;

for (i = 0; i < 10; i++)


{
mydisp.setBgColor(j);
mydisp.setColor(~j);

// mydisp.setBgColor(random(256)); //set another back ground color


mydisp.setRotation(i % 5);
mydisp.cleanDrawWindow();
mydisp.drawStr(0, 0, "TESTE"); //print string at 3,0 in draw window
mydisp.print(i);
delay(500);
j=~j;
}

for (i = 0; i < 49; i++)


{
mydisp.setRotation(i);
mydisp.drawStr(0, 0, "TOTAL DIA"); //print string at 3,0 in draw window
mydisp.drawStr(0, 1, "PARCIAL");
}
}

void loop() {

if(sensor.update()){
if(sensor.read() ==LOW)
sensor.rebounce(300);
Aux = Aux + (Sensor-4);
Contador = Contador +(Sensor-4);
ContadorTotal = ContadorTotal +(Sensor-4);
// Serial.print("Contagem Sensor: ");
// Serial.println(Contador);
// Serial.print("Contagem Total: ");
// Serial.println(ContadorTotal);
delay(1000);

if (Aux > 49 ) {
Aux=0;
Contador=0;
mydisp.clearScreen(); //Limpa Tela

digitalWrite(AlarmeSonoro, HIGH); // Aps contagem 50 liga Sirene durante 5


segundos
delay(2000);
}else {
// Desliga sirene:
digitalWrite(AlarmeSonoro, LOW); // Desliga sirene
}

/*
* Incremento manual da contagem
*/

if(aumentar.update()){
if(aumentar.read() ==LOW){
aumentar.rebounce(300);
if(Contador<49){
Contador ++;
ContadorTotal++;
Aux++;
// Serial.print("Aumento Contagem: ");
// Serial.println(Contador);
mydisp.clearScreen(); //Limpa Tela
}
}
}

/*
* Decremento manual da contagem
*/

if(diminuir.update()){
if(diminuir.read() ==LOW){
diminuir.rebounce(300);
if(Contador>1){
Contador --;
ContadorTotal--;
Aux --;

// Serial.print("Diminuicao Contagem: ");


// Serial.println(Contador);
mydisp.clearScreen(); //Limpa Tela

}
}
}

/*
* Reset dos contadores
*/

if(reset.update()){
if(reset.read() ==LOW){
reset.rebounce(1000);

Contador=0 ;
ContadorTotal=0;
// Serial.print("Contagem Sensor: ");
// Serial.println(Contador);
// Serial.print("Contagem Total: ");
// Serial.println(ContadorTotal);

mydisp.clearScreen(); //CLear screen


mydisp.setRotation(Contador % 8);
mydisp.drawStr(0, 1, "RESET=");
mydisp.print(Contador);

mydisp.setRotation(ContadorTotal % 8);
mydisp.drawStr(0, 0, "RESET=");
mydisp.print(ContadorTotal);
delay(2000);

}
}
}

Você também pode gostar