time(NULL) always returning 0

simply everytime I try to use time(NULL) it returns 0 why is that?

Can you please give us some clues as to what you are doing, perhaps by posting a sketch that illustrates the problem


#include <time.h>
void setup() {
lcd.begin(16, 2);
lcd.setCursor(1, 1);
srand(time(NULL));
for(int i=0;i<100;i++)
list[i]=rand()%100; 
lcd.print(list[1]);}


I actually meant a sketch that has a chance of compiling

#include <LiquidCrystal.h>

#include <time.h>
int x2 = 7; int x; int y1; int y2; int y3; int y4; int y5; int y6; float time1; int P;
int list[100];
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2);
lcd.setCursor(1, 1);
pinMode(7, INPUT_PULLUP);
lcd.print("Laoding. . .");
delay(1000);
lcd.clear();
srand(time(NULL));
for(int i=0;i<100;i++)
list[i]=rand()%100; }

void loop() {
lcd.print(list[1]);

delay(1000);

lcd.clear();

if (x != x2){
if (x == 1){
lcd.print("GRUEN");}
if (x == 2){
lcd.print("SCHWARZ");}
if (x == 3){
lcd.print("BLAU");}
if (x == 4){
lcd.print("ROT");}
if (x == 5){
lcd.print("GELB");}
if (x == 6){
lcd.print("WEISS");}
x2 = x;
delay(1000);
lcd.clear();

}}

What exactly do you expect the time() function to do ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.