problem changing delay to millis

Hi i just started learning arduino this fall. I am currently trying to work/learn with time alarms. I want to have a pump running once a day at a set time for x time. So far i wrote a sketch that work with a led function but its with delay(). When the timed fuction run everything “froze”. Like in this video - YouTube. and then it continue where is should be. I want to change the code so the other function wont be delay or affected. I tried millis but couldn’t get it to work i am missing something or doing it wrong. My coding knowledge is what i have learn since i started this fall really basic newbie knowledge ::slight_smile:

Here is the sketch that work with delay() sorry there is not a lot of note :frowning: i have to start doing more of them.

So how should i modified my sketch to get it to work without delay. And does the sketch make sense… :stuck_out_tongue:

#include <LiquidCrystal_I2C.h>
#include <TimeAlarms.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int led1=12;
int led2=11;
int led3=10;

void setup()
{
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);

Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(“hello”);
delay(1000);
lcd.clear();
setSyncProvider(RTC.get);
Alarm.alarmRepeat(15,38,30, ledAlarm);

}

void loop()

{
digitalClockDisplay();
Alarm.delay(1000);

}

void ledAlarm(){
Serial.println(“Led Cycle Starting”);
lcd.setCursor(0,0);
lcd.print(“LED ON”);

if(ledAlarm)
{
ledCycle();
}
lcd.clear();

}

void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();

lcd.setCursor(8,0);
lcd.print(hour());
lcdprintDigits(minute());
lcdprintDigits(second());

}

void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}

void lcdprintDigits(int digits)
{
lcd.print(":");
if(digits < 10)
lcd.print(‘0’);
lcd.print(digits);
}

void ledCycle()
{

digitalWrite(led1,HIGH);
Alarm.delay(1000);
digitalWrite(led1,LOW);
Alarm.delay(1000);
digitalWrite(led2,HIGH);
Alarm.delay(1000);
digitalWrite(led2,LOW);
Alarm.delay(1000);
digitalWrite(led3,HIGH);
Alarm.delay(1000);
digitalWrite(led3,LOW);
Alarm.delay(1000);
}

  if(ledAlarm)This looks very odd. You seem to be testing whether the ledAlarm function exists. Is that what you meant to do ?

i think it should be

if(ledAlarm = true) { ledCycle(); }

but when i put it like this it dosnt work and the way its write it does.... sorry my programing knowledge are not very good i just started

No, there you're assigning the value true to the name of the function you happen to be inside. That won't work.

What i want it to dois if ledAlarm goes on (like at 15:38 or the time it set to go)

then run ledCycle function.

The program only calls the ledAlarm() function when the alarm is triggered so why do you need to check anything ? Just run the ledCycle() function.

Just understand what you mean not useful for what i am doing and take space in code for no reason took it of so here is the update :wink:

#include <LiquidCrystal_I2C.h>
#include <TimeAlarms.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int led1=12;
int led2=11;
int led3=10;

void setup()
{
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);

Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(“hello”);
delay(1000);
lcd.clear();
setSyncProvider(RTC.get);
Alarm.alarmRepeat(17,20,30, ledAlarm);

}

void loop()

{
digitalClockDisplay();
Alarm.delay(1000);

}

void ledAlarm(){
Serial.println(“Led Cycle Starting”);
lcd.setCursor(0,0);
lcd.print(“LED ON”);
ledCycle();
lcd.clear();

}

void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();

lcd.setCursor(8,0);
lcd.print(hour());
lcdprintDigits(minute());
lcdprintDigits(second());

}

void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}

void lcdprintDigits(int digits)
{
lcd.print(":");
if(digits < 10)
lcd.print(‘0’);
lcd.print(digits);
}

void ledCycle()
{

digitalWrite(led1,HIGH);
Alarm.delay(1000);
digitalWrite(led1,LOW);
Alarm.delay(1000);
digitalWrite(led2,HIGH);
Alarm.delay(1000);
digitalWrite(led2,LOW);
Alarm.delay(1000);
digitalWrite(led3,HIGH);
Alarm.delay(1000);
digitalWrite(led3,LOW);
Alarm.delay(1000);
}

Have you looked at the demo several things at a time which illustrates how to manage timing using millis().

...R

No dint find that post while doing research will look at it for sure. thanks