Så, vi er kommet lengre i prosessen, og jeg plages med koden til Arduinoen. Mye er på plass, men problemet kommer når jeg skal bruke keypad til å velge en forhåndsprogrammert oppskrift. Jeg vil at programmet da skal kunne stegmeske, altså sjekke en temperatursensor og skru av/på varme dersom den ligger innenfor riktig temperatur. Etter en viss tid skal temperaturgrensen endres og holdes en viss tid, før den endres igjen. Problemet slik koden er nå, er at er at den sjekker temperaturen bare en gang, før den går tilbake til "velg program fra lista"-beskjeden på LCD. Er det noen Arduino-/C-kyndige som har gode råd om hvordan jeg kan få den til å repetere dette if-utsagnet i et forhåndsvalgt tidsintervall?
#include <Keypad.h>
#include <LiquidCrystal.h> //includes libraries for hardware
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 //datacable for temp.sensor on digital pin 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); //send oneWire-reference to Dallas Temperature
float step1Temp;
unsigned long step1Time;
float step2Temp;
unsigned long step2Time;
float step3Temp; // defining the different steps (if several) in the mashing-process as decimals (temperature) and integers (time).
unsigned long step3Time; // values will be defined later in the program, depending on which recipe is chosen by pressing a key on a keypad
float step4Temp; // keypad has 12 keys - potentially 12 preset recipes
unsigned long step4Time; // new recipes requires altering of program (replacing existing recipe)
float step5Temp;
unsigned long step5Time;
float tempInC = sensors.getTempCByIndex(0); //simplified name for comparing temperature
LiquidCrystal lcd(13, 14, 15, 16, 17, 18); //digital pins for LCD
const byte ROWS = 4; //Keypad has 4 rows
const byte COLS = 3; //keypad has 3 columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'}, //defining keypad structure
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = { 9, 8, 7, 6 }; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //constructing keypad
const int onLed = 3; //LED on digital pin 3. this LED will light up when the heater is on
const int offLed = 4; //LED on digital pin 4. this LED will light up when the heater is off
const int relayPin = 5; //relay for switching power to heater on digital pin 5
void setup() {
sensors.begin();
lcd.begin(16,2);
lcd.println("Velkommen til"); //welcome message printed on LCD
lcd.print("GL bryggerier");
delay(6000); //wait 6 seconds - for brewers to enjoy message
}
void loop() {
lcd.println("Velg program fra"); //instructs brewer to chose program by pressing a single key on keypad
lcd.println("lista. 0-9"); //numbers 0-9 will match beer names on a written list on the wall
char key = kpd.getKey(); //requesting key input
if(key == '1'){
lcd.println("Du har valgt:"); //LCD informs you what type of beer you have chosen
lcd.print("India Pale Ale"); //'1' is a preset IPA recipe
step1Temp = 74;
step1Time = 1800000;
step2Temp = 70;
step2Time = 1000000;
step3Temp = 67; //temperature and time values are set according to a IPA recipe
step3Time = 700000; //these are just random values for the example
//step4Temp = ;
//step4Time = ;
//step5Temp = ;
//step5Time = ;
delay(6000); //wait 6 seconds so you can read about the choice
sensors.requestTemperatures(); //command to receive temperature reading
sensors.getTempCByIndex(0); //sends temperature in degrees Celsius
//initiating step 1
if (tempInC < step1Temp)
{ digitalWrite (relayPin, HIGH); //if temperature is under preset limit, relay/heater goes on
digitalWrite (onLed, HIGH); //if temperature is under preset limit, red LED goes on.
digitalWrite (offLed, LOW);
lcd.println("Temperatur:");
lcd.print(tempInC); //LCD prints temperature
lcd.setCursor(1,6);
lcd.print("Celsius");
}
else
{
digitalWrite (relayPin, LOW); //heater off
digitalWrite (offLed, HIGH); //white LED on, indicates heater off
digitalWrite (onLed, LOW);
lcd.println("Temperatur:");
lcd.print(tempInC); //LCD prints temperature
lcd.setCursor(1,6);
lcd.print("Celsius");
}
//initiating step 2
if (tempInC < step2Temp)
{ digitalWrite (relayPin, HIGH); //if temperature is under preset limit, relay/heater goes on
digitalWrite (onLed, HIGH); //if temperature is under preset limit, red LED goes on.
digitalWrite (offLed, LOW);
lcd.println("Temperatur:");
lcd.print(tempInC); //LCD prints temperature
lcd.setCursor(1,6);
lcd.print("Celsius");
}
else
{
digitalWrite (relayPin, LOW); //heater off
digitalWrite (offLed, HIGH); //white LED on, indicates heater off
digitalWrite (onLed, LOW);
lcd.println("Temperatur:");
lcd.print(tempInC); //LCD prints temperature
lcd.setCursor(1,6);
lcd.print("Celsius");
}
//initiating step 3
if (tempInC < step3Temp)
{ digitalWrite (relayPin, HIGH); //if temperature is under preset limit, relay/heater goes on
digitalWrite (onLed, HIGH); //if temperature is under preset limit, red LED goes on.
digitalWrite (offLed, LOW);
lcd.println("Temperatur:");
lcd.print(tempInC); //LCD prints temperature
lcd.setCursor(1,6);
lcd.print("Celsius");
}
else
{
digitalWrite (relayPin, LOW); //heater off
digitalWrite (offLed, HIGH); //white LED on, indicates heater off
digitalWrite (onLed, LOW);
lcd.println("Temperatur:");
lcd.print(tempInC); //LCD prints temperature
lcd.setCursor(1,6);
lcd.print("Celsius");
}
}
}