Im having difficulties programming the code so that the two pushbuttons I have connected on the breadboard increment and decrements the setpoint temperature witch is my variable called x. Please help.
//Include Wire I2C Library
#include <Wire.h>
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(6, 7, 8, 9, 10, 11);
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 3; // the number of the pushbutton pin
float tempF; // create variable to store the temperature in.
int tempPin = 0; // Attach vout to analog pin 0.
int led = 13; // attach led to pin 13.
int fan1 = 12; // attach base of transistor to digital pin 9.
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
void setup() // Will execute once at the start of the code.
{
//Create a Wire Object
Wire.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode (led, OUTPUT); // sets the led pin 13 up as an output.
pinMode (fan1, OUTPUT); // sets the fan1 pin 9 up as an output.
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT); // initialize the pushbutton pin as an input:
}
void loop() // code here will continue to replay until powered off.
{
int x=75;
tempF = analogRead(tempPin); // read the analog value from the lm35 sensor.
tempF = (5.0 * tempF * 100.0)/1024.0; // convert the analog input to temperature in centigrade.
Serial.print((byte)tempF); // send the data to the computer.
lcd.setCursor(0,0);
lcd.print("ST:");
lcd.print(x);
lcd.setCursor(0,3);
lcd.print(tempF);
lcd.print(" F");
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == LOW) {
++x;
}
else if(buttonState2 == LOW) {
--x ;
}
if (tempF > x) // creates bool expression for analyzation. if it evaluates to true,
{ // the body of the if statement will execute.
digitalWrite (led, HIGH); // turns on led.
digitalWrite (fan1, HIGH); // turns on fan1.
}
else // if the if equation evaluates to false the else statement will execute.
{
digitalWrite (led, LOW); // turns off led.
digitalWrite (fan1, LOW); // turns off fan1.
}
delay(1000); // wait 3 seconds before redoing the loop.
}