[BBvideo 640,480]http://youtu.be/dTmZUf51iqU[/BBvideo]
Codigo fonte usado:
Código: Selecionar todos
// -- Dosadora -- By Antonio Ricardo Carreira Miranda
//
// -- Versao 1.2 20-04-2014
//
// Saidas porta 9-canal1 -- 10-canal2 -- 11-canal3
//
//* LCD RS pin to digital pin 7
// * LCD Enable pin to digital pin 6
// * LCD D4 pin to digital pin 5
// * LCD D5 pin to digital pin 4
// * LCD D6 pin to digital pin 3
// * LCD D7 pin to digital pin 2
// * LCD R/W pin to ground
// * 10K resistor:
// * ends to +5V and ground
// * wiper to LCD VO pin (pin 3)
//
// teclado porta A0
//
// DS1307 portas A5 A4
//
//
//
//
//
//
//
// ----------------------------------------------------
#define _BTA(a) (a >= 0 && a < 25) // +
#define _BTB(a) (a > 100 && a < 150) // -
#define _BTC(a) (a > 250 && a < 320) // ok
#define _BTD(a) (a > 420 && a < 500) // TESTE
#define _BTE(a) (a > 650 && a < 800) // MENU
static int valor = 0;
#include <Wire.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
#include "RTClib.h"
RTC_DS1307 RTC;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte d1 = EEPROM.read(11);;
byte d2 = EEPROM.read(12);
byte d3 = EEPROM.read(13);
byte c1 = EEPROM.read(1);
byte c2 = EEPROM.read(2);
byte c3 = EEPROM.read(3);
int t1 = 0;
int t2 = 0;
int t3 = 0;
byte BOMBA1 = 9;
byte BOMBA2 = 10;
byte BOMBA3 = 11;
byte hora;
byte minuto;
void setup(){
Wire.begin();
RTC.begin();
lcd.begin(16, 2);
pinMode(BOMBA1, OUTPUT);
pinMode(BOMBA2, OUTPUT);
pinMode(BOMBA3, OUTPUT);
analogWrite(BOMBA1, 0);
analogWrite(BOMBA2, 0);
analogWrite(BOMBA3, 0);
lcd.clear();
lcd.print(" Dosadora V1.2 "); // versao programa
delay(2000);
lcd.clear();
}
void loop() // ---------------- INICIO ---------------------------------
{
DateTime now = RTC.now();
lcd.setCursor(4,0);
digitalClock();
menu();
tempo();
t1 = ((((c1 * 1000) / 10) / 8 ) * d1); // c1 é o tempo em ms para 10ml / 10 (converte em 1ml) / 8 dosagem * d1(quantidade em ml por dia)
t2 = ((((c2 * 1000) / 10) / 8 ) * d2);
t3 = ((((c3 * 1000) / 10) / 8 ) * d3);
}// --------------------- END LOOP ------------------------------------------
// ------- MENU -------------------------------------------------------------
char menu() {
valor = analogRead(0);
if (_BTE(valor))
{
delay(300);
lcd.clear();
do // --------------- Dosagem Canal 1 ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Dosagem Canal 1 ");
lcd.setCursor(0,1);
lcd.print("RA: ");
lcd.print(d1);
lcd.print("ml ");
if (_BTA(valor)) {
delay(300);
d1++ ;
}
if (_BTB(valor)) {
delay(300);
d1--;
}
if (_BTC(valor)) {
delay(300);
lcd.clear();
lcd.print("Gravando RA ");
EEPROM.write(11, d1);
delay(1000);
lcd.clear();
}
} while (!_BTE(valor));
lcd.clear();
delay(300);
do // --------------- Dosagem Canal 2 ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Dosagem Canal 2 ");
lcd.setCursor(0,1);
lcd.print("CA: ");
lcd.print(d2);
lcd.print("ml ");
if (_BTA(valor)) {
delay(300);
d2++ ;
}
if (_BTB(valor)) {
delay(300);
d2--;
}
if (_BTC(valor)) {
delay(300);
lcd.clear();
lcd.print("Gravando CA ");
EEPROM.write(12, d2);
delay(1000);
lcd.clear();
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
do // --------------- Dosagem Canal 3 ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Dosagem Canal 3 ");
lcd.setCursor(0,1);
lcd.print("MG: ");
lcd.print(d3);
lcd.print("ml ");
if (_BTA(valor)) {
delay(300);
d3++ ;
}
if (_BTB(valor)) {
delay(300);
d3--;
}
if (_BTC(valor)) {
delay(300);
lcd.clear();
lcd.print("Gravando MG ");
EEPROM.write(13, d3);
delay(1000);
lcd.clear();
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
do // --------------- Calibra Canal 1 ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Calibra Canal 1 ");
lcd.setCursor(0,1);
lcd.print("10ml: ");
lcd.print(c1);
lcd.print("seg ");
if (_BTA(valor)) {
delay(300);
c1++ ;
}
if (_BTB(valor)) {
delay(300);
c1--;
}
if (_BTC(valor)) {
delay(300);
lcd.clear();
lcd.print("Gravando C1 ");
EEPROM.write(1, c1);
delay(1000);
lcd.clear();
}
if (_BTD(valor)) {
delay(300);
lcd.clear();
lcd.print("Teste ");
analogWrite(BOMBA1, 255);
delay(c1 * 1000);
analogWrite(BOMBA1,0);
lcd.clear();
lcd.print("Teste Finalizado");
delay(1000);
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
do // --------------- Calibra Canal 2 ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Calibra Canal 2 ");
lcd.setCursor(0,1);
lcd.print("10ml: ");
lcd.print(c2);
lcd.print("seg ");
if (_BTA(valor)) {
delay(300);
c2++ ;
}
if (_BTB(valor)) {
delay(300);
c2--;
}
if (_BTC(valor)) {
delay(300);
lcd.clear();
lcd.print("Gravando C2 ");
EEPROM.write(2, c2);
delay(1000);
lcd.clear();
}
if (_BTD(valor)) {
delay(300);
lcd.clear();
lcd.print("Teste ");
analogWrite(BOMBA2, 255);
delay(c2 * 1000);
analogWrite(BOMBA2,0);
lcd.clear();
lcd.print("Teste Finalizado");
delay(1000);
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
do // --------------- Calibra Canal 3 ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Calibra Canal 3 ");
lcd.setCursor(0,1);
lcd.print("10ml: ");
lcd.print(c3);
lcd.print("seg ");
if (_BTA(valor)) {
delay(300);
c3++ ;
}
if (_BTB(valor)) {
delay(300);
c3--;
}
if (_BTC(valor)) {
delay(300);
lcd.clear();
lcd.print("Gravando C3 ");
EEPROM.write(3, c3);
delay(1000);
lcd.clear();
}
if (_BTD(valor)) {
delay(300);
lcd.clear();
lcd.print("Teste ");
analogWrite(BOMBA3, 255);
delay(c3 * 1000);
analogWrite(BOMBA3,0);
lcd.clear();
lcd.print("Teste Finalizado");
delay(1000);
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
do // --------------- AJUSTE -- RELOGIO -- HORA ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Ajuste a HORA ");
lcd.setCursor(0,1);
digitalClock();
if (_BTA(valor)) {
delay(300);
hora++ ;
RTC.adjust(DateTime(2014, 4, 18, hora, minuto, 01));
}
if (_BTB(valor)) {
delay(300);
hora--;
RTC.adjust(DateTime(2014, 4, 18, hora, minuto, 01));
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
do // --------------- AJUSTE -- RELOGIO -- MINUTO ---------------------------------
{
valor = analogRead(0);
lcd.setCursor(0,0);
lcd.print("Ajuste a MINUTO ");
lcd.setCursor(0,1);
digitalClock();
if (_BTA(valor)) {
delay(300);
minuto++ ;
RTC.adjust(DateTime(2014, 4, 18, hora, minuto, 01));
}
if (_BTB(valor)) {
delay(300);
minuto--;
RTC.adjust(DateTime(2014, 4, 18, hora, minuto, 01));
}
} while (!_BTE(valor));
lcd.clear();
delay(500);
}
}
// --------------- RELOGIO -----------------------------
char digitalClock() {
DateTime now = RTC.now();
lcd.print(now.hour(), DEC);
lcd.print(':');
if (now.minute() < 10) lcd.print('0');
lcd.print(now.minute(), DEC);
lcd.print(':');
if (now.second() < 10) lcd.print('0');
lcd.print(now.second(), DEC);
hora = now.hour();
minuto = now.minute();
}
//------------------ TIMER ---------------------------------------
char tempo() {
DateTime now = RTC.now();
// ---------- Timmer 01 --------------------------------------------------
if (now.hour() == 8 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 8 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 8 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 01 ----------------------------------------------
// ---------- Timmer 02 --------------------------------------------------
if (now.hour() == 10 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 10 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 10 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 02 ----------------------------------------------
// ---------- Timmer 03 --------------------------------------------------
if (now.hour() == 12 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 12 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 12 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 03 ----------------------------------------------
// ---------- Timmer 04 --------------------------------------------------
if (now.hour() == 14 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 14 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 14 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 04 ----------------------------------------------
// ---------- Timmer 05 --------------------------------------------------
if (now.hour() == 16 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 16 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 16 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 05 ----------------------------------------------
// ---------- Timmer 06 --------------------------------------------------
if (now.hour() == 18 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 18 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 18 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 06 ----------------------------------------------
// ---------- Timmer 07 --------------------------------------------------
if (now.hour() == 20 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 20 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 20 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 07 ----------------------------------------------
// ---------- Timmer 08 --------------------------------------------------
if (now.hour() == 22 && now.minute() == 01 && now.second() == 01) {
analogWrite(BOMBA1, 255);
lcd.setCursor(0,1);
lcd.print("Dosando RA ");
lcd.print(t1);
delay(t1);
analogWrite(BOMBA1, 0);
lcd.clear();
}
if (now.hour() == 22 && now.minute() == 20 && now.second() == 01) {
analogWrite(BOMBA2, 255);
lcd.setCursor(0,1);
lcd.print("Dosando CA ");
lcd.print(t2);
delay(t2);
analogWrite(BOMBA2, 0);
lcd.clear();
}
if (now.hour() == 22 && now.minute() == 40 && now.second() == 01) {
analogWrite(BOMBA3, 255);
lcd.setCursor(0,1);
lcd.print("Dosando MG ");
lcd.print(t3);
delay(t3);
analogWrite(BOMBA3, 0);
lcd.clear();
}
// ---------- FIM Timmer 08 ----------------------------------------------
}