I make it short.
I want to place this code (that works fine):
int dark=1000; //Specified in Hz
int light=1300; //Specified in Hz
int buzzPin=12;
int timeOn=300; //specified in milliseconds
int timeOff=300; //specified in millisecods
void setup() {
}
void loop() {
tone(buzzPin, dark);
delay(timeOn);
noTone(buzzPin);
tone(buzzPin, light);
delay(timeOff);
}
Placed innside this code (That also works fine):
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char auth[] = "tdycdPRXW5ovPMtxJ6U9MffR0sdvJm-e";
char ssid[] = "";
char pass[] = "";
int ledred = 14;
int ledyellow = 12;
int ledblue = 13;
void ledgrid(){
if (sensors.getTempCByIndex(0) <20){
digitalWrite(ledblue, HIGH);
digitalWrite(ledyellow, LOW);
digitalWrite(ledred, LOW);
}
if (sensors.getTempCByIndex(0) >=20 && sensors.getTempCByIndex(0) <=22){
digitalWrite(ledblue, LOW);
digitalWrite(ledyellow, HIGH);
digitalWrite(ledred, LOW);
}
if (sensors.getTempCByIndex(0) >25){
digitalWrite(ledblue, LOW);
digitalWrite(ledyellow, LOW);
digitalWrite(ledred, HIGH);
Blynk.notify("WARNNG! Over 60 grader i boksen!");
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(ledred, OUTPUT);
pinMode(ledyellow, OUTPUT);
pinMode(ledblue, OUTPUT);
}
void loop() {
Blynk.run();
sensors.requestTemperatures();
Serial.print("Temperatur: ");
Serial.println(sensors.getTempCByIndex(0));
Blynk.virtualWrite(V5, sensors.getTempCByIndex(0));
ledgrid();
}
So what do i want the first code to do inside the last one?
When the temperature is over 25 i want the buzzer to play the alarm signal in the first code. When the temperature gets under 25, i want the rest of the code run.
I have tried with while loop and the buzzer started and it worked, but it never get outs of the while lopp again and my serial monitor doesent print any values when it was in while loop.
How cn i do that in the simpliest way?