Vet inte riktigt hur jag skall beskriva mitt problem i ämnesraden med gör att försök här!
Jag har gjort en kod där en tempsensor styr ett relä. Där jag kan ställa reläets aktiveringstemperatur med en pot. detta visas sen på en OLED. funkar bra.
Det jag skulle vilja ha hjälp med är hur jag på ett enkelt sätt kan visa på OLED om relät är aktiverat eller ej. Kan jag återkopplat om en outpuppin är HIGH eller LOW och visa det som "AV" eller "PÅ" i displayen?
I koden skulle jag alltså vilja ha in detta på rad 91 "STATUS" jag skulle vija ha in detta.
Ytterst tacksam för hjälp.
Kod: Markera allt
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h><br>#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
const int relaypin = 8; // relä
int potpin = 0;
int val;
void setup(void)
{
Serial.begin(9600); // initialize the Serial Monitor at a baud rate of 9600
// Start up the library
sensors.begin(); // initialize the DS18B20 temperature sensor:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
pinMode(relaypin, OUTPUT);
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0)); // get and print the temperature in degree Celsius
Serial.print("Vald temp: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(val); // get and print the temperature in degree Celsius
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70,0);
display.println(sensors.getTempCByIndex(0));
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70,10);
display.println(val);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(70,20);
display.println(LÄGE);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("TEMP");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,10);
display.println("VALD TEMP:");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println("STATUS:");
display.display();
val = analogRead(potpin);
val = map(val, 0, 1000, 0, 100);
if (sensors.getTempCByIndex(0) >= val+1)digitalWrite(relaypin,LOW);
if (sensors.getTempCByIndex(0) <= val-1)digitalWrite(relaypin,HIGH);
return val;
delay(10);
}