The three values time1, humidity, temperature in the void timebase cannot be used to sub into the void loop. I used them for limits for the void loop, but it doesn't work.
This is my code, words in // // can be ignored
#include <MsTimer2.h>
// Arduino Playground - MsTimer2
#include <SoftwareSerial.h>
#define txPin 1
#define heater 10
#define fan 11 // fan connected to PWM pin 9
#define motor 12 // motor connected to PWM pin 10
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only
int time1=30;
int temperature=60;
int humidity=60;
const int LCDdelay=2; // minimum 2, increase if LCD is unstable
int ms200 = 0, seconds = 0, minutes = 0;
// to store the time
boolean right = 0, up = 0, left = 0, down = 0, ok = 0, humi=0, humi2=0, reset=0;
boolean rightReleased = 1, upReleased = 1, leftReleased = 1, downReleased
= 1, okReleased = 1, humireleased=0, humireleased2=0, resetreleased=0;
// to store the status of the 5 buttons
void clearLCD(){
LCD.write(0xFE); //command flag
LCD.write(0x51); //clear command.
delay(LCDdelay);
}
void serCommand() { //a general function to call the command flag for
LCD.write(0xFE);
}
void backlite(char x){
LCD.write(0xFE);
LCD.write(0x53);
LCD.write(x);
delay(1);
}
void timebase() {
// this function is called the Interrupt Service Routine (ISR)
// It executes every 0.2 seconds, triggered by Timer2 interrupt
ms200++;
if (ms200 > 4){
seconds++;
ms200 = 0;
if (seconds > 59){
minutes++;
seconds = 0;
}
} // increments the time in minutes, seconds and 0.2 seconds
// put code to read buttons and sensors here,
// be sure to debounce, cater for press and hold,
// press and repeat, etc.
if (digitalRead(2)){ //if right button is not pressed (active low)
right = 0;
rightReleased = 1;
}
else{ // if right button is pressed
if (rightReleased){ // if the button is previously released
right = 1;
rightReleased = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(3)){ //if ok button is not pressed (active low)
ok = 0;
okReleased = 1;
}
else{
if (okReleased){ // if the button is previously released
ok = 1;
okReleased = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(4)){ //if up button is not pressed (active low)
up = 0;
upReleased = 1;
}
else{
if (upReleased){ // if the button is previously released
up = 1;
upReleased = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(5)){ //if down button is not pressed (active low)
down = 0;
downReleased = 1;
}
else{
if (downReleased){ // if the button is previously released
down = 1;
downReleased = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(7)){ //if down button is not pressed (active low)
humi = 0;
humireleased = 1;
}
else{
if (humireleased){ // if the button is previously released
humi = 1;
humireleased = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(8)){ //if down button is not pressed (active low)
humi2 = 0;
humireleased2 = 1;
}
else{
if (humireleased2){ // if the button is previously released
humi2 = 1;
humireleased2 = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(9)){ //if down button is not pressed (active low)
reset = 0;
resetreleased = 1;
}
else{
if (resetreleased){ // if the button is previously released
reset = 1;
resetreleased = 0; // so that it does not repeat if press & hold
}
}
if (digitalRead(6)){ //if left button is not pressed (active low)
left = 0;
leftReleased = 1;
}
else{
if (leftReleased){ // if the button is previously released
left = 1;
leftReleased = 0; // so that it does not repeat if press & hold
}
}
// put code to refresh the LCD or indicator lights here, e.g.:
clearLCD();
delay(LCDdelay);
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(5);
LCD.print("Time");
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(10);
LCD.print("Temp");
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(15);
LCD.print("Humi");
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(46);
LCD.print(time1);
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(51);
LCD.print(temperature);
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(56);
LCD.print(humidity);
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(89);
LCD.print("min");
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(95);
LCD.print("C");
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(100);
LCD.print("%");
if (right){
//Change Cursor position to Line 2 column 13
temperature=temperature-1;
}
if (ok){temperature=temperature+1;
//Change Cursor position to Line 2 column 10
//LCD.write(0xFE);
//LCD.write(0x45);
//LCD.write(49);
//LCD.print("OK");
//delay(LCDdelay);
}
if (up){
time1=time1+5;
}
if (down){
time1=time1-5;
}
if(humi){
humidity=humidity-1;
}
if(humi2){
humidity=humidity+1;
}
if(reset){
time1=30;
temperature=60;
humidity=60;
}
if (left){
//Change Cursor position to Line 2 column 4
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(40);
LCD.print("START");
}
}
void setup() {
// put the various setup code here
pinMode(txPin, OUTPUT);
pinMode(2, INPUT_PULLUP); // right button
pinMode(3, INPUT_PULLUP); // ok button
pinMode(4, INPUT_PULLUP); // up button
pinMode(5, INPUT_PULLUP); // down button
pinMode(6, INPUT_PULLUP); // left button
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
//Set Arduino serial baud rate to 9600kbps
LCD.begin(9600);
//If LCD is not responding correctly,
//try other baud rates: 300,1200,2400,14400,19200,57600,115200
backlite(2); // acceptable values 1 to 8
//Show LCD's baud rate
LCD.write(0xFE);
LCD.write(0x71);
delay(LCDdelay);
delay(1000);
//Change Cursor position to line 1 column 1
LCD.write(0xFE);
LCD.write(0x45);
LCD.write(0x40);
LCD.print("Newhaven Display");
delay(LCDdelay);
delay(1000);
// Timer2 interrupt every 0.2 seconds
MsTimer2::set(200, timebase);
// run the interrupt service routine (ISR) timebase()
// every 200 milliseconds
MsTimer2::start(); // start the ISR
}
void loop() {
if(left){
for (int fadeValue = 0 ; fadeValue <= humidity; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(fan, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
for (int fadeValue = 0 ; fadeValue <= time1; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(motor, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
digitalWrite(heater, HIGH);
delay(5000);
digitalWrite(heater, LOW);
// fade out from max to min in increments of 5 points:
for (int fadeValue = time1 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(motor, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = humidity ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(fan, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
delay(5000);}
}