so we have this lab/hw that we should use 2 lm35 as temperature sensors and an lcd to display their output and show their difference. my problem is that can i put 2 temperature by scrolling it without changing the temperature every time it scrolls here is my code for the project
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int screenWidth = 16;
int screenHeight = 2;
String line1 = "Temp. Difference"; // Static line
String line2 = " T1:"; // Scrolling line
String line3 = " T2:";
String line4 = " TD:";
float temp;
float tempf;
float tempx;
int sensor = 0;
int sensor2 = 1;
int stringStart, stringStop = 0;
int scrollCursor = screenWidth;
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
temp = analogRead(sensor);
temp = temp * 0.48828125;
tempf = analogRead(sensor2);
tempf = temp * 0.48828125;
tempx = temp - tempf;
}
void loop()
{
temp = analogRead(sensor);
temp = temp * 0.48828125;
tempf = analogRead(sensor2);
tempf = temp * 0.48828125;
tempx = temp - tempf;
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(scrollCursor, 1);
lcd.print(line2.substring(stringStart,stringStop));
lcd.print(temp);
lcd.print(line3.substring(stringStart,stringStop));
lcd.print(tempf);
lcd.print(line4.substring(stringStart,stringStop));
lcd.print(tempx);
delay(300);
lcd.clear();
if(stringStart == 0 && scrollCursor > 0){
scrollCursor--;
stringStop++;
} else if (stringStart == stringStop){
stringStart = stringStop = 0;
scrollCursor = screenWidth;
} else if (stringStop == line2.length() && scrollCursor == 0) {
stringStart++;
} else {
stringStart++;
stringStop++;
}
}
Do you have a question?
Please remember to use code tags when posting code.
AWOL:
Do you have a question?
Please remember to use code tags when posting code.
my problem in this activity of ours is how can i keep the temperatures in my scrolling line which is the second row, since in that code the temperature changes every time it scrolls each column.
ill remember it next time sorry, first time asking a question in the forum
noobkidph:
ill remember it next time sorry, first time asking a question in the forum
No need to.
Go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight the section of code (or output if you need to post that) from the IDE and click the icon.
In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can be quite garbled and is always more difficult to read.
It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.
Also tidy up your blank space. Do use blank lines, but only between functional blocks.
String is possibly the worst data type for a static string.
Also it's not clear to me what you're trying to do based on your description, nor how what the program is doing differs from what you want it to do.