Hey guys.
My goal is the same, as delis. I'm trying to build reef aquarium controler. I bought the Freduino and lcd keypad shield from nuelectronics.
MY goal is something like this:
When you turn it on, I would like to write on display:
Temp: xx°C TIME (time in 24h format
pH: xx DATE (dd.mm.yy)
For time, I will use Software Date Time library.
Then when you press menu button, you get:
1st level: < pH calibration > ; < temp > ; < Lights > ; <Pumps> ;
Your moving thrue menus with left or right button. If you press select, you run the program or go to sublevel:
2nd level : pH calibration: (run program for calibration)
temp: < low > ; < high1 > ; <high2>(if I press select button on low, then I can insert the low temperature -> when to turn on the heater (with relay switch); if i press select on high1, I can enter the temp, in which the heater is turned off; in high2, i enter the temperature, in whict the cooling ventilator is turned on )
lights: <manual switch>; <timers>; (I have four pairs of lights: in manual switch sublevel, there would bi option tu turn off or on those lights; in timers, there would be option to set the on and off time for every pair of lights)
pumps: <feeding mode>; <manual switch>; <water change> ; (feeding mode is a program, the shuts of the 2 main pumps for a few minutes; in manual switch sub level, there would be options for turning off or on all 5 pumps in the system; water change is a program, thet automatically turns of all 5 pumps, until i press the set button again)
I must say, I'm a beginner in elctronics and programing. So I started learning and found this great thread. Kiwix really did a great job on those menues. I also started to play with code for temperature.
I managed to print current temperature (dallas 1-wire sensor) and also for showing the temperature simultaneously on LCD screen:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 14, 9, 4, 5, 6, 7);
#include <stdio.h>
#define TEMP_PIN 3
//create object to control an LCD.
//number of lines in display=1
void getCurrentTemp(char *temp);
//Key message
int adc_key_val[5] ={30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
void setup() {
// initial lcd display while initialize and pc detection
lcd.clear();
lcd.print(" Reefino 0.0.t ");
delay(2000);
// initialize DS18B20 datapin
digitalWrite(TEMP_PIN, LOW);
pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1)
}
void loop() {
char temp_string[10];
adc_key_in = analogRead(0); // read the value from the sensor
{
delay(50); // wait for debounce time
adc_key_in = analogRead(0); // read the value from the sensor
{
getCurrentTemp(temp_string);
lcd.clear();
lcd.setCursor(0,1);
lcd.print(temp_string);
}
}
}
// Convert ADC value to key number
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
{
return k;
}
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed
return k;
}
void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500 us
delayMicroseconds(500);
pinMode(Pin, INPUT);
delayMicroseconds(500);
}
void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
byte n;
for(n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // test least sig bit
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(60);
}
else
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(60);
pinMode(Pin, INPUT);
}
d=d>>1; // now the next bit is in the least sig bit position.
}
}
byte OneWireInByte(int Pin) // read byte, least sig byte first
{
byte d, n, b;
for (n=0; n<8; n++)
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(5);
b = digitalRead(Pin);
delayMicroseconds(60);
d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
}
return(d);
}
void getCurrentTemp(char *temp)
{
int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0xbe);
LowByte = OneWireInByte(TEMP_PIN);
HighByte = OneWireInByte(TEMP_PIN);
TReading = (HighByte << 8) + LowByte;
sign = TReading & 0x8000; // test most sig bit
if (sign) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
whole = Tc_100 / 100; // separate off the whole and fractional portions
fract = Tc_100 % 100;
sprintf(temp, "%c%3d%c%2d", (sign==0)?'+':'-', whole, '.', fract);
}
When I tried to implement this code into kiwix code, all I did was fail

Would anybody be so nice and help me.
Thanky ou very much.
Best regards!