LCD SCREEN

Hello!!

I am having some problems with programming LCD screen and if statements, everything should work a part of anything related with LCD. Can i ask you an advice on this?

  • after touching the touch sensor: lcd.write(pause)
  • after touching the touch sensor when led is up: lcd.write(snooze)
  • if(cronometro== 5 : lcd(move)
  • if(cronometro== 20) : lcd.write(get up!)
  • if((cel>30) && (cel<33)){digitalWrite(bluePin,HIGH): lcd.write(relax)
    -if((cel>=33) && (cel<37)) : lcd(anxious)

How can i write those? and how can i make the disappear?

Thank you very much

thank you:

int val;
float temp;
int tempPin = 0;
bool on = false; // variabile on/off per il sensore che rileva il touch

#define touchpin 4

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 2, en = 3, d4 = 7, d5 = 8, d6 = 9, d7 = 10;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const int trigPin = 6; //SENSOR HS04
const int echoPin = 5;//SENSOR HS04
// def variables HS04 :

long duration;
int distance;
int cronometro = 0;// (cronometer)
int spengooggetto = 1;

int redPin = 11; // 10
int greenPin = 12; // 11
int bluePin = 13; // 12
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE
void setup()
{

lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
//lcd.print("ciao!!");
lcd.write("HELLO WORLD!");

pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

pinMode(touchpin, INPUT); //setta touch sensor come input

pinMode(trigPin, OUTPUT); // Output DISTANCE
pinMode(echoPin, INPUT); // Input
Serial.begin(9600); // set baud rate

}
void loop()
{

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:
//lcd.print("Sec. aan: ");
//lcd.print(millis()/1000);
// Turn off the display:
lcd.noDisplay();
delay(500);
// Turn on the display:
lcd.display();
delay(500);

// Clears the trigPin - HS04:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// trigPin HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin,
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);

if(distance<=10){
cronometro++;
}

if (distance>10){ //
cronometro=0;
}

if(cronometro== 5){
analogWrite(greenPin, 10spengooggetto);
analogWrite(redPin, 10
spengooggetto); //*spengooggetto sale il conteggio dello snooze

// lcd.write("move!"); DOESNT WORK
delay(1000);
}

if(cronometro== 20){ // se mi rileva 40 sec --> sto ignorando il led giallo
analogWrite(bluePin, 255);
analogWrite(redPin, 255);
analogWrite(greenPin,0); // spengo il verde che prima era accesso

lcd.write("alzati!"); DOESNT WORK
delay(1000);

}

val = analogRead(tempPin);
float mv = (val/1024.0)*5000;
float cel = mv/10;

Serial.print("TEMPERATURE = ");
//Serial.print(temp);
Serial.print(cel);
Serial.print("*C");
Serial.print("cronometro = ");
//Serial.print(temp);
Serial.print(cronometro);
Serial.println();

//if(cel<=30){digitalWrite(bluePin,HIGH);} -

if((cel>30) && (cel<33)){digitalWrite(bluePin,HIGH);
digitalWrite(greenPin,LOW);}
if((cel>=33) && (cel<37)){digitalWrite(redPin,HIGH);
digitalWrite(greenPin,LOW);}

if (digitalRead(touchpin)){
digitalWrite(bluePin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(redPin, LOW);
on = true;
spengooggetto++; // così conta il numero di volte che lo spengo

delay(2000); //
}

// questo significa che se è già stato toccato- e lo sto toccando nuovamente allora si accende!-
if ((on == true) && (digitalRead(touchpin))){
on = false;
digitalWrite(greenPin, HIGH);

}

delay(2000);

}

void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

Please read the sticky post at the beginning of this forum about how to post your code using code tags. It makes it much easier.

It appears the reason those lines you marked as not working are actually working, you are just printing off the edge of the display. When you print something to the display, the current cursor position moves so the next print statement continues where the previous one left off. It looks like you are printing "distance" and a value and then more stuff which is more than 16 characters.

Either set the cursor where you want it to print or clear() the display which removes all the chars as well as sets the cursor to (0,0)