Facebook
From Mungo Moth, 4 Years ago, written in Plain Text.
This paste is a reply to Untitled from Smelly Coyote - go back
Embed
Viewing differences between Untitled and Re: Untitled
\n#define BLYNK_PRINT Serial
#include 
#include 


/***************************/

#include  // wyswietlacz
#include  //
#include  //czyujnik temp
#include 

String apiKey = "";     //  Enter your Write API key from ThingSpeak
char auth[] = "";
const char *ssid =  "";     // replace with your wifi ssid and wpa2 key
const char *pass =  "";
const char* server = "api.thingspeak.com";



WiFiClient client;
BlynkTimer timer;

#define przekaznik D1

LiquidCrystal_I2C lcd(0x27,16,2); //wyswietlacz
OneWire oneWire(D2 );
DallasTemperature sensors(&oneWire);
 

int counter = 25; // poczatkowa temp.
bool bPress = false;

unsigned long timeStart = 0;



bool isCounting = false;

int CalcSt = 30 ;

float x = 0;
const int Up = D7;
const int Down = D8;
int upbutt = 0;
int uplastbutt = 0;
int downbutt = 0;
int downlastbutt = 0;

void setup(){


  Wire.begin(D5,D6);
  lcd.begin();
  lcd.clear();
  lcd.setCursor(0,0); // napis u gory
  lcd.print("Ustaw temp: ");
  lcd.print(counter);
  lcd.setCursor(0,1); // napis na dole
  lcd.print("T:00.00*C");
  
  sensors.begin();
   pinMode(przekaznik, OUTPUT);
  pinMode(Up, INPUT_PULLUP);
  pinMode(Down, INPUT_PULLUP);
  timeStart=millis();
  isCounting = true;
  
  //////////
  
       Serial.begin(115200);
       delay(10);
       
 
       Serial.println("Connecting to ");
       Serial.println(ssid);
 
 
       WiFi.begin(ssid, pass);
  
      while (WiFi.status() != WL_CONNECTED) 
     {
            delay(500);
            Serial.print(".");
     }
  
      Serial.println("");
      Serial.println("WiFi connected");
       Blynk.begin(auth, ssid, pass);
 timer.setInterval(1000L, sendsen);
}
 
void loop(){
  

  warunek();
  wyswietlacz();
  sendsen();
  checkUp();
  checkDown();


  
   Blynk.run();
  timer.run();
  float temp = sensors.getTempCByIndex(0);
                    if(timeStart2 - previousMillis2 >= t){
                      previousMillis2 = timeStart2;
                         if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(temp); 
                             postStr +="&field2=";
                             postStr += String(x);
                             postStr +="&field3=";
                             postStr += String(CalcSt);  
                                    
                             postStr += "\r\n\r\n";
 
                             client.print("POST /update HTTP/1.1\n");
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
 
                        
                             Serial.println("%. Send to Thingspeak.");
                        }
          client.stop();
 
          Serial.println("Waiting...");
  
  // thingspeak needs minimum 15 sec delay between updates
                    }
}
    void sendsen(){
     sensors.requestTemperatures();
     float temp = sensors.getTempCByIndex(0);
      Blynk.virtualWrite(V5, temp); //sending to Blynk
      Blynk.virtualWrite(V6, x);
      Blynk.virtualWrite(V4, CalcSt);
    }

    BLYNK_WRITE(V1){
       CalcSt = param.asInt();
     

    }   
 

void checkUp(){ // przycisk zliczajacy w gore
  upbutt = digitalRead(Up); //przepisanie do zmiennej przycisku
   if(upbutt !=uplastbutt){ // jeśli stan się zmienił, zwiększ licznik
    if(upbutt == LOW){
      bPress = true;
      CalcSt ++; //dodanie liczby
    }
    delay(20);
  }
  uplastbutt = upbutt; // zapisanie ostatniego stanu
}

void checkDown(){ // przycisk zliczajacy w dol
  downbutt = digitalRead(Down); //przepisanie do zmiennej przycisku
 if(downbutt != downlastbutt){
    if(downbutt == LOW){
      bPress=true;
      CalcSt --;
    }
    delay(20);
  }
  downlastbutt = downbutt; // zapisanie ostatniego stanu
}
/*
 void wyswietlacz(){
float temp = sensors.getTempCByIndex(0);
  lcd.setCursor(0,1);
  lcd.print("T:");
  lcd.print(sensors.getTempCByIndex(0)  );
  Serial.println(temp);   
   lcd.setCursor(0,0);
   lcd.print("Ustaw temp: ");
   lcd.print(CalcSt);
   }




void warunek() { //włącza bądź wyłącza 230v
   sensors.requestTemperatures();
   float temp = sensors.getTempCByIndex(0);
  
  if(temp < CalcSt){ // jeśli temp jest mniejsza od ustaw temp
   digitalWrite(przekaznik, HIGH); // to ma włączyć
  
  }else if(temp > CalcSt+5){ // jeśli temp jest większa niż ustaw temp +5
    digitalWrite(przekaznik, LOW); // to ma wyłączyć
  }

  while(isCounting && millis() - timeStart >= (21600*1000)){ // wyłącznik czasowy 
    isCounting = false;
    for(;;){
   digitalWrite(przekaznik, LOW);
    }
    Serial.println("Off");
  }

      for(int i = 0; i<(temp>CalcSt);i++){
  if(isCounting &&((millis()-timeStart)>=(i*1000))){
    isCounting = false;
     x = (millis()/6000);
 
     lcd.setCursor(11,1);
     lcd.print(x);
   
    }
  }
  */

  
}