Go Down

Topic: Can anyone please help with timing code (Read 149 times) previous topic - next topic

bryan8040

Hi ive been trying to do a little project for a while now, but just can not seem to achieve what i want.
after many hours/days  on internet, its just getting to me now and want it done so can get on with my life...

so here goes, at the moment im using the UNO board with a ds3231 rtc attached. I have manged to get the timing linked beetween the two so when i unplug then plug back in the time is still correct.
What i want to do is have my led strip fading in and out from the hours of 18.00 to 06.00 and the hours in between that i am after a consent mid light but with flash (like heart beat).
I have two different codes for the light effects probably not the way to do them but the effects are sort of what im after.

This is the heart beat code

Code: [Select]
void setup() {
  // put your setup code here, to run once:
pinMode (9, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
analogWrite(9, 225/8);
delay(3000);
digitalWrite(9, HIGH);
delay(80);
analogWrite(9, 225/20);
delay(125);
digitalWrite(9, HIGH);
delay(80);

}


and for the fading code im using the one from the IDE examples.

the main code i have for the timing rtc

Code: [Select]

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

int ledPin = 9;        //LED connected to digital pin 9

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

  if (! rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
  }

  //set the RTC to PC time:
  //uncomment the next line, upload, then comment the next line, then upload again.
  //rtc.adjust(DateTime(__DATE__,__TIME__));
  //Any pin. I have used Pin 9


  pinMode(9, OUTPUT);

}

void loop()
{
  DateTime now = rtc.now();
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print(")");
  Serial.println();

  Serial.println();
  delay(1000);
 
    //The time is set as 24 hours
    //Pin 9 get high at 6pm and low at 6am
 if (now.hour() == 17 & now.minute() == 54 & now.second() == 0)

 {
  // put code here
    // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
 
 }
 
 }
else if (now


This is as far as i have got, tried to modify/change to see what happens but just made things worse, starting to think the coding stuff is not for me.

This code does compile ok but i dont get anything from the lights. would be a bonus if could modify things in the code like speed, time, brightness, fade amount without messing anything else up in the process.

if anyone could please help me out i would be most grateful I think i would even consider paying a fee to get this done as my eyes just cant spend anymore time looking at a screen   

avh-on1

You seem to be missing the end of your code - it ends with
Code: [Select]
else if (now

Go Up