(Another) DIY LED Controller - Simple Arduino Style

Near the top is the zip with the library.
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

Don't think it's related. I'm suspecting it might be a memory thing, but I just don't know.


Trying stuff...heh


EDIT: Seems I was right, maybe. I trimmed some code by making sub routines and now the flicker/artifacts are mostly gone. The screen is still a bit 'off' but only the time changes every second. Going to do some more 'weeding' and see if that clears thigns up.

EDIT2: Nope, not fixed. Seems that my "night time" layout is causing some of the issues as it is much better once the light cycle starts...

EDIT the 3rd: And I now have a fan running off one of the PWMs, so I'll take that as it works...hehe.

EDIT 4: Commented out the IR code and now the screen is more or less normal...wish I knew how to code better...
 
Last edited:
I'm a little embarrassed as it's pretty ugly in places. But here it is. The fan was a simple analogWrite(fan, 255); where fan is the pin and 0 and 255 were used for off and on. Actually only pushing 5v to a 12v fan for testing but it works.

pastie link ***ed the first part so here it is in 'php':

PHP:
/*
 * GLCDexample
 *
 * Basic test code for the Arduino KS0108 GLCD library.
 * This code exercises a range of graphic functions supported
 * by the library and is an example of its use.
 * It also gives an indication of performance, showing the
 *  number of frames drawn per second.  
 */

#include <ks0108.h>
#include "Arial14.h"         // proportional font
#include "SystemFont5x7.h"   // system font
//#include "ArduinoIcon.h"     // bitmap
#include "SunRise.h"     // bitmap
#include "SunSet.h"     // bitmap
#include "SunUp.h"     // bitmap
#include "Dawn.h"     // bitmap
#include "Dusk.h"     // bitmap
#include "MoonUp.h"     // bitmap
#include "seahorse.h"     // bitmap
#include "seahorse2.h"     // bitmap
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#include "Wire.h"
#include "RTClib.h"
#include <IRremote.h>

RTC_Millis RTC;
unsigned long startMillis;
unsigned int loops = 0;
unsigned int iter = 0;

//int RECV_PIN = 9;
//IRrecv irrecv(RECV_PIN);
decode_results results;


/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  R E L A Y   P A R T  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  S I M P L E   O N   A N D   O F F   F E A T U R E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



const int ledPin1 =  2;          // pin number for relay 1
const int ledPin2 =  8;          // pin number for relay 2


int ledState1 = LOW;             
int ledState2 = LOW; 
long previousMillis1 = 0;        
long previousMillis2 = 0;
long interval1 = 30000;          // interval at which to blink (milliseconds) for RELAY1
long interval2 = 50000;		 // interval at which to blink (milliseconds) for RELAY2


/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L E D   D I M M I N G   P A R T  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  F A D E S   I N   A N D   O U T  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



int blueramptime = 60 ;    // time for blue LEDs to dim on and off in minutes
int whiteramptime = 120 ;  // time for white LEDs to dim on and off in minutes
int bluemin = 0 ;          // minimmum dimming value of blue LEDs, range of 0-255
int bluemax = 255 ;        // maximum dimming value of blue LEDs, range of 0-255
int whitemin = 0 ;         // minimum dimming value of white LEDs, range of 0-255
int whitemax = 255 ;       // maximum dimming value of white LEDs, range of 0-255
int photoperiod = 240 ;    // amount of time array is on at full power in minutes
int ontime = 10 ;          // time of day (hour, 24h clock) to begin photoperiod fade in
int blue = 3;              // blue LEDs connected to digital pin 3 (pwm)
int white = 7;            // white LEDs connected to digital pin 11 (pwm)
int fan = 10;            // Fan lead connected to digital pin 10 (pwm)

int bluepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };   // this line is needed if you are using meanwell ELN60-48P
int whitepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };   // these are the values in 10% increments

// int pwm_one = 10;       // extra pwm pin for future use
// int pwm_one = 9;        // extra pwm pin for future use

/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  R T C   C L O C K   D S 1 3 0 7  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



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

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

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));   // If you want 12 hour am/pm you need to set
  // bit 6 (also need to change readDateDs1307)
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second = bcdToDec(Wire.receive() & 0x7f);
  *minute = bcdToDec(Wire.receive());
  *hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
  *dayOfWeek = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month = bcdToDec(Wire.receive());
  *year = bcdToDec(Wire.receive());
}



