Logging LDR sensor data?

OK so I wrote this program :

/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

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

int ldr = 1;
int light;


  //LiquidCrystal lcd(RS,EN,D0,D1,D2,D3,D4,D5,D6,D7);
  LiquidCrystal lcd(7,8,2,3,4,5,9,10,11,12);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 4);
  
  // Print a message to the LCD.
  lcd.print("Hr Mn Sc Value");
  setTime(10,10,0,6,3,2011);
  
  Serial.begin(9600);
  
}

void loop() {
  light = analogRead(ldr);
  Serial.println(light);
  lcd.setCursor(0,1);
  lcd.print("                ");
  
  if (light > 750) {
    
    lcd.setCursor(0,1);
    lcd.print(hour());
    lcd.setCursor(3,1);
    lcd.print(minute());
    lcd.setCursor(6,1);
    lcd.print(second());
    lcd.setCursor(10,1);
    lcd.print(light);
    delay(1000);
  }
  

  }

I want to log the time and value of the LDR on the LCD but at night. I want it to give me 3 values + the time they occurred. I want to evenly space out the measuring periods so there’s only 3 of them. the 750 that I wrote in the code will NOT be implemented in the final code. Basically lets say the arduino says , oh its time to take a measurement, then it takes the measurement and logs the time it was taken and puts it on the LCD. Then after another allocated time it takes another measurement and does the same thing but on a new line. How would I get it to do this on a new line and with a delay?

Ok this is what I came up with:

/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

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

int ldr = 1;
int light;


  //LiquidCrystal lcd(RS,EN,D0,D1,D2,D3,D4,D5,D6,D7);
  LiquidCrystal lcd(7,8,2,3,4,5,9,10,11,12);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 4);
  
  // Print a message to the LCD.
  //setTime(hr,min,sec,day,month,yr);
  lcd.print("Hr Mn Sc Value");
  setTime(5,55,45,6,3,2011);
  
  Serial.begin(9600);
    lcd.setCursor(0,1);
  lcd.print("                ");
}

void loop() {

  light = analogRead(ldr);
  Serial.println(light);
  
  
delay(120000);
    
    lcd.setCursor(0,1);
    lcd.print(hour());
    lcd.setCursor(3,1);
    lcd.print(minute());
    lcd.setCursor(6,1);
    lcd.print(second());
    lcd.setCursor(10,1);
    lcd.print(light);
    delay(120000);
    light = analogRead(ldr);
       lcd.setCursor(-4,2);
    lcd.print(hour());
    lcd.setCursor(-1,2);
    lcd.print(minute());
    lcd.setCursor(2,2);
    lcd.print(second());
    lcd.setCursor(6,2);
    lcd.print(light);
    delay(120000);
    light = analogRead(ldr);
       lcd.setCursor(-4,3);
    lcd.print(hour());
    lcd.setCursor(-1,3);
    lcd.print(minute());
    lcd.setCursor(2,3);
    lcd.print(second());
    lcd.setCursor(6,3);
    lcd.print(light);
  

  }

So now after 2 minutes it logs the sensor data at that 2 minute mark and the time. Then it waits another 2 minutes and goes down to the next line and does the same thing. Is there a quicker or simpler way of doing this?

Is there a quicker or simpler way of doing this?

Yes.

1) Don't use delay() use the blink without delay technique of a state machine. 2) Write the bit that prints out to the LCD as a function and call it three times. 3) Use variables in that function in place of fixed numbers, that way the function can write to different parts of the LCD.

Grumpy_Mike:

Is there a quicker or simpler way of doing this?

Yes.

1) Don't use delay() use the blink without delay technique of a state machine. 2) Write the bit that prints out to the LCD as a function and call it three times. 3) Use variables in that function in place of fixed numbers, that way the function can write to different parts of the LCD.

how would I do number 2 and 3? oh and 1

http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

Mike is trying to tell you that there is more to the Arduino than just using libraries written by others, but he is not going to do the work for you. A side effect of doing this is that you can learn some C programming.

"1) Don't use delay() use the blink without delay technique of a state machine." The standard delay technique ties up the processor while it is delaying. In your example the processor is doing real work for only a few microseconds out of every two minute period. The 'blink without delay technique' uses an interrupt which lets the processor be idle, or do something else, during all that previously wasted time. You will have to look through the information on 'blink without delay' (I haven't yet) and see how to adapt it for your purposes.

"2) Write the bit that prints out to the LCD as a function and call it three times." Your program does the same thing over and over again. It may write to a different location each time, and it may write different information each time, but the process is nevertheless the same each time. This is the tip off that subroutine or function is appropriate.

"3) Use variables in that function in place of fixed numbers, that way the function can write to different parts of the LCD." This is a way to take care of the things that are different each time in (2).

I suggest that you start by revising your current program. Remove all of the extraneous comments that are specific to the 'Hello world' example and replace them with comments that explain what you are now doing with the code. You should also add comments to such unusual techniques as this one lcd.setCursor(-4,3); so that if and when they repair the library you will know why your program no longer works.

Don

floresta: Mike is trying to tell you that there is more to the Arduino than just using libraries written by others, but he is not going to do the work for you. A side effect of doing this is that you can learn some C programming.

"1) Don't use delay() use the blink without delay technique of a state machine." The standard delay technique ties up the processor while it is delaying. In your example the processor is doing real work for only a few microseconds out of every two minute period. The 'blink without delay technique' uses an interrupt which lets the processor be idle, or do something else, during all that previously wasted time. You will have to look through the information on 'blink without delay' (I haven't yet) and see how to adapt it for your purposes.

"2) Write the bit that prints out to the LCD as a function and call it three times." Your program does the same thing over and over again. It may write to a different location each time, and it may write different information each time, but the process is nevertheless the same each time. This is the tip off that subroutine or function is appropriate.

"3) Use variables in that function in place of fixed numbers, that way the function can write to different parts of the LCD." This is a way to take care of the things that are different each time in (2).

I suggest that you start by revising your current program. Remove all of the extraneous comments that are specific to the 'Hello world' example and replace them with comments that explain what you are now doing with the code. You should also add comments to such unusual techniques as this one lcd.setCursor(-4,3); so that if and when they repair the library you will know why your program no longer works.

Don

Okay thanks don, ill look up the functions and stuff because I think that's the most useful. What is it called anyway just a function? I want to search it on google.

The code in Reply #3 in your "LCD graph?" thread (http://arduino.cc/forum/index.php/topic,55090.0.html) is a 'function'.

Don