Interface

Hey
I have an assignment where I have to create an interface.
The requirements:
1 Rotator
1 Temperatur sensor
1 LED
1 Button
and
1 LCD/LSD display

My code so far:
#include <LiquidCrystal.h>
LiquidCrystal LSD(10,11,12,13,14,15,16);

int sensorvalue;
int sensorvalue2;
int Knap = 8;
int TEMP = A5;
int POT = A3;
int LED = 9;
boolean LED_STATUS = false;
boolean Button_STATUS = false;

void setup()
{
pinMode(LED, OUTPUT);
pinMode(Knap, INPUT);
Serial.begin(9600);
LSD.begin(16, 2);
}

void loop()
{
sensorvalue = analogRead(TEMP);
sensorvalue2 = analogRead(POT);

boolean Button_STATUS = digitalRead(Knap);

int Normaltemp = sensorvalue/24.0476190476;

// Celsius symbol: lcd.print((char)223);

LSD.clear();
LSD.setCursor(1,0);

if (sensorvalue2 < 200 && sensorvalue2 > -1)
{
int sensorvalue2Min = sensorvalue2/24.0476190476;
LSD.setCursor(0,0);
LSD.print("Min. temp.: ");
LSD.print(sensorvalue2Min);
LSD.print((char)223);
LSD.setCursor(0,1);
LSD.print("POT: ");
LSD.print(sensorvalue2);
if (Button_STATUS)
{
LSD.clear();
sensorvalue2 = analogRead(POT);
int sensorvalue2Min = sensorvalue2/24.0476190476;
LSD.setCursor(0,0);
LSD.print("Aendre min. temp.: ");
LSD.setCursor(0,1);
LSD.print(sensorvalue2Min);
}
}

if (sensorvalue2 < 400 && sensorvalue2 > 201)
{
int sensorvalue2Max = sensorvalue2/24.0476190476;
LSD.setCursor(0,0);
LSD.print(“Max. temp.:”);
LSD.print(sensorvalue2Max);
LSD.print((char)223);
LSD.setCursor(0,1);
LSD.print("POT: ");
LSD.print(sensorvalue2);
if (Button_STATUS)
{
int sensorvalue2Max = sensorvalue2/24.0476190476;
LSD.setCursor(0,0);
LSD.print(sensorvalue2Max);
}
}

if (sensorvalue2 > 401 && sensorvalue2 < 600) //Se temp.
{
LSD.setCursor(0,0);
LSD.print("Temp.: ");
LSD.print(Normaltemp);
LSD.print((char)223);
LSD.setCursor(0,1);
LSD.print("POT: ");
LSD.print(sensorvalue2);
}

if (sensorvalue2 > 601 && sensorvalue2 < 800)
{
LSD.setCursor(0,0);
LSD.print(“TRYYYYYYYYKKKK”);
LSD.setCursor(0,1);
LSD.print(“på knappen”);

if (Button_STATUS)
{
//LSD.clear();
LSD.setCursor(0,0);
LSD.print(“Du trykkede”);
}
}

int sensorvalue2Max2 = sensorvalue2/24.0476190476;
int sensorvalue2Min2 = sensorvalue2/24.0476190476;

if (sensorvalue > sensorvalue2Max2)
{
digitalWrite(LED, HIGH);
LED_STATUS = true;
}
if (sensorvalue < sensorvalue2Min2)
{
digitalWrite(LED, LOW);
LED_STATUS = false;
}

delay(300);
Serial.print("Temperaturen er: “);
Serial.print(sensorvalue);
Serial.print(” ");
Serial.print("Potentemeteret er: “);
Serial.print(sensorvalue2);
Serial.print(” ");
Serial.print("Minimum temp. er: “);
Serial.print(sensorvalue20.9/24.0476190476);
Serial.print(" ");
Serial.print("Maximum temp. er: ");
Serial.print(sensorvalue2
1.1/24.0476190476);
Serial.print(” ");
Serial.print("Normal temp. er: ");
Serial.print(Normaltemp);

if (LED_STATUS)
{
Serial.print(" “);
Serial.println(“LED = Tændt”);
}
else
{
Serial.print(”, ");
Serial.println(“LED = Slukket”);
}
}

This code has one problem - as I see it.
I want the rotator to change the minimum temperatur when the button is clicked. But, if I rotate the rotator it also changes the min. temp.
If I want it to display the min. temp. and rotators number. How do I then proceed?

Picture below.

int Normaltemp = sensorvalue/24.0476190476;I admire your attempt at calculating the value of Normaltemp to 10 decimal places but putting the result in an int variable defeats the object, don't you think ?

I see several problems with your code. Some of your variable names do not convey any meaning. sensorvalue and sensorvalue2 suggest that they are sensor values. But, what sensors and what values? Meaningful names ARE important.

Second, loop() is doing way too much. Move the code that writes to the LCD into separate functions. Create one that can write a string and a value at a specific location. Call that function in many places in loop(), and loop() will get a lot shorter and easier to understand.

Third, you are creating a lot of local variables that have names that look a lot like global variables. That is confusing.

I want the rotator to change the minimum temperatur when the button is clicked. But, if I rotate the rotator it also changes the min. temp.

No, that is not the case. What IS the case is that YOU change the value regardless of whether the switch is pressed, or not. You should not store the output of the analogRead() function in the minimum temperature variable. You should store it in a local variable, with a clearly defined name. When you determine that the switch is pressed, copy the local variable's value to the global minimum temperature variable.

Exactly how to do that is difficult to determine, since you don't have meaningful names, and nothing in the code is called rotator.

@oliverc1234. please make it easy for people to help you by modifying your post and using the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

…R