/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  U P N E X T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
char* UpNext[3] ;
void Next()
{
  GLCD.GotoXY(65, 0);
  GLCD.Puts("Next:");
  GLCD.GotoXY(65, 8);
  GLCD.Puts(UpNext[0]);
  GLCD.GotoXY(65, 16);
  GLCD.Puts(UpNext[1]);
  GLCD.GotoXY(65, 24);
  GLCD.Puts(UpNext[2]);
  GLCD.GotoXY(65, 32);
}
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  F A N S   O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void FansOn()
{
    analogWrite(fan, 255);
    GLCD.GotoXY(64, 48);
    GLCD.Puts("Fans:");
    GLCD.GotoXY(64, 56);
    GLCD.Puts("are on");
}
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  F A N S   O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void FansOff()
{
    analogWrite(fan, 0);
    GLCD.GotoXY(64, 48);
    GLCD.Puts("Fans:");
    GLCD.GotoXY(64, 56);
    GLCD.Puts("are off");
}
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  O N E S E C O N D |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



void onesecond() //function that runs once per second while program is running
{
  DateTime now = RTC.now();

/*   Commented out RTC
    GLCD.PrintNumber(now.year());
    GLCD.Puts("/");
    GLCD.PrintNumber(now.month());
    GLCD.Puts("/");
    GLCD.PrintNumber(now.day());
    GLCD.Puts(" ");
    GLCD.PrintNumber(now.hour());
    GLCD.Puts(":");
    GLCD.PrintNumber(now.minute());
    GLCD.Puts(":");
    GLCD.PrintNumber(now.second());
    */
 byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
 getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  GLCD.GotoXY(0, 0);
  //GLCD.PrintNumber(hour);
  //GLCD.PrintNumber(minute);
  //GLCD.PrintNumber(second);
  if((now.hour())>0)
  {
    if((now.hour())<=12)
    {
      GLCD.PrintNumber(now.hour());
    }
    else
    {
      GLCD.PrintNumber((now.hour())-12);
    }
  }
  else
  {
    GLCD.Puts("12");
  }
  GLCD.Puts(":");
  if ((now.minute()) < 10) {
    GLCD.Puts("0");
  }
  GLCD.PrintNumber(now.minute());
  GLCD.Puts(":");
  if ((now.second()) < 10) {
    GLCD.Puts("0");
  }
  GLCD.PrintNumber(now.second());
  if((now.hour())<12)
  {
    GLCD.Puts("am");
  }
  else
  {
    GLCD.Puts("pm");
  }
  GLCD.Puts(" ");
  //GLCD.GotoXY(0, 24 );
  //GLCD.PrintNumber (daybyminute);
  delay(1000);
}




/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  R E L A Y 1 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void relay1()  //FUNCTION TO TURN ON AND OFF RELAY 1.
{ 
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis1 > interval1) 
  { 
    previousMillis1 = currentMillis;   
    if (ledState1 == LOW)
      ledState1 = HIGH;
    else
      ledState1 = LOW;
    digitalWrite(ledPin1, ledState1);
  }
}



/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  R E L A Y 2 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void relay2()
{
  unsigned long currentMillis2 = millis();

  if(currentMillis2 - previousMillis2 > interval2) 
  {
    previousMillis2 = currentMillis2;   
    if (ledState2 == LOW)
      ledState2 = HIGH;
    else
      ledState2 = LOW;
    digitalWrite(ledPin2, ledState2);
  }
}




/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  S E T U P  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


