Close

Odpověď na: Uchování hodnoty proměnné

Úvodní stránka Fórum Vaše projekty Arduino Uchování hodnoty proměnné Odpověď na: Uchování hodnoty proměnné

#9325
Navry
Účastník

/*—–( Import needed libraries )—–*/
#include <LiquidCrystal.h>
#include <SD.h>
#include <Wire.h>
#include „RTClib.h“
#include <interval.h>
#include <IRremoteInt.h>
#include „IRremote.h“

/*—–( Declare Constants )—–*/
int receiver = 2; // pin 1 of IR receiver to Arduino digital pin 11
int teplVenk = 1; //Cidlo Commet
int vlhkVenk = 0; //Cidlo Commet
int topTepl = 3; //Pt100 topení teplá
int topStud = 2; //Pt100 topení studena

/*—–( Declare objects )—–*/
IRrecv irrecv(receiver); // create instance of ‚irrecv‘
decode_results results; // create instance of ‚decode_results‘
File logfile;
Interval blink;
LiquidCrystal lcd(3, 4, 5, 6, 7, 8); // initialize the library with the numbers of the interface pins
RTC_DS1307 RTC; // define the Real Time Clock object

/*—–( Declare Variables )—–*/
const int chipSelect = 10;
const long blinkinterval = 100; // interval at which to blink (milliseconds)

void setup() /*—-( SETUP: RUNS ONCE )—-*/
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
lcd.begin(16,2);
Wire.begin();
RTC.begin();

//—————————————-
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.print(„Initializing SD card…“);
pinMode(SS, OUTPUT);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(„Card failed, or not present“);
// don’t do anything more:
while (1) ;
}
Serial.println(„card initialized.“);
// create a new file
char filename[] = „METEO_00.CSV“;
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + ‚0‘;
filename[7] = i%10 + ‚0‘;
if (! SD.exists(filename)) {
// only open a new file if it doesn’t exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}

Serial.print(„Logging to: „);
Serial.println(filename);
logfile.println(„Datum, TeplotaVenku, VlhkostVenku, TopeniTepla, TopeniStudena“);
}/*–(end setup )—*/

void loop() /*—-( LOOP: RUNS CONSTANTLY )—-*/
{
if (irrecv.decode(&results)) // have we received an IR signal?

{
// Serial.println(results.value, HEX); UN Comment to see raw values
translateIR();
irrecv.resume(); // receive the next value
}
//——————————————————–
int SCteplVenk = analogRead(teplVenk);
SCteplVenk = map(SCteplVenk, 0, 1023, -20, 50);

int SCvlhkVenk = analogRead(vlhkVenk);
SCvlhkVenk = map(SCvlhkVenk, 0, 1023, 0, 100);

int SCtopTepl = analogRead(topTepl);
SCtopTepl = map(SCtopTepl, 0, 1023, 10, 120);

int SCtopStud = analogRead(topStud);
SCtopStud = map(SCtopStud, 0, 1023, 10, 120);

String dataString = „“;

DateTime now = RTC.now();
//———————————————————–
if (blink.expired()) {
blink.set(blinkinterval); // set new interval period

logfile.print(now.year(), DEC);
logfile.print(„/“);
logfile.print(now.month(), DEC);
logfile.print(„/“);
logfile.print(now.day(), DEC);
logfile.print(„,“);
logfile.print(now.hour(), DEC);
logfile.print(„:“);
logfile.print(now.minute(), DEC);
logfile.print(„,“);
//———————————————————–
logfile.print(SCteplVenk);
logfile.print(„,“);
logfile.print(SCvlhkVenk);
logfile.print(„,“);
logfile.print(SCtopTepl);
logfile.print(„,“);
logfile.print(SCtopStud);
logfile.print(„,“);
// delay(10000); //čekej 10minut

//————————————————————

logfile.println(dataString);
logfile.flush();
}
//———————————————————–

}/* –(end main loop )– */

/*—–( Declare User-written Functions )—–*/
void translateIR() // takes action based on IR code received
{
int SCteplVenk = analogRead(teplVenk);
SCteplVenk = map(SCteplVenk, 0, 1023, -20, 50);

int SCvlhkVenk = analogRead(vlhkVenk);
SCvlhkVenk = map(SCvlhkVenk, 0, 1023, 0, 100);

int SCtopTepl = analogRead(topTepl);
SCtopTepl = map(SCtopTepl, 0, 1023, 10, 120);

int SCtopStud = analogRead(topStud);
SCtopStud = map(SCtopStud, 0, 1023, 10, 120);
// describing KEYES Remote IR codes

int tlacitko = 0;
switch(results.value)

{
case 0x141: tlacitko = 1;
Serial.println(“ zmacknuto tlacitko 1 „);
lcd.setCursor(0, 0); // set the cursor to (0,0):
lcd.print(SCteplVenk);
lcd.setCursor(0, 1);
lcd.print(SCvlhkVenk);
lcd.setCursor(3, 0);
lcd.print(„C – Teplota“);
lcd.setCursor(3, 1);
lcd.print(„% – Vlhkost“);
break;
case 0x942: tlacitko = 2;
Serial.println(“ zmacknuto tlacitko 2 „);
lcd.setCursor(0, 0);
lcd.print(SCtopTepl);
lcd.setCursor(0, 1);
lcd.print(SCtopStud);
lcd.setCursor(3, 0);
lcd.print(„C – Kotel HOT“);
lcd.setCursor(3, 1);
lcd.print(„C – Kotel COLD“);
break;
case 0x143: tlacitko = 3;
Serial.println(“ zmacknuto tlacitko 3 „);
break;
case 0x944: tlacitko = 4;
Serial.println(“ zmacknuto tlacitko 4 „);
break;
case 0x145: tlacitko = 5;
Serial.println(“ zmacknuto tlacitko 5 „);
break;
case 0x946: tlacitko = 6;
Serial.println(“ zmacknuto tlacitko 6 „);
break;
case 0x147: tlacitko = 7;
Serial.println(“ zmacknuto tlacitko 7 „);
break;
case 0x948: tlacitko = 8;
Serial.println(“ zmacknuto tlacitko 8 „);
break;
case 0x149: tlacitko = 9;
Serial.println(“ zmacknuto tlacitko 9 „);
break;
case 0x940: tlacitko = 0;
Serial.println(“ zmacknuto tlacitko 0 „);
break;
default:
Serial.println(“ jine tlacitko „);
}// End Case

// return tlacitko;

} //END translateIR