Hallo an Alle,
ich bin neu hier und auch noch relativ neu bei der Programierung des Arduino. Ich habe schon die Beispielprojekte erfolgreich durchprobiert und möchte mich jetzt an ein größeres Projekt wagen und benötige Hilfe von erfahrnen Programmierern
Ich möchte mir mit oben genannter Hardware ein Temperaturlogger bauen (so ist das Ziel).
Da ich aber das Teil nicht so häufig benutzen werde, möchte ich kein Realtimeshield verwenden, sondern beim starten, einmal die aktuelle Uhrzeit und Datum per Tasten eingeben. Wenn das erfolgt ist, sollen die Daten intern weiterlaufen (für die Speicherung auf SD Karte) das Display gelöscht werden und mir dann die Werte der Temperatursensoren angezeit werden.
Soweit soll der erste Schritt sein. Ich habe auch schon einen Sketch der "fast" das so macht wie ich es möchte, aber eben nur fast. Ich kann die Uhrzeit und das Datum einstellen, doch es bleibt immer auf der Anzeige zu sehen. Dadurch bekomme ich nur 2 Werte der Temperatursensoren noch angezeigt, da mir der Platz auf der Anzeige fehlt. ICh möchte aber 4 Sensoren anzeigen.
Bitte schaut auch mal meinen Sketch an und gebt mir Hilfe bei der Umsetzung meines Vorhabens. Ich danke schon mal im Voraus für Euche tatkräftige Unterstützung.
/******************************************************************
* Clock and clock adjust demo by "jurs" for German Arduino Forum *
* Hardware required: keypad shield
* Additional library required: Time library must be installed
******************************************************************/
#include <LiquidCrystal.h>
#include <Time.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
// Select the pins used on the LCD panel:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Define some values used by the LCD panel and buttons:
enum keypadButtons {btnNONE, btnSELECT, btnLEFT, btnRIGHT, btnDOWN, btnUP };
enum menuStates {menuNONE, menuTIME, menuDATE, menuYEAR};
int readPadButtons()
// read the buttons from analog interface:
// returns the key currently pressed
// do not call this function directly from the sketch!
{
int adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
#define DEBOUNCETIME 10
int buttonPressed()
// this function returns true only once per single button pressed
// use this function in your program sketch
{
static boolean buttonFired;
static long buttonDownSince;
int State=readPadButtons();
if (State==btnNONE)
{ // this button is not pressed at this time
buttonFired=false;
buttonDownSince=0;
}
else if (buttonDownSince==0)
{ // button is pressed but DEBOUNCETIME did not yet started counting
buttonFired=false;
buttonDownSince=millis();
}
if (millis()-buttonDownSince>=DEBOUNCETIME && buttonFired==false)
{ // button is pressed and DEBOUNCETIME passed, so fire the button
buttonFired=true;
return(State); // return button
}
return(btnNONE); // no button fired this time
}
void setup()
{
Serial.begin(9600); // set serial interface to 9600 baud
lcd.begin(16, 2); // starts the LCD display (2 lines by 16 chars)
setTime(1357002000); // set some initial time
}
int menuState; // global variable to hold the menu status
void updateDisplay()
// this function updates the display (time and menu status)
{
char lcdline[17];
sprintf(lcdline,"%02d:%02d:%02d",hour(),minute(),second());
lcd.setCursor(0,0);
lcd.print(lcdline);
lcd.setCursor(0,1);
if (menuState==menuTIME)
lcd.print(F("Zeit einst"));
else if (menuState==menuDATE)
{
lcd.print(F("Dat:"));
sprintf(lcdline,"%02d.%02d. ",day(),month());
lcd.print(lcdline);
}
else if (menuState==menuYEAR)
{
lcd.print(F("J:"));
sprintf(lcdline,"%04d ",year());
lcd.print(lcdline);
}
else
// lcd.print(F("Normalbetrieb "));
printZiffernGenulltOhnePunkt(day());
lcd.print(".");
printZiffernGenulltOhnePunkt(month());
lcd.print(".");
// printZiffernGenulltOhnePunkt(year());
//lcd.print(".");
}
void checkForNewSecond()
// function will update the display once per second
{
static long lastsecond;
if (lastsecond!=now())
{
updateDisplay();
lastsecond=now();
}
}
void handleMenuTimeButton(int button)
// we are in time setting menu and react on pressed button
// by changing the time
{
switch (button)
{
case btnRIGHT:
{
setTime(now()+3600);
break;
}
case btnLEFT:
{
setTime(now()-3600);
break;
}
case btnUP:
{
setTime(now()+60);
break;
}
case btnDOWN:
{
setTime(now()-60);
break;
}
}
}
void handleMenuDateButton(int button)
// we are in time setting menu and react on pressed button
// by changing the time
{
switch (button)
{
case btnRIGHT:
{
setTime(hour(),minute(),second(),day(),month()+1,year());
break;
}
case btnLEFT:
{
setTime(hour(),minute(),second(),day(),month()-1,year());
break;
}
case btnUP:
{
setTime(hour(),minute(),second(),day()+1,month(),year());
break;
}
case btnDOWN:
{
setTime(hour(),minute(),second(),day()-1,month(),year());
break;
}
}
}
void handleMenuYearButton(int button)
// we are in time setting menu and react on pressed button
// by changing the time
{
switch (button)
{
case btnRIGHT:
case btnUP:
{
if (year()<2038)
setTime(hour(),minute(),second(),day(),month(),year()+1);
break;
}
case btnLEFT:
case btnDOWN:
{
if (year()>2000)
setTime(hour(),minute(),second(),day(),month(),year()-1);
break;
}
}
}
void handleNormalButton(int button)
{
// nothing yet
}
void handleButtons()
// Abfrage ob eine Taste gedrückt wurde
// Umschaltung des Menüstatus
// Falls im Zeiteinstellmenü, Funktion zur Behandlung der Tasten im Einstellmenü aufrufen
// Falls im Normalbetrieb, Funktion zur Behandlung der Tasten im Normalbetrieb aufrufen
{
int curButton;
curButton=buttonPressed();
if (curButton==btnNONE) return; // nothing to do if no button is pressed
else if (curButton==btnSELECT) // switch menu status
{
if (menuState==menuNONE) menuState=menuTIME;
else if (menuState==menuTIME) menuState=menuDATE;
else if (menuState==menuDATE) menuState=menuYEAR;
else menuState=menuNONE;
}
else if (curButton!=btnNONE) // falls eine Taste gedrückt wurde
{
if (menuState==menuTIME) handleMenuTimeButton(curButton); // Zeit einstellen
else if (menuState==menuDATE) handleMenuDateButton(curButton); // Datum einstellen
else if (menuState==menuYEAR) handleMenuYearButton(curButton); // Jahr einstellen
else handleNormalButton(curButton); // gedrückte Tasten sonst behandeln
}
updateDisplay();
}
void printZiffernGenulltOhnePunkt(int zahl) // definieren Subroutine
{
// verschoenern Anzeige, indem wir ...
if(zahl < 10) // wenn kleiner als 10 ...
{
Serial.print("0"); // fuehrende 0 einfuegen
lcd.print("0"); // fuehrende 0 einfuegen
}
Serial.print(zahl); // Ausgabe auf serieller Konsole
lcd.print(zahl); // Ausgabe auf LCD
}
void printZiffernGenulltmitPunkt(int zahl) // definieren Subroutine
{
// verschoenern Anzeige, indem wir ...
Serial.print(":"); // trennende ":" einfuegen
lcd.print(":"); // trennende ":" einfuegen
if(zahl < 10) // wenn kleiner als 10 ...
{
Serial.print('0'); // fuehrende 0 einfuegen
lcd.print("0");
}
Serial.print(zahl); // Ausgabe auf serieller Konsole
lcd.print(zahl);
}
void loop()
{
sensors.requestTemperatures();
lcd.setCursor(11, 0);
//lcd.print("0: ");
lcd.print(sensors.getTempCByIndex(0));
// lcd.print("C");
lcd.setCursor(11, 1);
// lcd.print("1: ");
lcd.print(sensors.getTempCByIndex(1));
// lcd.print("C");
checkForNewSecond(); // einmal pro Sekunde das Display updaten
handleButtons();
}
[code/]
Ich würde mich freuen wenn mir jemand helfen kann.