void setup(){
//  pinMode(ledPin1, OUTPUT);    // set the digital pin as output:
//  pinMode(ledPin2, OUTPUT);    // set the digital pin as output:
  RTC.begin(DateTime(__DATE__, __TIME__));
  GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
  GLCD.ClearScreen();  
   GLCD.SelectFont(System5x7); // switch to fixed width system font
  GLCD.DrawBitmap(seahorse2, 8,0, BLACK); //draw the bitmap at the given x,y position
  GLCD.DrawRoundRect(48,0,32,63, 5, BLACK);  // rounded rectangle around text area  
  GLCD.GotoXY(56, 1);
  GLCD.Puts("S W");
    GLCD.GotoXY(56, 9);
  GLCD.Puts("e h");
    GLCD.GotoXY(56, 17);
  GLCD.Puts("a i");
    GLCD.GotoXY(56, 25);
  GLCD.Puts("h s");
    GLCD.GotoXY(56, 32);
  GLCD.Puts("o p");
    GLCD.GotoXY(56, 40);
  GLCD.Puts("r e");
    GLCD.GotoXY(56, 47);
  GLCD.Puts("s r");
    GLCD.GotoXY(56, 55);
  GLCD.Puts("e s");
   GLCD.DrawBitmap(seahorse, 88,0, BLACK); //draw the bitmap at the given x,y position
  GLCD.SelectFont(System5x7); // switch to fixed width system font 
  countdown(1); 
  GLCD.ClearScreen();
  introScreen();              // show some intro stuff 
  GLCD.ClearScreen();
  BusinessScreen();
}
void introScreen(){
  GLCD.SelectFont(Arial_14); // you can also make your own fonts, see playground for details   
  GLCD.GotoXY(20, 2);
  GLCD.Puts("GLCD  version  ");
  GLCD.PrintNumber(GLCD_VERSION);
  GLCD.DrawRoundRect(16,0,99,18, 5, BLACK);  // rounded rectangle around text area   
  GLCD.SelectFont(System5x7); // switch to fixed width system font 
  showCharacters();
  countdown(1);
}


void showCharacters(){
  byte line = 3; // start on the fourth line 
  for(byte c = 32; c <=127; c++){
     if( (c-32) % 20 == 0)
         GLCD.CursorTo(1,line++);  // CursorTo is used for fixed width system font
     GLCD.PutChar(c);    
  }   
}


void countdown(int count){
    while(count--){  // do countdown  
     GLCD.CursorTo(0,1);   // first column, second row (offset is from 0)
     GLCD.PutChar(count + '0');
     delay(1000);  
  } 
//   Serial.begin(9600);
 // irrecv.enableIRIn(); // Start the receiver 
}

  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  S E T U P - D I S P L A Y |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

