# How to store a variable to move...

Display temperature in Celsius continuously.

How would we move this variable?
Most recent temperature is in upper left of top row, measurement before that in the middle of the top row, and the oldest measurement in the upper right top row.

How would else ifs be used here to calculate?
“Up” is displayed at the bottom right if current average is higher than previous average. “Down” is displayed at bottom left if current average is lower than previous average. “Steady” is displayed in bottom middle if average is not more than 0.15 degrees from previous average.

I am using the SparkFun redboard with Arduino code. We have a (16,2) LCD to print on and are collecting temperature using a sensor and are trying to print the current value at (0,0) the previous value (6,0) and the oldest (12,0). I am currently unsure how to store these as variables and use them. The first two values are to change every .75 seconds.

here is our current code:

/*
SparkFun Inventor’s Kit
Circuit 4B - Temperature Sensor

The LCD will display readings from a temperature sensor in degrees Celsius and Fahrenheit.
*/

#include <LiquidCrystal.h> //the liquid crystal libarry contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // tell the RedBoard what pins are connected to the display
float voltage = 0; //the voltage measured from the TMP36
float degreesC = 0; //the temperature in Celsius, calcuated from the voltage

void setup()
{
lcd.begin(16, 2); //initialize the lcd display to 2 lines, 16 wide
lcd.clear(); // clear the display of any random junk
pinMode(A0, INPUT); //connect pin A0 to the middle pin of the temperature sensor
pinMode(5, INPUT_PULLUP); //connect pin 5 to the button
pinMode(A1, INPUT); //connect pin A1 to the photoresistor as in diagrams for SparkFun 1C
}

void loop() {
int degreesCP=degreesC;
voltage = analogRead(A0) * 0.004882814; //convert the analog reading, which varies from 0 to 1023, back to a voltage value from 0-5 volts
degreesC = (voltage - 0.5) * 100.0; //convert the voltage to a temperature in degrees Celsius
lcd.clear(); //clear the LCD

lcd.setCursor(0,0); //set the cursor to the top left position //now
lcd.print(degreesC); //print the degrees Celsius
degreesC=degreesCP;
delay(750);
lcd.setCursor(6,0); //set the cursor to the top left position //previous
lcd.print(degreesCP); //print the degrees Celsius
delay(750);
lcd.setCursor(12,0); //set the cursor to the top left position //oldest
lcd.print(degreesC); //print the degrees Celsius

delay(750); //delay for .75 second between each reading (this makes the display less noisy)
}

Display on what? You've left out a ton of detail. Please understand that none of us are sitting there with you working on this. You have to describe the WHOLE thing to us.

How would we move this variable?

Which variable? I don't see any code.

Try to imagine we don't have a clue what you're talking about.

Start again.

Try to imagine we don't have a clue what you're talking about.

No need to imagine.

It is a fact.

We don't have a clue what you're talking about.

1) Store readings in array. Update array by moving the two most recent readings one position and adding new reading to free position. 2) Display array elements at desired position.

Display temperature in Celsius continuously.

How would we move this variable?
Most recent temperature is in upper left of top row, measurement before that in the middle of the top row, and the oldest measurement in the upper right top row.

I am using the SparkFun redboard with Arduino code. We have a (16,2) LCD to print on and are collecting temperature using a sensor and are trying to print the current value at (0,0) the previous value (6,0) and the oldest (12,0). I am currently unsure how to store these as variables and use them. The first two values are to change every .75 seconds.

here is our current code:

/*
SparkFun Inventor’s Kit
Circuit 4B - Temperature Sensor

The LCD will display readings from a temperature sensor in degrees Celsius and Fahrenheit.
*/

#include <LiquidCrystal.h> //the liquid crystal libarry contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // tell the RedBoard what pins are connected to the display
float voltage = 0; //the voltage measured from the TMP36
float degreesC = 0; //the temperature in Celsius, calcuated from the voltage

void setup()
{
lcd.begin(16, 2); //initialize the lcd display to 2 lines, 16 wide
lcd.clear(); // clear the display of any random junk
pinMode(A0, INPUT); //connect pin A0 to the middle pin of the temperature sensor
pinMode(5, INPUT_PULLUP); //connect pin 5 to the button
pinMode(A1, INPUT); //connect pin A1 to the photoresistor as in diagrams for SparkFun 1C
}

void loop() {
int degreesCP=degreesC;
voltage = analogRead(A0) * 0.004882814; //convert the analog reading, which varies from 0 to 1023, back to a voltage value from 0-5 volts
degreesC = (voltage - 0.5) * 100.0; //convert the voltage to a temperature in degrees Celsius
lcd.clear(); //clear the LCD

lcd.setCursor(0,0); //set the cursor to the top left position //now
lcd.print(degreesC); //print the degrees Celsius
degreesC=degreesCP;
delay(750);
lcd.setCursor(6,0); //set the cursor to the top left position //previous
lcd.print(degreesCP); //print the degrees Celsius
delay(750);
lcd.setCursor(12,0); //set the cursor to the top left position //oldest
lcd.print(degreesC); //print the degrees Celsius

delay(750); //delay for .75 second between each reading (this makes the display less noisy)
}

