Min Max Werte von Temperatur im Menü ändern

Moinsen,

ich habe mir meine LED Steuerung bisher ordentlich zusammen gebaut. Alles dimmt hoch und runter, Temperatur wird auch schön niedrig gehalten, jedoch hätte ich noch gerne ein Extra eingefügt. Da ich nicht jedesmal den Quellcode ändern möchte, wäre es super, wenn ich die Min Max Werte innerhalb meines Menüs durch Tasten (Hoch, Runter, Enter) ändern könnte. Leider weiß ich nicht ansatzweise, wie dies zu realisieren ist. Ich finde ebenfalls keine passenden Stichwörter, welche mir bei google das richtige ausspucken.

Ich hänge mal einen meiner drei Tabs an (zu viel Code für das Forum):

/* =============================================== */
/* Example 1: LCD Menu with LiquidCrystal          */
/* =============================================== */
#define Tmin 20
#define Tmax 30
#include <Wire.h>
#include <LiquidCrystal.h>
#include <LCDMenuLib.h>
#include <Wire.h>
#include <PWM.h>

//Uhr Adresse
#define DS1307_ADDRESS 0x68

/* settings for lcd */
#define _LCDMenuLib_LCD_cols             20
#define _LCDMenuLib_LCD_rows             4

/* pin settings */
#define _LCDMenuLib_LCD_rs               13
#define _LCDMenuLib_LCD_e                12
#define _LCDMenuLib_LCD_dat0             8
#define _LCDMenuLib_LCD_dat1             7
#define _LCDMenuLib_LCD_dat2             4
#define _LCDMenuLib_LCD_dat3             5 

/* lib config */
#define _LCDMenuLib_cfg_initscreen       0       /* 0=disable, 1=enable */
#define _LCDMenuLib_cfg_initscreen_time  60000   /* 0=time disabled, >0 wait time in ms */
#define _LCDMenuLib_cfg_scrollbar	 1       /* 0=no scrollbar, 1=complex scrollbar, 2=easy scrollbar */
#define _LCDMenuLib_cfg_lcd_standard	 0       /* 0=HD44780 standard / 1=HD44780U standard */
#define _LCDMenuLib_cfg_press_time       200    /* button press time in ms */

/* menu element count - last element id */
#define _LCDMenuLib_cnt    7
int32_t frequency = 32000;
/* init lcdmenulib */
LCDMenuLib_init(_LCDMenuLib_cnt);

//HD44780U (LCD-II)Oktal-Codes für Umlaute:
//ö =  \357
//ä =  \341
//ü =  \365
//ß =  \342

/* create lcdmenulib */
/* Item           => layer 0 */
/* Item_XX        => layer 1 */
/* Item_XX_XX     => layer 2 */
/* Item_XX_XX_XX  => layer 3 */
/* LCDMenuLib_element(id, prev_layer_element, current_layer_element, lang_string, callback_function) */
LCDMenuLib_element(0  , Item         , Item_1        , "Information"        , FUNC_information);
LCDMenuLib_element(1  , Item         , Item_2        , "Zeit"               , FUNC_zeit);
LCDMenuLib_element(2  , Item         , Item_3        , "Licht"              , FUNC_licht);
/*LCDMenuLib_element(3  , Item_3       , Item_3_1      , "LED Weiss"          , FUNC);
 LCDMenuLib_element(4  , Item_3       , Item_3_2      , "LED Blau"           , FUNC);
 LCDMenuLib_element(5  , Item_3       , Item_3_3      , "LED UV"             , FUNC);
 LCDMenuLib_element(6  , Item_3       , Item_3_4      , "LED Gr\365n"        , FUNC);
 LCDMenuLib_element(7  , Item_3       , Item_3_5      , "LED Rot"            , FUNC);
 LCDMenuLib_element(4  , Item_3       , Item_3_6      , "zur\365ck"          , FUNC_back);*/