void BusinessScreen(){

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();

  // Change these values to what you want to set your clock to.
  // You probably only want to set your clock once and then remove
  // the setDateDs1307 call.
//  second = 56;
//  minute = 57;
//  hour = 23;
//  dayOfWeek = 6;  // Sunday is 0
//  dayOfMonth = 26;
//  month = 2;
//  year = 11;
  //setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

  analogWrite(blue, bluemin);
  analogWrite(white, whitemin);
//  GLCD.begin(20, 8); // set up the LCD's number of rows and columns: 
  //  lcd.print("12:00 80.6"); // Print a message to the LCD.
  //  lcd.print(char(223));
  //byte line = 2; // start on the 3rd line 
  GLCD.GotoXY(0, 8 );
  GLCD.Puts("Blue:   ");
 // GLCD.PrintNumber(33*blueramptime/85);
  //GLCD.Puts("%");
  //       GLCD.GotoXY(1,1);  // GotoXY is used for fixed width system font
  GLCD.GotoXY(0, 16);
 GLCD.Puts("White:   ");
  //GLCD.PrintNumber(33*whiteramptime/85);  
//  GLCD.Puts("%");
GLCD.DrawBitmap(seahorse2, 100,0, BLACK); //draw the bitmap at the given x,y position
//GLCD.DrawBitmap(MoonUp, 0,32, WHITE); //draw the bitmap at the given x,y position
//GLCD.DrawBitmap(SunSet, 64,32, WHITE); //draw the bitmap at the given x,y position

}
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L O O P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void loop()
{
  onesecond();
  relay2();
  relay1();

    

//if (irrecv.decode(&results)) {
//    Serial.println(results.value, HEX);
//    irrecv.resume(); // Receive the next value
//  }

  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L O O P - D I M   F U N C T I O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
DateTime now = RTC.now();
  int daybyminute = ((now.hour() * 60) + now.minute()); //converts time of day to a single value in minutes
 //  int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
      

 
  int bluerampup;
     if (daybyminute >= (ontime*60)) 
       bluerampup = (((ontime*60) + blueramptime) - daybyminute);
     else
       bluerampup = blueramptime;
       
  int whiterampup;
    if (daybyminute >= (ontime*60 + blueramptime)) 
       whiterampup = (((ontime*60) + blueramptime + whiteramptime) - daybyminute);
     else
       whiterampup = whiteramptime;

  int whiterampdown;
    if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
      whiterampdown = (((ontime*60) + photoperiod + blueramptime + 2*whiteramptime) - daybyminute);
    else
      whiterampdown = whiteramptime;
      
  int bluerampdown;
    if (((ontime * 60) + photoperiod + blueramptime + 2*whiteramptime) <= daybyminute)
      bluerampdown = (((ontime*60) + photoperiod + 2*blueramptime + 2*whiteramptime) - daybyminute);
    else
      bluerampdown = blueramptime;






  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L O O P - F A D E  I N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


 if (daybyminute >= (ontime*60))
  { 

    if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime/10*9))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
    {
    FansOn();
      // fade blue LEDs in from min to max.
      
      for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0% 
     { 
    char* UpNext[] = {"white", "ramp", "up"};
      Next();
    if((ontime + (blueramptime/60))<12)
      {
        GLCD.PrintNumber (ontime + (blueramptime/60));
        GLCD.Puts(":00am");
      }
      else
      {
        GLCD.PrintNumber (ontime + (blueramptime/60) - 12);
        GLCD.Puts(":00pm");
      }
      GLCD.GotoXY(0, 24 );
      GLCD.Puts("Dawn       ");
      GLCD.DrawBitmap(Dawn, 0,32, WHITE); //draw the bitmap at the given x,y position 
       analogWrite(blue, bluepercent[i]); 
       GLCD.GotoXY(30, 8);
                GLCD.Puts("    ");
       GLCD.GotoXY(30, 8);
        GLCD.PrintNumber(i*10);
        GLCD.Puts("%"); 
        GLCD.GotoXY(36, 16);
             GLCD.Puts("    ");
        GLCD.GotoXY(36, 16);
        GLCD.PrintNumber(0);
        GLCD.Puts("% ");
           
        int countdown = ((bluerampup*60)/10); // calculates seconds to next step
        while (countdown>0)
          {
          onesecond(); // updates clock once per second
          countdown--;
          relay2();
          relay1();
        }
      }      

      // fade white LEDs in from min to max.
      for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0%
      { 
      char* UpNext[] = {"all", "lights", "max"};
        Next();
      if((ontime + (blueramptime/60) + (whiteramptime/60))<12)
        {
          GLCD.PrintNumber (ontime + (blueramptime/60) + (whiteramptime/60));
          GLCD.Puts(":00am");
        }
        else
        {
          GLCD.PrintNumber (ontime + (blueramptime/60) + (whiteramptime/60) - 12);
          GLCD.Puts(":00pm");
        }       
        GLCD.GotoXY(0, 24 );
      GLCD.Puts("Sunrise    ");
      GLCD.DrawBitmap(SunRise, 0,32, WHITE); //draw the bitmap at the given x,y position
        analogWrite(white, whitepercent[i]); 
        GLCD.GotoXY(36, 16);
             GLCD.Puts("    ");
        GLCD.GotoXY(36, 16);
        GLCD.PrintNumber(i*10);
        GLCD.Puts("%");
 
   int countdown = ((whiterampup*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          countdown--;
          relay2();
          relay1();
        }
      } 
    }
  }

  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L O O P - M A X  V A L U E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



 if (daybyminute >= ((ontime * 60) + blueramptime + whiteramptime)) 
  { 
    if ( daybyminute < ((ontime * 60) + blueramptime +  whiteramptime + photoperiod)) // if time is in range of photoperiod, turn lights on to maximum fade value
       {
    char* UpNext[] = {"white", "ramp", "down"};
    Next();
    if((ontime + (blueramptime/60) + (whiteramptime/60) + (photoperiod/60))<12)
      {
        GLCD.PrintNumber (ontime + (blueramptime/60) + (whiteramptime/60)+ (photoperiod/60));
        GLCD.Puts(":00am");
      }
      else
      {
        GLCD.PrintNumber (ontime + (blueramptime/60) + (whiteramptime/60)+ (photoperiod/60) - 12);
        GLCD.Puts(":00pm");
      }
    FansOn();
    GLCD.GotoXY(0, 24 );
    GLCD.Puts("Daytime   ");
    GLCD.DrawBitmap(SunUp, 0,32, WHITE); //draw the bitmap at the given x,y position
 
      analogWrite(blue, 255);
       GLCD.GotoXY(30, 8);
                GLCD.Puts("    ");
       GLCD.GotoXY(30, 8);
        GLCD.PrintNumber(100);
      GLCD.Puts("%");
      analogWrite(white, 255); 
        GLCD.GotoXY(36, 16);
             GLCD.Puts("    ");
        GLCD.GotoXY(36, 16);
        GLCD.PrintNumber(100);
      GLCD.Puts("%");
      
    } 
  }



  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L O O P - F A D E  O U T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



  if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
  { 
    if (((ontime * 60) + photoperiod + whiteramptime + (2*blueramptime) + (whiteramptime/10*9)) >= daybyminute)
    {
    FansOn(); 
      // fade white LEDs out from max to min in increments of 1 point:
      for (int i = 10; i >= 0; i--) // // setting i value for 10% increment. Start with 10%
      { 
   GLCD.GotoXY(64, 8);
char* UpNext[] = {"blue", "ramp", "down"};
  Next();
if((ontime + (blueramptime/60) + (2*whiteramptime/60) + (photoperiod/60))<12)
  {
    GLCD.PrintNumber (ontime + (blueramptime/60) + (2*whiteramptime/60)+ (photoperiod/60));
    GLCD.Puts(":00am");
  }
  else
  {
    GLCD.PrintNumber (ontime + (blueramptime/60) + (2*whiteramptime/60)+ (photoperiod/60) - 12);
    GLCD.Puts(":00pm");
  }        
        GLCD.GotoXY(0, 24 );
      GLCD.Puts("SunSet  ");
      GLCD.DrawBitmap(SunSet, 0,32, WHITE); //draw the bitmap at the given x,y position
        analogWrite(blue, 255);
       GLCD.GotoXY(30, 8);
                GLCD.Puts("    ");
       GLCD.GotoXY(30, 8);
        GLCD.PrintNumber(100);
        GLCD.Puts("%"); 
        
        analogWrite(white, whitepercent[i]); 
        GLCD.GotoXY(36, 16);
             GLCD.Puts("    ");
        GLCD.GotoXY(36, 16);
        GLCD.PrintNumber(i*10);
       GLCD.Puts("%");  

        int countdown = ((whiterampdown*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          countdown--;
          relay2();
          relay1();
        }

      } 

      // fade blue LEDs out from max to min in increments of 1 point:
      for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
      { 
char* UpNext[] = {"All", "Lights", "off"};
  Next();
if((ontime + (2*blueramptime/60) + (2*whiteramptime/60) + (photoperiod/60))<12)
  {
    GLCD.PrintNumber (ontime + (2*blueramptime/60) + (2*whiteramptime/60)+ (photoperiod/60));
    GLCD.Puts(":00am");
  }
  else
  {
    GLCD.PrintNumber (ontime + (2*blueramptime/60) + (2*whiteramptime/60)+ (photoperiod/60) - 12);
    GLCD.Puts(":00pm");
  }    
        GLCD.GotoXY(0, 24 );
      GLCD.Puts("Dusk    ");
      GLCD.DrawBitmap(Dusk, 0,32, WHITE); //draw the bitmap at the given x,y position
        analogWrite(blue, bluepercent[i]);
        GLCD.GotoXY(30, 8);
                GLCD.Puts("    ");
       GLCD.GotoXY(30, 8);
        GLCD.PrintNumber(i*10);
        GLCD.Puts("%"); 

        int countdown = ((bluerampdown*60)/10); // calculates seconds to next step
        while (countdown>0)
        {
          onesecond(); // updates clock once per second
          countdown--;
          relay2();
          relay1();
        }
      }
    }
  }
 //*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  Night Time |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/

if (((ontime * 60) + photoperiod + (2 * blueramptime) + (2 * whiteramptime)) < daybyminute)
  {         
      GLCD.GotoXY(64, 8);
char* UpNext[] = {"blue", "ramp", "up"};
  Next();
if((ontime)<12)
  {
    GLCD.PrintNumber (ontime);
    GLCD.Puts(":00am");
  }
  else
  {
    GLCD.PrintNumber (ontime - 12);
    GLCD.Puts(":00pm");
  }
    FansOff();  
    GLCD.GotoXY(30, 8);
                GLCD.Puts("    ");
       GLCD.GotoXY(30, 8);
        GLCD.PrintNumber(0);
        GLCD.Puts("%");
        GLCD.GotoXY(36, 16);
             GLCD.Puts("    ");
        GLCD.GotoXY(36, 16);
        GLCD.PrintNumber(0);
        GLCD.Puts("%");
  GLCD.GotoXY(0, 24 );
   GLCD.Puts("Night time");
   GLCD.DrawBitmap(MoonUp, 0,32, WHITE); //draw the bitmap at the given x,y position

  }
 if (daybyminute < (ontime*60))
{
char* UpNext[] = {"blue", "ramp", "up"};
  Next();
if((ontime)<12)
  {
    GLCD.PrintNumber (ontime);
    GLCD.Puts(":00am");
  }
  else
  {
    GLCD.PrintNumber (ontime - 12);
    GLCD.Puts(":00pm");
  }
    FansOff();
  GLCD.GotoXY(30, 8);
                GLCD.Puts("    ");
       GLCD.GotoXY(30, 8);
        GLCD.PrintNumber(0);
        GLCD.Puts("%");
        GLCD.GotoXY(36, 16);
             GLCD.Puts("    ");
        GLCD.GotoXY(36, 16);
        GLCD.PrintNumber(0);
        GLCD.Puts("%");
  GLCD.GotoXY(0, 24 );
   GLCD.Puts("Night time");
   GLCD.DrawBitmap(MoonUp, 0,32, WHITE); //draw the bitmap at the given x,y position
}
}  
  // END LOOP