Display temperature in Celsius continuously.

How would we move this variable?
Most recent temperature is in upper left of top row, measurement before that in the middle of the top row, and the oldest measurement in the upper right top row.

I am using the SparkFun redboard with Arduino code. We have a (16,2) LCD to print on and are collecting temperature using a sensor and are trying to print the current value at (0,0) the previous value (6,0) and the oldest (12,0). I am currently unsure how to store these as variables and use them. The first two values are to change every .75 seconds.

here is our current code:

/*
SparkFun Inventor’s Kit
Circuit 4B - Temperature Sensor

The LCD will display readings from a temperature sensor in degrees Celsius and Fahrenheit.
*/

#include <LiquidCrystal.h> //the liquid crystal libarry contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // tell the RedBoard what pins are connected to the display
float voltage = 0; //the voltage measured from the TMP36
float degreesC = 0; //the temperature in Celsius, calcuated from the voltage

void setup()
{
lcd.begin(16, 2); //initialize the lcd display to 2 lines, 16 wide
lcd.clear(); // clear the display of any random junk
pinMode(A0, INPUT); //connect pin A0 to the middle pin of the temperature sensor
pinMode(5, INPUT_PULLUP); //connect pin 5 to the button
pinMode(A1, INPUT); //connect pin A1 to the photoresistor as in diagrams for SparkFun 1C
}

void loop() {
int degreesCP=degreesC;
voltage = analogRead(A0) * 0.004882814; //convert the analog reading, which varies from 0 to 1023, back to a voltage value from 0-5 volts
degreesC = (voltage - 0.5) * 100.0; //convert the voltage to a temperature in degrees Celsius
lcd.clear(); //clear the LCD

lcd.setCursor(0,0); //set the cursor to the top left position //now
lcd.print(degreesC); //print the degrees Celsius
degreesC=degreesCP;
delay(750);
lcd.setCursor(6,0); //set the cursor to the top left position //previous
lcd.print(degreesCP); //print the degrees Celsius
delay(750);
lcd.setCursor(12,0); //set the cursor to the top left position //oldest
lcd.print(degreesC); //print the degrees Celsius

delay(750); //delay for .75 second between each reading (this makes the display less noisy)
}

As I understand, you want to store 3 temperature values : the current one, the previous one and the one before that. They are displayed in that order from left to right.

So you need 3 variables, say Tcurr, Tprev and Told. Each time you get a measurement, you just have to shift the values Told = Tprev; Tprev = Tcurr; Tcurr = measured; Then you erase the display and just display the variables as you already did

how would we set these at different times? I'm lost on where to place these variables.

OK, let's cut to the chase.

Please go and read the instructions, then go back and modify your post using the "More --> Modify" option you will find to the bottom right of the post, to mark up the code (but it always needs to be the complete code) as such so we can examine it conveniently and accurately. Please do not post a ".ino" file as an attachment - that would mean that you are expecting people to actually load it to their IDE to look at it and that is extra unnecessary labour. In fact, attachments do not always show properly on different operating systems.

If you do not mark it up as code, it is as you see, garbled and is certainly anything but easy to read.

Note: Also mark up any data - as a separate section - in the same way. This includes error output that you get from the IDE.

And - before you post any code, use "Auto Format" in the Tools menu of the IDE to properly present the code. You can then use the "copy for forum" function in order to paste it into a message with the "code" tags already provided.

Try and avoid unnecessary white space (blank lines). You should only use these to separate functional blocks of code.

Following my previous answer, here is what I suggest

``````/*
SparkFun Inventor's Kit
Circuit 4B - Temperature Sensor

The LCD will display readings from a temperature sensor in degrees Celsius and Fahrenheit.
*/

#include <LiquidCrystal.h>                  //the liquid crystal libarry contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);    // tell the RedBoard what pins are connected to the display
float voltage = 0;                          //the voltage measured from the TMP36
float degreesC = 0;                         //the temperature in Celsius, calcuated from the voltage
int Tcurr = 0;
int Tprev = 0;
int Told = 0;

void setup() {
lcd.begin(16, 2);      //initialize the lcd display to 2 lines, 16 wide
lcd.clear();           // clear the display of any random junk
pinMode(A0, INPUT);   //connect pin A0 to the middle pin of the temperature sensor
//  pinMode(5, INPUT_PULLUP); //connect pin 5 to the button
//  pinMode(A1, INPUT);   //connect pin A1 to the photoresistor as in diagrams for SparkFun 1C
}