LCDMenuLib_element(3  , Item         , Item_4        , "Einstellungen"      , FUNC);
LCDMenuLib_element(4 , Item_4       , Item_4_1      , "Temperatur"         , FUNC_temperatur);
LCDMenuLib_element(5 , Item_4       , Item_4_2      , "L\365fter"          , FUNC_luefter);
LCDMenuLib_element(6 , Item_4       , Item_4_3      , "Tmin, Tmax"         , FUNC);
LCDMenuLib_element(7 , Item_4       , Item_4_4      , "zur\365ck"          , FUNC_back);

LCDMenuLib_createMenu(_LCDMenuLib_cnt);

//******************************************************************************************+

int temp1;
int temp2;
int fan1 = 9;
//int fan2 = 10;
const int whitePin = 11;
const int bluePin = 10;
//const int greenPin = 6;
//const int redPin = 10;
//const int uvPin = 5;
const unsigned long HOUR = 60 * 60;
const unsigned long MINUTE = 60;
const int TARGET_BRIGHTNESS = 255;


//******************************************************************************************+
void setup()
{    
  LCDMenuLib_setup(_LCDMenuLib_cnt);  /* Setup for LcdMenuLib */
  Serial.begin(9600);                 /* start serial */

  pinMode(fan1, OUTPUT);


  Wire.begin();
}

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

void loop()
{  
  //LCDMenuLib_control_analog();      /* lcd menu control - config in tab "LCDML_control" */
  LCDMenuLib_control_digital();     /* lcd menu control - config in tab "LCDML_control" */

  //LCDMenuLib_control_serial();        /* lcd menu control */  
  LCDMenuLib_loop();                  /* lcd function call */
  //***************************************************************************************************************************
  InitTimersSafe();
  bool succes = SetPinFrequencySafe(9, frequency);
  //***************************************************************************************************************************
  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);   //****************************************** 24h Zeit


  unsigned long time = RTCHour * HOUR + RTCMinute * MINUTE + RTCSecond;


  //************************************************************************************************* Uhrzeit zeigt den Beginn der Dimmung an!
  analogWrite(whitePin,   brightness(time, 10*HOUR, 15*HOUR+53*MINUTE));
  analogWrite(bluePin,    brightness(time, 8*HOUR+30*MINUTE, 12*HOUR+30*MINUTE));
  //analogWrite(greenPin,   brightness(time, 9*HOUR, 17*HOUR));
  //analogWrite(redPin,     brightness(time, 9*HOUR, 17*HOUR+10*MINUTE));
  //analogWrite(uvPin,      brightness(time, 9*HOUR, 17*HOUR));

  temp1 = ((5.0*analogRead(A3)*100.0)/1024);        //Analog 3 für temp1
  temp2 = ((5.0*analogRead(A2)*100.0)/1024);        //Analog 2 für temp2
  fan1 = map(temp1, Tmin, Tmax, 0, 255);    // Tmin->0%/0 // Tmax->100%/255
  if (fan1<25)   fan1 = 0;
  if (fan1>255) fan1 = 255;


  analogWrite(9, fan1);

}

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

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

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

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

Über einen kleinen Tipp oder Hinweis wäre ich euch dankbar!

Grüße,

Jan

Klar kannst du das machen. Ist die Frage wie viel Aufwand du betreiben willst. z.B einen Schalter und einen Taster. Mit der Schalterstellung wählst du Min oder Max aus. Mit jedem Tasterdruck addierst du 1 zu deiner Temperatur bis zu einem Endwert, dann fängt es wieder bei Null oder wo auch immer an. Mit zwei Tastern könntest du +1 oder -1 addieren, wäre etwas komfortabler. Wie gesagt, wie viel Aufwand willst du treiben. gruß

Einfach mal so als Pseudo Code:

void changeTemp(){
  nurBeimErstenAufruf{
    Menueinhalt schreiben
    setCursor.
  }
  if (TasteIncrement){
   Temp++;
   setCursor
   lcd.print(Temp);
  }  
  if (TasteDecrement){
   Temp--;
   setCursor
   lcd.print(Temp);
  }
  if (TasteEnde){
    Hauptmenue;
  }
}