EDIT: I also got a little excited as I found a box, in the basement, for an external CD/DVD with a 5v and 12v lead/power supply. The screen doesn't quite fit so I still have some figuring, but other than that it's sweet:
IMAG0062.jpg
 
Last edited:
also I would not power the fan from the arduino instead hook it up just like we do the meanwells with a transistor inbetween the negative of a power supply and the fan..... I am ordering a 10v regulator and a 7.5v regulator if I can find one and I will build a small power circuit to power everything off a regulated 12v radioshack wallwart. Arduino will get the 7.5v regulator and the meanwells will get the 10v regulator anything else like nighttime LED's and fan will be fed the 12v straight with no regulators
 
Hmmmm try to get that fan working from a analog pin would save us a digital input. as soon as my girl leaves for work I will get my fans working on this or at least try
 
Hmmmm try to get that fan working from a analog pin would save us a digital input. as soon as my girl leaves for work I will get my fans working on this or at least try

Running the mega 1280 with 50 digitals, not worried about saving one. :lmao:

As well I'm planning on setting up mine like ktnch: http://www.reefcentral.com/forums/showpost.php?p=18566367&postcount=302

I'll have 2 extra regulated 10v PWM signals (running through a 2nd op amp) so I figured why not use it.

At the moment I'm turned off by the IR as it was mostly gimmick. At this point I think I'm going to move on to buttons and some sort of menu...pretty scared...heh:confused:
 