void loop() {
voltage = analogRead(A0) * 0.004882814;   //convert the analog reading, which varies from 0 to 1023, back to a voltage value from 0-5 volts
degreesC = (voltage - 0.5) * 100.0;       //convert the voltage to a temperature in degrees Celsius

Told = Tprev;
Tprev = Tcurr;
Tcurr = (int)degreesC;

lcd.clear();                              //clear the LCD

lcd.setCursor(0, 0);                      //set the cursor to the top left position //now
lcd.print(Tcurr);                      //print the degrees Celsius
delay(750);
lcd.setCursor(6, 0);                      //set the cursor to the top left position //previous
lcd.print(Tprev);                      //print the degrees Celsius
delay(750);
lcd.setCursor(12, 0);                      //set the cursor to the top left position //oldest
lcd.print(Told);                      //print the degrees Celsius

delay(750);                              //delay for .75 second between each reading (this makes the display less noisy)
}
``````

To store something in a variable you create the variable:

``````int myVariable;
``````

and you assign it a value:

``````myVariable = 6;
``````

You're already doing this with the voltage and degreesC variables in your code.

Be sure you give your variable the appropriate type for the kind of data you want it to hold. Look in the reference area of this site for more on data types. It looks to me like you need three variables, one for current Temp, on for last temp, and one for old temp. Whenever you read a new temp set old temp equal to last temp, last temp equal to the current temp and the current temp to the new value.

@the00daltonator, do not cross-post. Threads merged.

@OP

The following diagrams and codes may be helpful for you to achieve what you want in respect of displaying Tcurr, Tprev, and Told.

Pseudo Codes:
(1) Acquire current temperature from your LM35 sensor and save the float value into float array named tempArray[0].

...................

``````#include <LiquidCrystal.h>                  //the liquid crystal libarry contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);    // tell the RedBoard what pins are connected to the display
//float voltage = 0;                          //the voltage measured from the TMP36
float degreesCurr = 0, degreesPrev, degreesOld;                         //the temperature in Celsius, calcuated from the voltage
float tempArray[3] = {0.0, 0.0, 0.0};

void setup()
{
lcd.begin(16, 2);      //initialize the lcd display to 2 lines, 16 wide
lcd.clear();           // clear the display of any random junk
// pinMode(A0, INPUT);   //connect pin A0 to the middle pin of the temperature sensor
pinMode(5, INPUT_PULLUP); //connect pin 5 to the button
// pinMode(A1, INPUT);   //connect pin A1 to the photoresistor as in diagrams for SparkFun 1C
}

void loop()
{
// int degreesCP = degreesC;     //both are 0
// voltage = analogRead(A0) * 0.004882814;   //convert the analog reading, which varies from 0 to 1023, back to a voltage value from 0-5 volts
degreesCurr = 100 * 0.004882814 * analogRead(A0); //100*(5/1023)*ananlogRead(A0)
// degreesC = (voltage - 0.5) * 100.0;       //convert the voltage to a temperature in degrees Celsius
// lcd.clear();
//clear the LCD
tempArray[0] = degreesCurr;
tempArray[2] = tempArray[1];     //Old <--- Prev
tempArray[1] = tempArray[0];   //Prev <--- Curr
//degreesPrev = degreesCurr;
// degreesOld = degreesPrev;

lcd.setCursor(0, 0);                      //set the cursor to the top left position //now
lcd.print(tempArray[0]);                      //print the degrees Celsius

lcd.setCursor(6, 0);
lcd.print(tempArray[1]);

lcd.setCursor(11, 0);
lcd.print(tempArray[2]);

delay(750);
/*
degreesC = degreesCP;
delay(750);

lcd.setCursor(6, 0);                      //set the cursor to the top left position //previous
lcd.print(degreesCP);                      //print the degrees Celsius
delay(750);
lcd.setCursor(12, 0);                      //set the cursor to the top left position //oldest
lcd.print(degreesC);                      //print the degrees Celsius

delay(750);                              //delay for .75 second between each reading (this makes the display less noisy)
*/
}
``````

By doing this

``````  tempArray[0] = degreesCurr;
tempArray[2] = tempArray[1];     //Old <--- Prev
tempArray[1] = tempArray[0];   //Prev <--- Curr
``````

Both tempArray[0] and tempArray[1] will have the same value (current temperature). You need to change the order

``````  tempArray[2] = tempArray[1];     //Old <--- Prev
tempArray[1] = tempArray[0];   //Prev <--- Curr
tempArray[0] = degreesCurr;
``````

lesept:
You need to change the order

``````  tempArray[2] = tempArray[1];     //Old <--- Prev
``````

tempArray[1] = tempArray[0];  //Prev <— Curr
tempArray[0] = degreesCurr;

OK!