Weird LCD display

Hi

I have written down the program as below in order to blink led on 30 s and led off 30s.But after some time I see that LCD display shows a negative value.Please advise.

This sketch prints counter value to the LCD and switching on and off for the relay.

The circuit:

  • LCD RS pin to digital pin 8
  • LCD Enable pin to digital pin 9
  • LCD D4 pin to digital pin 4
  • LCD D5 pin to digital pin 5
  • LCD D6 pin to digital pin 6
  • LCD D7 pin to digital pin 7
  • Relay A1 pin to digital pin 15

*/

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

// initialize the library with the numbers of the interface pins

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

void setup() {
lcd.begin(16, 2);
pinMode(15, OUTPUT);
// set cursor position to start of first line on the LCD

}

void loop() {
lcd.clear();
lcd.setCursor(0,0);
//text to print
lcd.print(" COUNTER");
delay(3000);
int a=0;
lcd.setCursor(0,1);
lcd.print(" “);
lcd.print(a);
while(a<=999999)
{
a=a+1;
delay(30000);
digitalWrite(15, HIGH);
lcd.setCursor(0,1);
lcd.print(” “);
lcd.print(a);
a=a+1;
delay(30000);
digitalWrite(15, LOW);
lcd.setCursor(0,1);
lcd.print(” ");
lcd.print(a);
}
}

Variable 'a' is a 16-bit signed integer. What's the largest positive value a signed 16-bit integer can store?

And after you get your problem figured out with Blackfin's hint above, you could improve upon your code by looking in to Blink Without Delay.

Your code, as written, takes almost 278 days to go through loop() just one time. Whereas, if coded correctly, the Arduino can go through the loop() many thousands of times per second.