So I still have the occasional artifact...any thoughts? Basically it's like it refreshes the screen but maybe one letter is shifted partially.

I have another question of "correct" coding. Let's say that I print the word "Start" and an hour later I print the word "End" in the same place. It ends up looking like "Endrt" because the last 2 letters are left over. Is there a smart way to get rid of the previous word? Currently I just do something like "End " adding spaces to clear out previous text...
 
yup just add a few spaces to clean it.... as for the artifact issue no idea other than its in the code somewhere..
 
Hello!

I´m making this build and it is "kind" of working, I say "kind" because the leds dim are made with huge steps, not smooth. In the first step, 0/1 to 26 it ligth up like 0 to 40% or 50% of total power. When it turns on I can see leds with a very wheak ligth, on the next step... BUmmm, 40% of total power. Same thing on both blues and whites.
I´m using the 48P driven with 2n2222.
As I´m in test mode I have my ramp´s set to 10 minutes now.
Already tryed to change this :

int bluepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 }; // this line is needed if you are using meanwell ELN60-48P
int whitepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 }; // these are the values in 10% increments

to lower values like : 0, 2, 5, 10, .... no luck.

So, is this behaviour normal or do I have something wrong in my code?

many thanks,
Henrique


First of all, welcome to RC, and to my thread.... I apologize for the delay, im done moving but everything right now are scattered everywhere and still in boxes... its very chaotic....


this is not normal.... please double check everthing specially the wiring... are you sure, you are using NPN? because you can easily have it mixed with PNP? do you have what i have? as in terms of hardware? what kind of hardware do you have, please list it here.... do you have a pic?

Im curious as to why it acts like that...

You should have something like this....

PHP:
//int bluepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 };   // this line is needed if you are using meanwell ELN60-48D
//int whitepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 };   // these are the values in 10% increments

int bluepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };   // this line is needed if you are using meanwell ELN60-48P
int whitepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };   // these are the values in 10% increments
 
Here is the previous post Shikyung...

To all, there are 2 functions on this sketch...

FUNCTION 1
We are only talking about "one" function... which is the ramp down and up of two channel/s. One for white and one for blue...

FUNCTION 2
We just need (FUTURE) to add a low voltage relay and this can be used as a wavetimer. We have two channel/s already built in on this sketch. This is "RELAY1" and "RELAY2". Arduino PIN 2 & 8
 
First of all, welcome to RC, and to my thread.... I apologize for the delay, im done moving but everything right now are scattered everywhere and still in boxes... its very chaotic....


this is not normal.... please double check everthing specially the wiring... are you sure, you are using NPN? because you can easily have it mixed with PNP? do you have what i have? as in terms of hardware? what kind of hardware do you have, please list it here.... do you have a pic?

Im curious as to why it acts like that...

You should have something like this....

PHP:
//int bluepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 };   // this line is needed if you are using meanwell ELN60-48D
//int whitepercent[11] = { 0, 1, 2, 5, 8 ,12, 18, 27, 44, 80, 255 };   // these are the values in 10% increments

int bluepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };   // this line is needed if you are using meanwell ELN60-48P
int whitepercent[11] = { 0, 26, 52, 78, 103, 128, 154, 180, 205, 230, 255 };   // these are the values in 10% increments

Hello!

I´ve tried the 2N2222, pwm out to transistor base , with and without resistor, and also tried the ICL7667 with same results (only diference from transt to IC was 255=0 and 0=255)
To have something similar to a fade I changed the ramp code to:

int bluepercent[11] = { 0, 24, 25, 26, 30 ,50, 70, 100, 150, 200, 255 }; // this line is needed if you are using meanwell ELN60-48P
int whitepercent[11] = { 0, 24, 25, 26, 30 ,50, 70, 100, 150, 200, 255 }; // these are the values in 10% increments

My hardware is a Mega, HD47780 20x4 display, ds1307 RTC, LM35 for temperature.
The 10V for dimming came from wall power supply regulated by a 7810 but also tried with a 9.5V PS with same results.
Is it possible I have the wrong transistor?
One thing I note is that when fading out is more sustainable, a bit more smooth.

Thanks for your help.
Henrique
 
Any one had any luck with buttons? I was able to run a simple sketch and it worked just fine:
PHP:
#include <Button.h>

//create a Button object at pin 12
/*
|| Wiring:
|| GND -----/ ------ pin 12
*/
Button button = Button(12,PULLUP);

void setup(){
  pinMode(13,OUTPUT); //debug to led 13
}
void loop(){
  if(button.isPressed()){
	digitalWrite(13,HIGH);
  }else{
	digitalWrite(13,LOW);
  }
}

But when I added the pieces to my main sketch it didn't respond at all. I spent about an hour+ trying different pins and commands with no luck. Any thoughts?
 
Back
Top