AcquaPortal Forum Acquario Dolce e Acquario Marino

AcquaPortal Forum Acquario Dolce e Acquario Marino (http://www.acquariofilia.biz/forum.php)
-   Fai da te marino (http://www.acquariofilia.biz/forumdisplay.php?f=60)
-   -   Controller plafoniere fai da te Arduino alla portata di tutti (http://www.acquariofilia.biz/showthread.php?t=441446)

matteociocca 02-01-2014 02:26

Controller plafoniere fai da te Arduino alla portata di tutti
 
Ciao a tutti.
Se state pensando di realizzare un controller per la vostra plafoniera led autocostruita e state pensando ad Arduino questo articolo può fare al caso vostro.

Ero alla ricerca di un controller per la mia plafoniera ed avevo pensato ad arduino solo che una volta acquistato, anche se ho un minimo di conoscenza nella programmazione, non avevo voglia di perdere mooooolte ore per realizzare un codice.
Quello che serviva a me era poter gestire 2-3 canali con effetto alba-tramonto, mi sono messo a cercare online e sono incappato in un controller(non dico il nome) in grado di fare questo.
Ed ecco l'idea, perchè non realizzare l'hardware sulla base del codice anzichè viceversa?

Perciò analizzando il codice(disponibile online perchè open source) sono risalito all'hardware necessario, ed ecco cosa serve per realizzare il vostro controller :
-Arduino uno
-RTC ds1307
-Display 1602
-4 switch button
-4 resistenze 10kOhm
-1 resistenza 2.2kOhm
-1 resistenza 100 Ohm
-1 transistor BC547

Ecco lo schema per collegare tutti i componenti



http://s22.postimg.cc/c532hot31/collegamenti.jpg

L'unica cosa non corretta nei collegamenti sono i pulsanti, cioè manca il disegno della resistenza.
Ecco come realizzare un pulsante digitale:

http://s29.postimg.cc/yed7q21xv/arduino10.jpg

Per quanto riguarda l'RTC acquistatelo già su pcb con pila e non dovrete fare nulla se non collegarlo ad arduino senza dover assembrare tutti i componenti come in figura.
Io ho realizzato tutti e 4 i pulsanti su una millefori rettangolare in modo di avere i pulsanti già tutti su uno stesso piano tutti insieme e con la disposizione che si desidera.

Una volta realizzato l'hardware, basterà collegare il dispositivo al pc, e caricare tramite l'ambiente di sviluppo Arduino 0022, e mi raccomando Arduino 0022 e non i successivi, il codice seguente:



[
codice:

// include the libraries:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Button.h>
#include <EEPROM.h>
#include <EEPROMVar.h>


/**** Define Variables & Constants ****/
/**************************************/

// set the RTC's I2C address
#define DS1307_I2C_ADDRESS 0x68
// create the LCD
LiquidCrystal lcd(8, 7, 5, 4, 16, 2);
// set up backlight
int bkl        = 6;        // backlight pin
byte bklIdle    = 10;      // PWM value for backlight at idle
byte bklOn      = 70;      // PWM value for backlight when on
int bklDelay    = 10000;    // ms for the backlight to idle before turning off
unsigned long bklTime = 0;  // counter since backlight turned on
// create the menu counter
int menuCount  = 1;
int menuSelect = 0;

//create the plus and minus navigation delay counter with its initial maximum of 250.
byte btnMaxDelay = 200;
byte btnMinDelay = 25;
byte btnMaxIteration = 5;
byte btnCurrIteration;

//create manual override variables
boolean override = false;
byte overmenu = 0;
int overpercent = 0;

// create the buttons
Button menu    = Button(12,PULLDOWN);
Button select  = Button(13,PULLDOWN);
Button plus    = Button(14,PULLDOWN);
Button minus    = Button(15,PULLDOWN);

// LED variables. These control the behavior of lighting. Change these to customize behavoir
int minCounter = 0;        // counter that resets at midnight.
int oldMinCounter = 0;      // counter that resets at midnight.
int oneLed = 9;            // pin for channel 1
int twoLed = 10;            // pin for channel 2
int threeLed = 11;          // pin for channel 3
int fourLed = 3;            // pin for channel 4

int oneVal = 0;            // current value for channel 1
int twoVal = 0;            // current value for channel 2
int threeVal = 0;          // current value for channel 3
int fourVal = 0;            // current value for channel 4

// Variables making use of EEPROM memory:

EEPROMVar<int> oneStartMins = 750;      // minute to start this channel.
EEPROMVar<int> onePhotoPeriod = 720;  // photoperiod in minutes for this channel.
EEPROMVar<int> oneMax = 100;          // max intensity for this channel, as a percentage
EEPROMVar<int> oneFadeDuration = 60;  // duration of the fade on and off for sunrise and sunset for
                                      //    this channel.
EEPROMVar<int> twoStartMins = 810;
EEPROMVar<int> twoPhotoPeriod = 600;
EEPROMVar<int> twoMax = 100;
EEPROMVar<int> twoFadeDuration = 60;

EEPROMVar<int> threeStartMins = 810;
EEPROMVar<int> threePhotoPeriod = 600;
EEPROMVar<int> threeMax = 100;
EEPROMVar<int> threeFadeDuration = 60;
                           
EEPROMVar<int> fourStartMins = 480;
EEPROMVar<int> fourPhotoPeriod = 510; 
EEPROMVar<int> fourMax = 100;         
EEPROMVar<int> fourFadeDuration = 60; 

// variables to invert the output PWM signal,
// for use with drivers that consider 0 to be "on"
// i.e. buckpucks. If you need to provide an inverted
// signal on any channel, set the appropriate variable to true.
boolean oneInverted = false;
boolean twoInverted = false;
boolean threeInverted = false;
boolean fourInverted = false;

/*
int oneStartMins = 1380;      // minute to start this channel.
int onePhotoPeriod = 120;  // photoperiod in minutes for this channel.
int oneMax = 100;          // max intensity for this channel, as a percentage
int oneFadeDuration = 60;  // duration of the fade on and off for sunrise and sunset for
                                      //    this channel.                                   
int twoStartMins = 800;
int twoPhotoPeriod = 60;
int twoMax = 100;
int twoFadeDuration = 15;

int threeStartMins = 800;
int threePhotoPeriod = 60;
int threeMax = 100;
int threeFadeDuration = 30;
                           
int fourStartMins = 800;
int fourPhotoPeriod = 120; 
int fourMax = 100;         
int fourFadeDuration = 60; 
*/

/****** RTC Functions ******/
/***************************/

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

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

// Sets date and time, starts the clock
void setDate(byte second,        // 0-59
            byte minute,        // 0-59
            byte hour,          // 1-23
            byte dayOfWeek,    // 1-7
            byte dayOfMonth,    // 1-31
            byte month,        // 1-12
            byte year)          // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second));
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.endTransmission();
}

// Gets the date and time
void getDate(byte *second,
            byte *minute,
            byte *hour,
            byte *dayOfWeek,
            byte *dayOfMonth,
            byte *month,
            byte *year)
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  *second    = bcdToDec(Wire.receive() & 0x7f);
  *minute    = bcdToDec(Wire.receive());
  *hour      = bcdToDec(Wire.receive() & 0x3f);
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year      = bcdToDec(Wire.receive());
}

/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down

int  setLed(int mins,        // current time in minutes
            int ledPin,        // pin for this channel of LEDs
            int start,        // start time for this channel of LEDs
            int period,        // photoperiod for this channel of LEDs
            int fade,          // fade duration for this channel of LEDs
            int ledMax,        // max value for this channel
            boolean inverted  // true if the channel is inverted
            )  {
  int val = 0;
     
      //fade up
      if (mins > start || mins <= start + fade)  {
        val = map(mins - start, 0, fade, 0, ledMax);
      }
      //fade down
      if (mins > start + period - fade && mins <= start + period)  {
        val = map(mins - (start + period - fade), 0, fade, ledMax, 0);
      }
      //off or post-midnight run.
      if (mins <= start || mins > start + period)  {
        if((start+period)%1440 < start && (start + period)%1440 > mins )
          {
            val=map((start+period-mins)%1440,0,fade,0,ledMax);
          }
        else 
        val = 0;
      }
   
   
    if (val > ledMax)  {val = ledMax;}
    if (val < 0) {val = 0; }
   
  if (inverted) {analogWrite(ledPin, map(val, 0, 100, 255, 0));}
  else {analogWrite(ledPin, map(val, 0, 100, 0, 255));}
  if(override){val=overpercent;}
  return val;
}

/**** Display Functions ****/
/***************************/

//button hold function
int btnCurrDelay(byte curr)
{
  if(curr==btnMaxIteration)
  {
    btnCurrIteration = btnMaxIteration;
    return btnMaxDelay;
  }
  else if(btnCurrIteration ==0)
  {
    return btnMinDelay;
  }
  else
  {
    btnCurrIteration--;
    return btnMaxDelay;
  }
}

// format a number of minutes into a readable time (24 hr format)
void printMins(int mins,      //time in minutes to print
              boolean ampm    //print am/pm?
              )  {
  int hr = (mins%1440)/60;
  int mn = mins%60;
    if(hr<10){
      lcd.print(" ");
    }
    lcd.print(hr);
    lcd.print(":");
    if(mn<10){
      lcd.print("0");
    }
    lcd.print(mn);
}

// format hours, mins, secs into a readable time (24 hr format)
void printHMS (byte hr,
              byte mn,
              byte sec      //time to print
              ) 
{
 
    if(hr<10){
      lcd.print(" ");
    }
    lcd.print(hr, DEC);
    lcd.print(":");
    if(mn<10){
      lcd.print("0");
    }
    lcd.print(mn, DEC);
    lcd.print(":");
    if(sec<10){
      lcd.print("0");
    }
    lcd.print(sec, DEC);
}
void ovrSetAll(int pct){
    analogWrite(oneLed,map(pct,0,100,0,255));
    analogWrite(twoLed,map(pct,0,100,0,255));
    analogWrite(threeLed,map(pct,0,100,0,255));
    analogWrite(fourLed,map(pct,0,100,0,255));
}

/**** Setup ****/
/***************/

void setup() {
  Wire.begin();
  pinMode(bkl, OUTPUT);
  lcd.begin(16, 2);
  digitalWrite(bkl, HIGH);
  lcd.print("Matteo-Reef");
  lcd.setCursor(0,1);
  lcd.print("");
  delay(5000);
  lcd.clear();
  analogWrite(bkl,bklIdle);
  btnCurrIteration = btnMaxIteration;
}

/***** Loop *****/
/****************/

void loop() {
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

  getDate(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  oldMinCounter = minCounter;
  minCounter = hour * 60 + minute;
 
  //reset plus & minus acceleration counters if the button's state has changed
  if(plus.stateChanged())
  {
  btnCurrDelay(btnMaxIteration);
  }
  if(minus.stateChanged())
  { 
    btnCurrDelay(btnMaxIteration);
  }
     
 
  //check & set fade durations
  if(oneFadeDuration > onePhotoPeriod/2 && onePhotoPeriod >0){oneFadeDuration = onePhotoPeriod/2;}
  if(oneFadeDuration<1){oneFadeDuration=1;}
 
  if(twoFadeDuration > twoPhotoPeriod/2 && twoPhotoPeriod >0){twoFadeDuration = twoPhotoPeriod/2;}
  if(twoFadeDuration<1){twoFadeDuration=1;}
 
  if(threeFadeDuration > threePhotoPeriod/2 && threePhotoPeriod >0){threeFadeDuration = threePhotoPeriod/2;}
  if(threeFadeDuration<1){threeFadeDuration=1;}
 
  if(fourFadeDuration > fourPhotoPeriod/2 && fourPhotoPeriod > 0){fourFadeDuration = fourPhotoPeriod/2;}
  if(fourFadeDuration<1){fourFadeDuration=1;}
 
  //check & set any time functions
 
 
  //set outputs
  if(!override){
  oneVal = setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, oneFadeDuration, oneMax, oneInverted);
  twoVal = setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, twoFadeDuration, twoMax, twoInverted);
  threeVal = setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, threeFadeDuration, threeMax, threeInverted);
  fourVal = setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fourFadeDuration, fourMax, fourInverted);
  }
  else{
    ovrSetAll(overpercent);
  }
 
 
  //turn the backlight off and reset the menu if the idle time has elapsed
  if(bklTime + bklDelay < millis() && bklTime > 0 ){
    analogWrite(bkl,bklIdle);
    menuCount = 1;
    lcd.clear();
    bklTime = 0;
  }

  //iterate through the menus
  if(menu.uniquePress()){
    analogWrite(bkl,bklOn);
    bklTime = millis();
    if(menuCount < 20){
      menuCount++;
    }else {
      menuCount = 1;
    }
  lcd.clear();
  }
  if(menuCount == 1){
    //main screen turn on!!!
    if (minCounter > oldMinCounter){
      lcd.clear();
    }
    lcd.setCursor(0,0);
    printHMS(hour, minute, second);
    lcd.setCursor(0,1);
    lcd.print(oneVal);
    lcd.setCursor(4,1);
    lcd.print(twoVal);
    lcd.setCursor(8,1);
    lcd.print(threeVal);
    lcd.setCursor(12,1);
    lcd.print(fourVal);
    //debugging function to use the select button to advance the timer by 1 minute
    //if(select.uniquePress()){setDate(second, minute+1, hour, dayOfWeek, dayOfMonth, month, year);}
  }
 
  if(menuCount == 2){
    //Manual Override Menu
    lcd.setCursor(0,0);
    lcd.print("Manual Overrides");
    lcd.setCursor(0,1);
    lcd.print("All: ");
    if(select.uniquePress()){
      if(menuSelect < 3){menuSelect++;}
      else{menuSelect = 0;}
      bklTime = millis();
    }
   
    if(menuSelect == 0){
      lcd.print("Timer");
      override = false;}
    if(menuSelect == 1){
      lcd.print("ON  ");
      overpercent = 100;
      override = true;}
    if(menuSelect == 2){
      lcd.print("OFF  ");
      overpercent = 0;
      override = true;}   
    if(menuSelect == 3){
      override = true;
      lcd.print(overpercent,DEC);
      lcd.print("%  ");
      if(plus.isPressed() && overpercent <100)
        {
          overpercent++;
          delay(btnCurrDelay(btnCurrIteration-1));
          bklTime = millis();
        }
       
        if(minus.isPressed() && overpercent > 0)
        {
          overpercent--;
          delay(btnCurrDelay(btnCurrIteration-1));
          bklTime = millis();
        }
      }
}
 


  if(menuCount == 3){
    //set start time for channel one
    lcd.setCursor(0,0);
    lcd.print("Channel 1 Start");
    lcd.setCursor(0,1);
    printMins(oneStartMins, true);
   
    if(plus.isPressed() && oneStartMins < 1440){
        oneStartMins++;
        if(onePhotoPeriod >0){onePhotoPeriod--;}
        else{onePhotoPeriod=1439;}
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && oneStartMins > 0){
        oneStartMins--;
        if(onePhotoPeriod<1439){onePhotoPeriod++;}
        else{onePhotoPeriod=0;}
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 4){
    //set end time for channel one
    lcd.setCursor(0,0);
    lcd.print("Channel 1 End");
    lcd.setCursor(0,1);
    printMins(oneStartMins+onePhotoPeriod, true);
    if(plus.isPressed()){
      if(onePhotoPeriod < 1439){
      onePhotoPeriod++;}
      else{
        onePhotoPeriod=0;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed()){
      if(onePhotoPeriod >0){
        onePhotoPeriod--;}
      else{
        onePhotoPeriod=1439;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 5){
    //set fade duration for channel one
    lcd.setCursor(0,0);
    lcd.print("Channel 1 Fade");
    lcd.setCursor(0,1);
    printMins(oneFadeDuration, false);
    if(plus.isPressed() && (oneFadeDuration < onePhotoPeriod/2 || oneFadeDuration == 0)){
      oneFadeDuration++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && oneFadeDuration > 1){
      oneFadeDuration--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 6){
    //set intensity for channel one
    lcd.setCursor(0,0);
    lcd.print("Channel 1 Max");
    lcd.setCursor(1,1);
    lcd.print(oneMax);
    lcd.print("  ");
    if(plus.isPressed() && oneMax < 100){
      oneMax++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && oneMax > 0){
      oneMax--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 7){
    //set start time for channel two
    lcd.setCursor(0,0);
    lcd.print("Channel 2 Start");
    lcd.setCursor(0,1);
    printMins(twoStartMins, true);
    if(plus.isPressed() && twoStartMins < 1440){
        twoStartMins++;
        if(twoPhotoPeriod >0){twoPhotoPeriod--;}
        else{twoPhotoPeriod=1439;}
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && twoStartMins > 0){
        twoStartMins--;
        if(twoPhotoPeriod<1439){twoPhotoPeriod++;}
        else{twoPhotoPeriod=0;}
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 8){
    //set end time for channel two
    lcd.setCursor(0,0);
    lcd.print("Channel 2 End");
    lcd.setCursor(0,1);
    printMins(twoStartMins+twoPhotoPeriod, true);
    if(plus.isPressed()){
      if(twoPhotoPeriod < 1439){
      twoPhotoPeriod++;}
      else{
        twoPhotoPeriod=0;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed()){
      if(twoPhotoPeriod >0){
        twoPhotoPeriod--;}
      else{
        twoPhotoPeriod=1439;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 9){
    //set fade duration for channel two
    lcd.setCursor(0,0);
    lcd.print("Channel 2 Fade");
    lcd.setCursor(0,1);
    printMins(twoFadeDuration, false);
    if(plus.isPressed() && (twoFadeDuration < twoPhotoPeriod/2 || twoFadeDuration == 0)){
      twoFadeDuration++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && twoFadeDuration > 1){
      twoFadeDuration--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 10){
    //set intensity for channel two
    lcd.setCursor(0,0);
    lcd.print("Channel 2 Max");
    lcd.setCursor(1,1);
    lcd.print(twoMax);
    lcd.print("  ");
    if(plus.isPressed() && twoMax < 100){
      twoMax++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && twoMax > 0){
      twoMax--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 11){
    //set start time for channel three
    lcd.setCursor(0,0);
    lcd.print("Channel 3 Start");
    lcd.setCursor(0,1);
    printMins(threeStartMins, true);
    if(plus.isPressed() && threeStartMins < 1440){
        threeStartMins++;
        if(threePhotoPeriod >0){threePhotoPeriod--;}
        else{threePhotoPeriod=1439;}
        delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && threeStartMins > 0){
        threeStartMins--;
        if(threePhotoPeriod<1439){threePhotoPeriod++;}
        else{threePhotoPeriod=0;}
        delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 12){
    //set end time for channel three
    lcd.setCursor(0,0);
    lcd.print("Channel 3 End");
    lcd.setCursor(0,1);
    printMins(threeStartMins+threePhotoPeriod, true);
    if(plus.isPressed()){
      if(threePhotoPeriod < 1439){
      threePhotoPeriod++;}
      else{
        threePhotoPeriod=0;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed()){
      if(threePhotoPeriod >0){
        threePhotoPeriod--;}
      else{
        threePhotoPeriod=1439;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 13){
    //set fade duration for channel three
    lcd.setCursor(0,0);
    lcd.print("Channel 3 Fade");
    lcd.setCursor(0,1);
    printMins(threeFadeDuration, false);
    if(plus.isPressed() && (threeFadeDuration < threePhotoPeriod/2 || threeFadeDuration == 0)){
      threeFadeDuration++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && threeFadeDuration > 1){
      threeFadeDuration--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 14){
    //set intensity for channel three
    lcd.setCursor(0,0);
    lcd.print("Channel 3 Max");
    lcd.setCursor(1,1);
    lcd.print(threeMax);
    lcd.print("  ");
    if(plus.isPressed() && threeMax < 100){
      threeMax++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && threeMax > 0){
      threeMax--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 15){
    //set start time for channel four
    lcd.setCursor(0,0);
    lcd.print("Channel 4 Start");
    lcd.setCursor(0,1);
    printMins(fourStartMins, true);
    if(plus.isPressed() && fourStartMins < 1440){
        fourStartMins++;
        if(fourPhotoPeriod >0){fourPhotoPeriod--;}
        else{fourPhotoPeriod=1439;}
        delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && fourStartMins > 0){
        fourStartMins--;
        if(fourPhotoPeriod<1439){fourPhotoPeriod++;}
        else{fourPhotoPeriod=0;}
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 16){
    //set end time for channel four
    lcd.setCursor(0,0);
    lcd.print("Channel 4 End");
    lcd.setCursor(0,1);
    printMins(fourStartMins+fourPhotoPeriod, true);
    if(plus.isPressed()){
      if(fourPhotoPeriod < 1439){
      fourPhotoPeriod++;}
      else{
        fourPhotoPeriod=0;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed()){
      if(fourPhotoPeriod >0){
        fourPhotoPeriod--;}
      else{
        fourPhotoPeriod=1439;
      }
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 17){
    //set fade duration for channel four
    lcd.setCursor(0,0);
    lcd.print("Channel 4 Fade");
    lcd.setCursor(0,1);
    printMins(fourFadeDuration, false);
    if(plus.isPressed() && (fourFadeDuration < fourPhotoPeriod/2 || fourFadeDuration == 0)){
      fourFadeDuration++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && fourFadeDuration > 1){
      fourFadeDuration--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 18){
    //set intensity for channel four
    lcd.setCursor(0,0);
    lcd.print("Channel 4 Max");
    lcd.setCursor(1,1);
    lcd.print(fourMax);
    lcd.print("  ");
    if(plus.isPressed() && fourMax < 100){
      fourMax++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && fourMax > 0){
      fourMax--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  }

  if(menuCount == 19){
    //set hours
    lcd.setCursor(0,0);
    lcd.print("Set Time: Hrs");
    lcd.setCursor(0,1);
    printHMS(hour, minute, second);
    if(plus.isPressed() && hour < 23){
      hour++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && hour > 0){
      hour--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  }
 
  if(menuCount == 20){
    //set minutes
    lcd.setCursor(0,0);
    lcd.print("Set Time: Mins");
    lcd.setCursor(0,1);
    printHMS(hour, minute, second);
    if(plus.isPressed() && minute < 59){
      minute++;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
    if(minus.isPressed() && minute > 0){
      minute--;
      delay(btnCurrDelay(btnCurrIteration-1));
      bklTime = millis();
    }
  setDate(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  }
}

A questo link troverete le librerie da scaricare e da mettere nella cartella libreries di Arduino 0022 prima di caricare il codice su Arduino
Librerie

Penso di aver detto tutto, Buon divertimento, ecco quello che ho realizzato io

http://s16.postimg.cc/klq34hy29/IMG_2412.jpg

LOLLO77 02-01-2014 05:52

Bravissimo#25#25#25#25

Ho capito di che controller si tratta
#25#25#25

aleslai 02-01-2014 06:10

Grazie per aver condiviso il tuo lavoro😉

LOLLO77 02-01-2014 07:21

Quote:

Originariamente inviata da aleslai (Messaggio 1062268101)
Grazie per aver condiviso il tuo lavoro😉

Per ringraziare qualcuno c'è il pulsante apposta. Thanks

matteociocca 02-01-2014 11:33

Visto le numerose richieste di aiuto che ci sono sul forum riguardo ad arduino e mai nessuno che posta i codici ( mi sembra anche giusto visto il duro lavoro XD ) ho deciso di condividere questa piccola guida che può essere anche solo uno spunto visto che il codice poi può essere modificato a piacere, ma per chi è zero assoluto bella programmazione può andare bene

grispa72 02-01-2014 19:50

Grazie per la condivisione.

Qui si trovano altre informazioni. Io come prima cosa ho provato ha collegare il display LCD ma dopo un'ora di prove e il controllo dei collegamenti non sono neanche riuscito a far comparire la scritta classica scritta "Ciao Mondo".

Ho sbagliato a collegare il pin R/W. Invece che alla terra (GND) l'ho collegato a +5V (lato porte analogice. Secondo te ho danneggiato qualcosa?
Perché poi ricollegato tutto giusto non andava ancora >:-(

matteociocca 02-01-2014 20:29

Quote:

Originariamente inviata da grispa72 (Messaggio 1062268812)
Grazie per la condivisione.

Qui si trovano altre informazioni. Io come prima cosa ho provato ha collegare il display LCD ma dopo un'ora di prove e il controllo dei collegamenti non sono neanche riuscito a far comparire la scritta classica scritta "Ciao Mondo".

Ho sbagliato a collegare il pin R/W. Invece che alla terra (GND) l'ho collegato a +5V (lato porte analogice. Secondo te ho danneggiato qualcosa?
Perché poi ricollegato tutto giusto non andava ancora >:-(

Cavolo dove hai trovato quel post..
Mannaggia se lo trovavo faticavo 20 volte meno XD..

Comunque allora sbagliare i collegamenti del positivo non è mai una bella cosa, però non è detto che tu abbia rovinato qualcosa..
Tu che schema stai seguendo per il collegamento?
Se stai facendo delle prove non usare quello postato da me ma uno classico che trovi su nei tutorial, perche cambiano i pin di collegamento e quindi anche quando li dichiari devono corrispondere a quelli a cui li hai collegati.

Segui questa guida per il collegamento del display per le prove
link

grispa72 02-01-2014 20:57

Ho seguito proprio quel tutorial nel link che hai messo tu.
Il mio LCD è un LCM1602C.
Comunque riproverò con calma a ripartire da zero. Spero bene...

matteociocca 02-01-2014 21:10

Tante volte basta un falso contatto e non va nulla..
Controlla le saldature, se è tutto collegato correttamente va per forza..
A schermo cosa ti esce? Si illumina?

grispa72 02-01-2014 21:17

Iniziamo dai componenti. Io ho un Arduino UNO REV3.

Poi l'RTC DS1307 è questo?
Serve pure la batteria (mi pare)?

Questo è il BJT NPN BC547.

Poi per quanto riguarda l'IDE cosa intendi per 0022? Quello che si scarica da qui?

matteociocca 02-01-2014 22:00

L'rtc ok ci siamo, serve anche la batteria.
Anche col transistor ci siamo..
L'IDE ne hanno fatti molti, ed a ogni IDE nuovo vengono apportate modichi al linguaggio utilizzato quindi un comando che nell IDE 0022 funziona nella IDE aggiornata ad oggi ,che mi pare è 1.5 o roba simile , non funziona più..
Perciò per poter utilizzare questo codice che ho postato serve utilizzare l'IDE 0022..
La trovi a questa pagina
link

billykid591 03-01-2014 00:28

C'e' solo una cosa non molto corretta che potrebbe dare problemi di stabilita' mancano le resistenze di pull down sui pulsanti di navigazione collegate tra gli ingressi di arduino e la massa..........per il resto ( anche se non ho visto tutto il codice) ok.
------------------------------------------------------------------------
Quote:

Originariamente inviata da matteociocca (Messaggio 1062268999)
L'rtc ok ci siamo, serve anche la batteria.
Anche col transistor ci siamo..
L'IDE ne hanno fatti molti, ed a ogni IDE nuovo vengono apportate modichi al linguaggio utilizzato quindi un comando che nell IDE 0022 funziona nella IDE aggiornata ad oggi ,che mi pare è 1.5 o roba simile , non funziona più..
Perciò per poter utilizzare questo codice che ho postato serve utilizzare l'IDE 0022..
La trovi a questa pagina
link

Anche con la versione 23 dell'Ide puo' funzionare.... Con le successive ci sono problemi con alcune librerie usate.......

matteociocca 03-01-2014 01:53

Ciao.. Nello schema non sono riportate.. Se leggi bene lo troverai scritto ;)

matteociocca 03-01-2014 02:26

Quote:

Originariamente inviata da matteociocca (Messaggio 1062268069)
L'unica cosa non corretta nei collegamenti sono i pulsanti, cioè manca il disegno della resistenza.

Questo intendevi?

billykid591 03-01-2014 12:08

Si lo schema elettronico non e' completo ( fra l'altro manca l'indicazione delle uscite pwm Usate anche se si deducono dal codice) comunque hai fatto un bel lavoro...se vuoi vedere un gestore di menu piu' sofisticato (funziona pero' con gli ultimi IDE dall' 1.0 in poi) vediti questo link http://forum.arduino.cc/index.php?topic=115498.0

matteociocca 03-01-2014 12:37

essi purtroppo lo schema non le riporta.
gli do un occhiata per il futuro =)

matteociocca 03-01-2014 13:17

tu billykid591 hai provato ad utilizzarlo? quando avevo intenzione di scrivermelo io il codice l'avevo preso in considerazione.
Col dispaly tuoch sai se si può utilizzare?

billykid591 03-01-2014 18:23

io ho solo fatto delle prove con menwiz..... per il touch bisogna usare librerie apposite di solito rilasciate dal produttore del display.... io ho comprato tempo fa un display touch della 4Dsystem che ha la possibilità di essere interfacciato tramite I2c a Arduino ma ho fatto poche prove per mancanza di tempo... ho realizzato un controller a 5 canali un paio di anni fa con display e 5 pulsanti di navigazione......ma non touch.

matteociocca 03-01-2014 19:13

A ok , li ho visto quei display, belli lasciano i pin liberi ma costano una cifra rispetto a quelli che si trovano su ebay.. Ovviamente intendo che costano tanto per farci qualche prova.. Infatti se riesco ne ordino uno dalla Cina con 30€ ti danno il mega,shield e schermo 3.2 touch poi ovviamente la qualità non sarà la stessa =)

billykid591 03-01-2014 21:43

Quote:

Originariamente inviata da matteociocca (Messaggio 1062269958)
A ok , li ho visto quei display, belli lasciano i pin liberi ma costano una cifra rispetto a quelli che si trovano su ebay.. Ovviamente intendo che costano tanto per farci qualche prova.. Infatti se riesco ne ordino uno dalla Cina con 30€ ti danno il mega,shield e schermo 3.2 touch poi ovviamente la qualità non sarà la stessa =)

Il problema dei "normali" display touch grafici che si trovano su ebay e' che sono paralleli e consumano un "botto" di ingressi per cui o si usa il mega o rimangono al massimo due tre piedini di input/output..... Conviene trovare display con interfaccia seriale o, meglio, I2C.... Non esiste solo il 4DSystem.... ( anche se per quest'ulltimo esiste una suite grafica per programmarlo abbastanza facilmente)

Francesco93 19-02-2014 16:24

Un controller costruito seguendo questo progetto va bene per dei meanwell eln-60-48p? Poi come dovrei collegarli? Un capo (quale?) del cavo per dimmer al pin di arduino indicato nel codice, l'altro?

Scusate le domanda probabilmente cretina, ma sono completamente ignorante in materia :-))

matteociocca 19-02-2014 20:12

ciao, se hai il modello con controllo pwm puoi utilizzarlo, colleghi il cavo per ingresso pwm al pin di arduino poi ovviamente i due cavi in entrata alla 220V e quelli in uscita per la serie di led .

billykid591 19-02-2014 23:33

Quote:

Originariamente inviata da matteociocca (Messaggio 1062327870)
ciao, se hai il modello con controllo pwm puoi utilizzarlo, colleghi il cavo per ingresso pwm al pin di arduino poi ovviamente i due cavi in entrata alla 220V e quelli in uscita per la serie di led .

Purtroppo cosi' non funziona o meglio funziona male......il meanwell eln 60-48P funziona si in pwm ma accetta segnali PWM 0-10 volt mentre le uscite pwm di arduino sono 0-5 volt.....si dovrebbe usare un transistor per ogni uscita di arduino alimentato a 10 volt (il typhon ad esempio e'fatto cosi' con doppia uscita)

Francesco93 20-02-2014 11:16

In pratica dovrei fare come dicono qui?
https://sites.google.com/site/caddni...led_controller

Il codice va cambiato in qualche modo?

billykid591 20-02-2014 16:26

Quote:

Originariamente inviata da Francesco93 (Messaggio 1062328506)
In pratica dovrei fare come dicono qui?
https://sites.google.com/site/caddni...led_controller

Il codice va cambiato in qualche modo?

Devi usare l'ultimo schema, quella senza potenziometro (se usi i meanwell tipo P in PWM)....il codice non cambia....

matteociocca 20-02-2014 18:53

Ascolta @billykid591 che ne sa più di me =)

Francesco93 20-02-2014 21:00

Quote:

Originariamente inviata da billykid591 (Messaggio 1062328882)
Quote:

Originariamente inviata da Francesco93 (Messaggio 1062328506)
In pratica dovrei fare come dicono qui?
https://sites.google.com/site/caddni...led_controller

Il codice va cambiato in qualche modo?

Devi usare l'ultimo schema, quella senza potenziometro (se usi i meanwell tipo P in PWM)....il codice non cambia....

Okay, grazie mille per l'aiuto #70

GIMMI 23-02-2014 20:29

Scusate, mi aggancio e seguo.....

marco3020 23-02-2014 23:53

seguo anch'io

Danilolorispaterno 21-06-2015 20:44

Lo schermo vai in crash
 
Dopo aver assemblato e avviato il tutto, lo schermo entra in crash come si vede dalla foto...alcuni dati non compaiono e altri sono sostituiti da altri simboli come per esempio ?#?##?
Cosa c'è che non va?
http://s12.postimg.cc/opuyz4bzd/1434...1814720309.jpg

Kiddannos 22-06-2015 19:55

Scusate la domanda banale, ma i componenti che costi hanno? QUanto si arriva a spendere in totale?


Tutti gli orari sono GMT +2. Attualmente sono le 20:07.

Powered by vBulletin versione 3.8.9
Copyright ©: 2000 - 2024, Jelsoft Enterprises Ltd.
Traduzione italiana Team: AcquaPortal
User Alert System provided by Advanced User Tagging v3.2.5 Patch Level 2 (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Copyright Zero Pixel Srl

Page generated in 0,16228 seconds with 14 queries