BIG Project

I had initially purchased an Arduino with the intent to use it to control 2 or more pwm drivers for LEDs, variable fade in and out timing for sunrise and sunset application. I want to be able to utilize a menu to change the fade in/out timing, and peak output to the drivers. I have an LCD screen, three buttons and some LEDs, and I'm learning as much as I can as fast as I can. Unfortunately I am on a time schedule and after spending a week going through the forums, reading other's posts, and going all over the internet I have not been able to find any code that I can apply to my situation. The only one I have found is for the Arduino 0015... kinda old. (Just out of curiosity, can I upload the 0015 library onto my new Uno?

Feel free to reply in any form you wish; criticism, assistance, an example of a code you may have used... etc.

THANKS A LOT! XD

#include "Wire.h"
#define DS1307_ADDRESS 0x68  // This is the I2C address

const int Blue1Pin = 3;
const int Blue2Pin = 5;
const int White3Pin = 6;
const int White4Pin = 9;
const unsigned long HOUR = 60 * 60;
const unsigned long MINUTE = 60;
const int TARGET_BRIGHTNESS = (255 * 3) / 4;  // Target brightness is 3/4 of full

void setup()
{
  Wire.begin();
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void loop()
{
  /////  Get time from RTC into RTCHour, RTCMinute, RTCSecond

  // Set the register pointer to 0 (Second)
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write((byte)0);
  Wire.endTransmission();

  //  Read Second, Minute, and Hour
  Wire.requestFrom(DS1307_ADDRESS, 3);

  int RTCSecond = bcdToDec(Wire.read());
  int RTCMinute = bcdToDec(Wire.read());
  int RTCHour = bcdToDec(Wire.read() & 0b111111); //24 hour time


  unsigned long time = RTCHour * HOUR + RTCMinute * MINUTE + RTCSecond;  // Time in seconds

  analogWrite(Blue1Pin,   brightness(time, 7*HOUR,                 17*HOUR));
  analogWrite(Blue2Pin,   brightness(time, 7*HOUR+30*MINUTE, 16*HOUR+30*MINUTE));
  analogWrite(White3Pin, brightness(time, 8*HOUR,                 15*HOUR));
  analogWrite(White4Pin, brightness(time, 9*HOUR,                 14*HOUR));

  delay(1000);
}

byte brightness(unsigned long time, unsigned long fadeUpStart, unsigned long fadeDownStart)
{
  //  Mid day, light is at maximum brightness
  if (time >= fadeUpStart + 2*HOUR  && time <= fadeDownStart)
    return TARGET_BRIGHTNESS;

  // Dawn:  fade up the light
  if (time >= fadeUpStart && time <= fadeUpStart + 2*HOUR)  // Fading up
  {
    unsigned long seconds = time - fadeUpStart;  // Number of seconds into the fade time 
    return TARGET_BRIGHTNESS * seconds / (HOUR*2);  // Fade up based on portion of interval completed.
  }

  // Evening: Fade down the light
  if (time >= fadeDownStart && time <= fadeDownStart + 2*HOUR)  // Fading down
  {
    unsigned long seconds = (fadeDownStart + (HOUR*2)) - time;  // Number of seconds remaining in the fade time 
    return TARGET_BRIGHTNESS * seconds / (HOUR*2);  // Fade down based on portion of interval left.
  }

  // The remaining times are night and the lights is off
  return 0;  // Shouldn't get here
}

This is a great starting point, and I was looking for stuff just like this online. One problem I'm banging my head against right now is how to integrate a menu into this fade in and out. The menu needs to be able to alter the time of day, change the intensity of the peak day light and change the times at which the lights turn on and reach their peak. Moonlight isn't necessary. I have figured out how to program the relays. It's the menu I need help on now. Thanks johnwasser! That looks super neat and simple compared to the garbage I was writing!

I would like for the menu to be run by 3 buttons. A menu button to jump from one menu to the next e.g. (Change Time, Change Channel 1 Intensity, Change Channel Two Intensity, Change ramp up/down time for the two channels... etc) Then two buttons for increasing, decreasing values.

Anyone used a menu like this before, or know someone who has any help would be great! Thanks!

-Brandon

Do you have a picture or a sketch of the circuit diagram/adruino circuit scheme? I'm trying to do this for a middle school project but can't find a visual aid.

Thanks!

Google
Arduino encoder menu

Educate... educa8...... the guy with the swiss accent.

He has both and encoder menu and a button menu

If you’re up against time, you may get more complete results in Gigs & Collaborations - at a cost.

These other sections of the forum tend to push you in the right direction, but not hand over complete code.

This thread was started over 5 years ago. Th OP is long gone and is no longer a member as can be seen from his guest status.

Oh well.
It never hurts to remind whoever lands here they can “do or buy”!