help with continuing temperature display


i have barometric sensor display temperature on lcd display , when press button1 display temperature in real-time (change on display temp changes). of right displays doesn't update, have keep pressing button1 in order update temp. know need have loop constatnly updating values, maybe while loop not sure use terminating condition.
any hints or suggestions appreciated.

here's full code
code: [select]
#include <scp1000.h>

#include <liquidcrystal.h>

#define slaveselect 10

int buttonpin1= 18;
int buttonpin2 = 19;
liquidcrystal lcd(9, 8, 5, 4, 3, 2);
scp1000 scp(slaveselect);

int prevbuttonstate1;
int prevbuttonstate2;

long starttime;
long elapsedtime;
int flag;
int flag2;
int buttonstate1;
int buttonstate2;

void setup()
{
 pinmode(buttonpin1, input);
 pinmode(buttonpin2, input);
 digitalwrite(buttonpin1, low);  // pulldown resistors
 digitalwrite(buttonpin2,low);
 scp.init();
 lcd.begin(20, 4);
 lcd.setcursor(2,1);
 lcd.print("trail tracker co.");}




void loop(){
 buttonstate1 = digitalread(buttonpin1);  //records current state of button1 , button2
 buttonstate2 = digitalread(buttonpin2);
 scp.readsensor();  //reads sensor
 //button1 -> elapsed time/velocity button2 -> start/stop
 if (buttonstate1 == low && prevbuttonstate1== high && flag == false){  // detects transition high low transition
   lcd.clear();
   starttime = (millis());
   
   lcd.setcursor(0,0);
   lcd.print("time elapsed:");
   lcd.setcursor(0,1);
   lcd.print("distance: ");
   lcd.setcursor(0,2);
   lcd.print("real time:");
   lcd.setcursor(0,3);
   lcd.print("temp: ");
   lcd.print(scp.tempc);  // prints out temperature in celcius
   flag = true;
   prevbuttonstate1 = buttonstate1;// updates current , previous state
 }
 else if(buttonstate1 == low && prevbuttonstate1== high && flag == true){
   lcd.clear();
   lcd.print("velocity:");
   double vel = velocity(50,389.5);
   lcd.print(vel);
   lcd.print("mi/hr");
   lcd.setcursor(0,1);
   lcd.print("altitude:");
   lcd.setcursor(0,2);
   lcd.print("coordinates:");
   flag = false;
   prevbuttonstate1 = buttonstate1;
 }
 else if(buttonstate2 == low && prevbuttonstate2== high && flag2 == false) { // starts logging
   lcd.clear();
   lcd.setcursor(6,1);
   lcd.print("start");
   flag2 = true;
   prevbuttonstate2 = buttonstate2;
 }
 else if(buttonstate2 == low && prevbuttonstate2 == high && flag2 == true ){ //stops logging
   flag2 = false;
   lcd.clear();
   lcd.setcursor(2,1);
   lcd.print("stop");
   prevbuttonstate2 = buttonstate2;
 }

 else{
   prevbuttonstate1 = buttonstate1;
   prevbuttonstate2 = buttonstate2;
 }

}
double velocity(double acc, double time){

 return acc * time/3600;


}




you have loop already. it's loop function.

what need decide triggers program stop displaying real-time temperature.

there things in code make easier you.
code: [select]
if (buttonstate1 == low && prevbuttonstate1== high && flag == false)
 else if(buttonstate2 == low && prevbuttonstate2== high && flag2 == false)

without studying code, meanings of buttonstate1 , prevbuttonstate1 pretty easy guess, , check make sure guess correct. but, flag? what's that?

the buttonstate1 , buttonstate2 variables follow pattern. prevbuttonstate1 , prevbuttonstate2 variables follow same pattern. flag , flag2 variables not follow same pattern.

code: [select]
 else{
   prevbuttonstate1 = buttonstate1;
   prevbuttonstate2 = buttonstate2;
 }

the previous button state variables should set on every pass through loop, not sometimes. it's hard follow (with names flag , flag2 being used) under circumstances, if ever, these variables reset.

it easier understand happening, or supposed happen if code this:
code: [select]
 if (buttonstate1 == low && prevbuttonstate1== high && flag == false){  // detects transition high low transition
   lcd.clear();
   starttime = (millis());
   
   lcd.setcursor(0,0);
   lcd.print("time elapsed:");
   lcd.setcursor(0,1);
   lcd.print("distance: ");
   lcd.setcursor(0,2);
   lcd.print("real time:");
   lcd.setcursor(0,3);
   lcd.print("temp: ");
   lcd.print(scp.tempc);  // prints out temperature in celcius
   flag = true;
   prevbuttonstate1 = buttonstate1;// updates current , previous state
 }

looked this:
code: [select]
 if (buttonstate1 == low && prevbuttonstate1== high && flag == false)
 {
   showtimedistandtemp();
   flag = true;
   prevbuttonstate1 = buttonstate1;// updates current , previous state
 }


if make of these changes, should pretty apparent why button needs pressed in order trigger update of display.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help with continuing temperature display


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums