Εμφάνιση ενός μόνο μηνύματος
  #6  
Παλιά 06-12-14, 14:36
Το avatar του χρήστη jimbit22
jimbit22 Ο χρήστης jimbit22 δεν είναι συνδεδεμένος
Senior Member
 
Εγγραφή: 27-05-2011
Περιοχή: Ελληνορώσων
Μηνύματα: 491
Προεπιλογή

Κώδικας:
#include <LiquidCrystal.h>
#include <math.h>
#include "RTClib.h"
#include <Time.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define SCREEN1 0
#define SCREEN2 1
#define SCREEN3 2

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress WaterTemperature = { 0x28, 0x62, 0x30, 0xCA, 0x03, 0x00, 0x00, 0xF1 };
DeviceAddress DeviceTemperature = { 0x10, 0x9A, 0x3E, 0x84, 0x02, 0x08, 0x00, 0x4D };
DeviceAddress RoomTemperature = { 0x10, 0xA1, 0xFE, 0x83, 0x02, 0x08, 0x00, 0xFC };

const int TurnHeaterOnTemperature = 27.8;   // The Temperature that sets the Heater on
const int TurnHeaterOffTemperature = 28.0;   // The Temperature that sets the Heater off
const int TurnFanOnTemperature = 27.2;  // The Temperature that sets the Fan on
const int TurnFanOffTemperature = 27.0;  // The Temperature that sets the Fan off

uint16_t relayHeatInterval = 4000;

byte degree[8] PROGMEM = {
  0b00110,
  0b01001,
  0b01001,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

char buffer[20];                //stores sprintf data before lcd.print

/*
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
*/

LiquidCrystal lcd(12, 11, 4, 5, 6, 7);
RTC_DS1307 RTC;
long lcdInterval = 20000;
long previousLCDMillis = 0;
long previousRelayMillis = 0;
// screen to show 
int screen = 0;    
int screenMax = 2;
bool screenChanged = true;   // initially we have a new screen,  by definition 
// defines of the screens to show


int ledPinFilter1 = 26;                 // LED connected to digital pin 28 (Filter 1)
int ledPinFilter2 = 27;                 // LED connected to digital pin 31 (Filter 2)
int ledPinHeater = 29;                  // LED connected to digital pin 27 (Heater)
int ledPinFan = 28;
int RelayPinHeater = 24;
int RelayPinFan = 25;

/*------------------------- SCREEN FUNCTIONS ---------------------------*/

void showWelcome()
{
  lcd.clear();
  lcd.setCursor(1, 0);           
  lcd.print("My Amazon Aquarium");
  lcd.setCursor(3, 1);          
  lcd.print("initialising...");
  lcd.setCursor(1, 2);          
  lcd.print("Aquarium Controler");  
  delay(4000);   // to show message on screen}
}

void showScreen1()
{
  lcd.clear();
  lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row)
  lcd.print("My Amazon Aquarium");
  lcd.setCursor(0, 1);       
  lcd.print("Water Temp:");
  printTemperature(WaterTemperature); 
  lcd.print((char)223); 
  lcd.print("C");
  lcd.setCursor(0, 2);
  lcd.print("PH: 6.8");
  lcd.setCursor(0, 3);
  lcd.print("TDS: 150");
  lcd.setCursor(9, 3);
  lcd.print("ms");
}

void showScreen2()
{
  lcd.clear();
  DateTime now = RTC.now();
  lcd.setCursor(1, 0);
  lcd.print("My Amazon Aquarium");
  lcd.setCursor(0, 1);
  sprintf(buffer, "%02d/%02d/%02d    %02d:%02d:%02d" , now.day(),now.month(),now.year(),now.hour(),now.minute(),now.second());
  lcd.print(buffer);  
  lcd.setCursor(0, 2);
  lcd.print("Room Temp:");  
  printTemperature(RoomTemperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0, 3);
  lcd.print("PH: 6.8");
  lcd.setCursor(8, 3);
  lcd.print("TDS: 150");
  lcd.setCursor(16, 3);
  lcd.print("ms");
  
}

void showScreen3()
{
  lcd.clear();
  DateTime now = RTC.now();
  lcd.setCursor(1, 0);// set the cursor to column 1, line 0 (first row)
  lcd.print("My Amazon Aquarium");
  lcd.setCursor(0, 1);
  sprintf(buffer, "      %02d:%02d:%02d" , now.hour(),now.minute(),now.second());
  lcd.print(buffer);
  lcd.setCursor(0, 2);
  lcd.print("Water Temp:");
  printTemperature(WaterTemperature); 
  lcd.print((char)223); 
  lcd.print("C");
  lcd.setCursor(0, 3);
  lcd.print("Device Temp:");  
  printTemperature(DeviceTemperature);
  lcd.print((char)223);
  lcd.print("C");
 
  
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) lcd.print("Error");
  else  lcd.print(tempC, 1);
}

/*------------------------- END SCREEN FUNCTIONS ---------------------------*/

void setup(void) 
{
  pinMode(ledPinFilter1, OUTPUT);      // sets the digital pin as output
  pinMode(ledPinFilter2, OUTPUT);
  pinMode(ledPinHeater, OUTPUT);
  pinMode(ledPinFan, OUTPUT);
  pinMode(RelayPinHeater, OUTPUT);
  pinMode(RelayPinFan, OUTPUT);
  pinMode(8,OUTPUT);
  digitalWrite(RelayPinHeater, LOW); // Set the Heater to LOW (off)
  
  // Start up the library
  sensors.begin();  
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(WaterTemperature, 11);
  sensors.setResolution(RoomTemperature, 11);
  sensors.setResolution(DeviceTemperature, 11);
  
  lcd.createChar (0, degree);
  lcd.begin(20, 4);
 
  previousLCDMillis = millis();
  previousRelayMillis = millis();
  if (! RTC.isrunning()){
  Serial.println("RTC is NOT running!");
  // following line sets the RTC to the date & time this sketch was compiled
  RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  Serial.begin(9600);
  Wire.begin();
  RTC.begin();
  showWelcome(); 
}

void loop(void) {
  
    if ((millis() - previousRelayMillis) > relayHeatInterval){
      sensors.requestTemperatures();
      if('WaterTemperature' <= 'TurnHeaterOnTemperature') digitalWrite(RelayPinHeater,HIGH);    // sets the Heater on 
      else digitalWrite(RelayPinHeater,LOW);
    }
  // MUST WE SWITCH SCREEN?
  if((millis() - previousLCDMillis) > lcdInterval)              // save the last time you changed the display 
  {
    previousLCDMillis = millis(); 
    screen++;
    if (screen > screenMax) screen = 0;  // all screens done? => start over
    screenChanged = true; 
  }
  if (screenChanged){
    switch(screen){
    case SCREEN1: 
      showScreen1(); 
      break;
    case SCREEN2: 
      showScreen2();
      break;
    case SCREEN3:
      showScreen3();
      break;
    }
  }
  screenChanged = false; // reset for next iteration
}
__________________
3dpg.gr/3D Printers Greece

30lit amano-red cherry shrimp
60lit blue pearl shrimp
130lit hi-tech φυτεμένο RIP
Απάντηση με παράθεση
 
Page generated in 0,01140 seconds with 11 queries