using "while" to display info on LCD


ok stumper need input for. building ac control unit car, , want display "temp" setting on lcd screen, have 16x2. have 2 buttons, temp , temp down, multiplexed output on pins 22-30, (i have mega), , go 3 different cascaded multiplexers, can give me total of 24 "temp settings" using 18. there 18 leds hooked on parallell set of multiplexers, can watch happening. when system boots, led 1 on, when temp hit, leds light increasing until 18 lit, , opposite temp down. part works perfect.

now question. want display like:

    temp
c********x***h

on screen, , have x move , forth. display should last second, go right doing before, static display of outside , inside temperatures. when add section in, adds delay loop, , buttons stop working. need responsive possible. uploading code , try take short video can see trying accomplish.

heres code, vid follow:
code: [select]
byte temp0 = 0; //analog 8 sensor input
byte temp1 = 0; //analog 9 sensor input
int temp1f = 0;
int temp0f = 0;
int fan = 0;
int loc = 0;
#include <liquidcrystal.h>

liquidcrystal lcd(8, 9, 4, 5, 6, 7);


byte count;

void setup()
{
 lcd.begin (16,2);              //displays opening logo once
 lcd.setcursor (0,0);
 lcd.print (" welcome my");
 lcd.setcursor (0,1);
 lcd.print ("     camaro");
 delay (7000);
 lcd.clear();
 delay(100);                   //clears 7 seconds later

 //temp sensor inputs
 
 //temp , down control
 pinmode (32, input);         //external debounced switch pins 52 temp up
 pinmode (33, input);        // 50 temp down
 pinmode (22, output);       //pins odd 37-53 outputs multiplexers
 pinmode (23, output);
 pinmode (24, output);
 pinmode (25, output);
 pinmode (26, output);
 pinmode (27, output);
 pinmode (28, output);
 pinmode (29, output);
 pinmode (30, output);       //end output pins temp chips
 //fan speed/location control
 pinmode (15, input);     //reads adc value fan speed knob
 pinmode (35, output);    //outputs s0 on fan driver chip
 pinmode (36, output);    //outputs s1 on fan driver chip
 pinmode (37, output);    //outputs s2 on fan driver chip
 pinmode (38, output);    //outputs s0 on location chip
 pinmode (39, output);    //outputs s1 on location chip
 pinmode (40, output);    //outputs s2 on location chip
 pinmode (14, input);     //reads adc value location knob
 serial.begin (9600);     //start serial hell of it

}

void loop()  
//=========================================================================================
//=========================================================================================
//=========================================================================================
//fan speed block start
{
 int fan = analogread (15);

//p[in 34 input knob
// trigger notes : 35 s0, 36 s1, , 37 s2

if (fan < 10 )                                  //pot detent 1
{digitalwrite (35, low);
digitalwrite (36, low);
digitalwrite (37, low);}
else
{}

if (fan > 100 && fan < 250 )              //pot detent 2
{digitalwrite (35, high);
digitalwrite (36, low);
digitalwrite (37, low);}
else
{}

if (fan > 251 && fan < 350 )              //pot detent 3
{digitalwrite (35, low);
digitalwrite (36, high);
digitalwrite (37, low);}
else
{}

if (fan > 351 && fan < 450 )              //pot detent 4
{digitalwrite (35, high);
digitalwrite (36, high);
digitalwrite (37, low);}
else
{}

if (fan > 451 && fan < 625 )              //pot detent 5
{digitalwrite (35, low);
digitalwrite (36, low);
digitalwrite (37, high);}
else
{}

if (fan > 626 && fan < 775 )              //pot detent 6
{digitalwrite (35, high);
digitalwrite (36, low);
digitalwrite (37, high);}
else
{}
if (fan > 776 && fan < 950 )              //pot detent 7
{digitalwrite (35, low);
digitalwrite (36, high);
digitalwrite (37, high);}
else
{}
if (fan > 951 )              //pot detent 8
{digitalwrite (35, high);
digitalwrite (36, high);
digitalwrite (37, high);}
else
{}

serial.println (analogread (15));

//fan speed block close
//=========================================================================================
//=========================================================================================
//temp sensor block start
{
 int temp0 = analogread(8);  
  int temp0f = temp0 * 20 / 10; // converting reading voltage, 3.3v arduino use 3.3
   lcd.setcursor(0,0);
    lcd.print("outside   "); lcd.print (temp0f); lcd.print("f ");

delay (0);

int temp1 = analogread(9);  
  int temp1f = temp1 * 20 / 20; // converting reading voltage, 3.3v arduino use 3.3
   lcd.setcursor(0,1);
    lcd.print("inside    "); lcd.print (temp1f); lcd.print("f ");

delay (500);}
//temp sensor input block close
//=========================================================================================
//=========================================================================================
//temp control block start
{if (digitalread(33) == high && count < 18)
 {count++;
 delay (10);}
else if (digitalread(32) == high && count > 0)
 {count--;
 delay (10);}
 
//start sending temp button contact closure commands

if (count == 0)
{digitalwrite (22, low);
 digitalwrite (23, low);
 digitalwrite (24, low);
 digitalwrite (25, low);
 digitalwrite (26, low);
 digitalwrite (27, low);
 digitalwrite (28, low);
 digitalwrite (29, low);
 digitalwrite (30, low);}
else
{}

//counts way 0 17, 18 total. omittted space.

if(count == 17)
{ digitalwrite (22, high);
 digitalwrite (23, high);
 digitalwrite (24, high);
 digitalwrite (25, high);
 digitalwrite (26, high);
 digitalwrite (27, high);
 digitalwrite (28, high);
 digitalwrite (29, low);
 digitalwrite (30, high); }
else
{}
//temp control block close
//=========================================================================================
//=========================================================================================
//location control block start
{int loc = analogread (14);

// pin 14 input knob
// trigger notes : 38 s0, 39 s1, , 40 s2

if (loc < 10 )                                  //pot detent 1
{digitalwrite (38, low);
digitalwrite (39, low);
digitalwrite (40, low);}
else
{}

if (loc > 150 && loc < 250 )              //pot detent 2
{digitalwrite (38, high);
digitalwrite (39, low);
digitalwrite (40, low);}
else
{}

if (loc > 251 && loc < 450 )              //pot detent 3
{digitalwrite (38, low);
digitalwrite (39, high);
digitalwrite (40, low);}
else
{}

if (loc > 451 && loc < 650 )              //pot detent 4
{digitalwrite (38, high);
digitalwrite (39, high);
digitalwrite (40, low);}
else
{}

if (loc > 651 && loc < 850 )              //pot detent 5
{digitalwrite (38, low);
digitalwrite (39, low);
digitalwrite (40, high);}
else
{}

if (loc > 851 )              //pot detent 6
{digitalwrite (38, high);
digitalwrite (39, low);
digitalwrite (40, high);}
else
{}}
//location control block close
//=========================================================================================
//=========================================================================================

}
}



just noticed of pin numbers in notes dont line up. cosmetic ill fix them.

first of, use if statements blanc else, allright leave out else (in fact, preferable).
however, optimise code using else
simply remove {} after it.
this make @ first if, , disregard other ifs if 1 true.
this should save controller instructions, other ifs can never true if earlier 1 true.

ie:
code: [select]
if(i == 1)
{
 //do something
}
else {}

if(i == 2)
...

to
code: [select]
if(i == 1)
{
 //do something
}
else
if(i == 2)
...





a bit late here @ moment, i'll take further tomorrow.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > using "while" to display info on LCD


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