egg_incubator:258: error: request for member 'year' in 'now', which is of non-class type 'int'
jag misstänker är man kanske behöver nått till lägg för det verkar som att den inte förstår datum och tid
den hårdvara jag har nu är
DTH22 fukt/temp sensor
Arduono uno rv3 "starter kit" så lite motstånd dioder mm
men ingen minneskort display mm som han haft som jag hitta koden hos
men det borde väl gå bra att låta det vara kvar utan att jag har den hårdvaran kanske ska skaffa det sen men börja med att köra med datorn inkopplad.
vore tacksam om jag kunde få lite hjälp jag håller på att försöka lära mig grunderna än.
är kommer koden
Kod: Markera allt
#include "DHT.h"
//#include <LiquidTWI.h>
#include <Wire.h>
#include "Chronodot.h"
#include <SD.h>
#include <Adafruit_RGBLCDShield.h>
/*
Pins used:
LCD:
Connect via i2c, default address #0 (A0-A2 not jumpered)
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
SDshield
* CS to D8
* MOSI to D11
* MISO to D12
* SCK to D13
RGB Backlight
RED to D3
GREEN to D5
BLUE to D6
Humidity Warning to D2
DHT22 to D4
Heating to D9
*/
Chronodot RTC;
DateTime now = RTC.now();
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
File dataFile;
const int chipSelect = 8; //Sparkfun SD shield pin 8, Adafruit SD shield pin 4.
#define DHTPIN 4 // Pin to read from DHT22 sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
int maxT=0, minT=100; //temperature range
int maxH=0, minH=100; //Humidity range
DHT dht(DHTPIN, DHTTYPE);
//here's where the temp and hum setpoints are changed
float tempset=23, tempreset=28;
float humset=60, humreset=58;
int tmem=0, hmem=0;
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
SD.begin(chipSelect);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
lcd.setBacklight(WHITE);
pinMode(9, OUTPUT); //Heating
pinMode(10, OUTPUT); //Needed for the SDbreakout board to work.
digitalWrite (9, HIGH); //This keeps the relay turned off during setup
lcd.begin(16, 2); //set up the LCD's number of columns and rows:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Incubator");
lcd.setCursor(0,1);
lcd.print("Controler");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("By George");
lcd.setCursor(0,1);
lcd.print("Timmermans");
delay(2000);
Serial.println("Initializing Chronodot.");
Serial.println("Date\t\tTime\t\tHumidity\tTemperature\tTempRTC");
dataFile = SD.open("DHT22.txt", FILE_WRITE); // open the file. note that only one file can be open at a time,
dataFile.println("Date\t\tTime\t\tHumidity\tTemperature");
dataFile.close(); // so you have to close this one before opening another.
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
}
delay(500);
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT22");
lcd.clear(); //Display error on vfd display.
lcd.setCursor(0,0);
lcd.print("Failed to read");
lcd.setCursor(0,1);
lcd.print("from DHT22");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
dataFile = SD.open("DHT22.txt", FILE_WRITE);
dataFile.println("Failed to read from DHT22"); //Write error message too MicrSD.
dataFile.close(); //Close the file.
lcd.setBacklight(RED);
}
else {
temperature(h, t); //Check temerature and humidity and control relays.
if (now.second() == 0) { //Log data every minute(RTC needed)
debug(h, t, RTC.now());
Log(h, t, RTC.now());
}
else {
LCD(h, t, RTC.now());
}
}
}
void temperature (float h, float t) {
if (tempreset<=t && t<=tempset && tmem==1) {
digitalWrite (9, HIGH);
}
if (t>=tempset) {
tmem==1,
lcd.setBacklight(GREEN);
digitalWrite (9, HIGH);
}
if (t<tempreset) {
tmem==0,
lcd.setBacklight(BLUE);
digitalWrite (9, LOW);
}
if (humreset<=h && h<=humset && hmem==1) {
digitalWrite (2, LOW);
}
if (h>humset) {
hmem==1,
digitalWrite (2, LOW);
}
if (h<humreset) {
hmem==0,
digitalWrite (2, HIGH);
}
}
void Log(float h, float t, DateTime now) {
dataFile = SD.open("DHT22.txt", FILE_WRITE);
if(now.day() < 10) dataFile.print("0");
dataFile.print(now.day(), DEC);
dataFile.print('/');
if(now.month() < 10) dataFile.print("0");
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print('\t');
if(now.hour() < 10) dataFile.print("0");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
if(now.minute() < 10) dataFile.print("0");
dataFile.print(now.minute(), DEC);
dataFile.print(':');
if(now.second() < 10) dataFile.print("0");
dataFile.print(now.second(), DEC);
dataFile.print("\t");
dataFile.print(h);
dataFile.print("\t\t");
dataFile.println(t);
dataFile.close(); //Close the file.
delay(100);
}
void debug(float h, float t, DateTime now) {
if(now.day() < 10) Serial.print("0");
Serial.print(now.day(), DEC);
if(now.month() < 10) Serial.print("0");
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print('/\t');
if(now.hour() < 10) Serial.print("0");
Serial.print(now.hour(), DEC);
Serial.print(':');
if(now.minute() < 10) Serial.print("0");
Serial.print(now.minute(), DEC);
Serial.print(':');
if(now.second() < 10) Serial.print("0");
Serial.print(now.second(), DEC);
Serial.print("\t");
Serial.print(h);
Serial.print("\t\t");
Serial.print(t);
Serial.print("\t\t");
Serial.println(now.tempC());
delay(100);
}
void LCD(float h, float t, DateTime now) {
lcd.clear(); //Display Time, Humidity and Temperature on LCD.
lcd.setCursor(0,0);
if(now.hour() < 10) lcd.print("0");
lcd.print(now.hour(), DEC);
lcd.setCursor(2,0);
lcd.print(":");
lcd.setCursor(3,0);
if(now.minute() < 10) lcd.print("0");
lcd.print(now.minute(), DEC);
lcd.setCursor(5,0);
lcd.print(":");
lcd.setCursor(6,0);
if(now.second() < 10) lcd.print("0");
lcd.print(now.second(), DEC);
lcd.setCursor(10,0);
lcd.print("H");
lcd.setCursor(11,0);
lcd.print(h,1);
lcd.setCursor(15,0);
lcd.print("%");
lcd.setCursor(0,1);
if(now.day() < 10) lcd.print("0");
lcd.print(now.day(), DEC);
lcd.setCursor(2,1);
lcd.print('/');
lcd.setCursor(3,1);
if(now.month() < 10) lcd.print("0");
lcd.print(now.month(), DEC);
lcd.setCursor(5,1);
lcd.print('/');
lcd.setCursor(6,1);
lcd.print(now.year()-2000, DEC);
lcd.setCursor(10,1);
lcd.print("T");
lcd.setCursor(11,1);
lcd.print(t,1);
lcd.setCursor(15,1);
lcd.print((char)223); // degree symbol
}
får inte till en sån där scroll lista någon som vet hur man gör så det blir lättare att läsa så ändrar jag koden