Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- const int buttonPin = 12; // the number of the pushbutton pin
- const int ledPin = 13; // the number of the LED pin
- const int temperaturePin = A0;
- float minTemp, maxTemp; // Variables to store min and max temperature
- int buttonState = 0; // variable for reading the pushbutton status
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(buttonPin, INPUT_PULLUP);
- pinMode(ledPin, OUTPUT);
- EEPROM.put(0, 25);
- EEPROM.put(8, 25);
- minTemp = 100.00;
- maxTemp = -100.00;
- printTemp();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- // read the state of the pushbutton value:
- buttonState = digitalRead(buttonPin);
- saveReadings();
- // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
- if (buttonState == LOW) {
- // turn LED on:
- digitalWrite(ledPin, HIGH);
- printTemp();
- } else {
- // turn LED off:
- digitalWrite(ledPin, LOW);
- }
- }
- void printTemp() {
- float storedMinTemp, storedMaxTemp;
- EEPROM.get(0, storedMinTemp);
- EEPROM.get(8, storedMaxTemp);
- Serial.print("Min: ");
- Serial.print(storedMinTemp);
- Serial.print(" Max: ");
- Serial.println(storedMaxTemp);
- delay(200);
- }
- void saveReadings() {
- float voltage, degreesC, degreesF; //Declare 3 floating point variables
- voltage = getVoltage(temperaturePin); //Measure the voltage at the analog pin
- degreesC = (voltage - 0.5) * 100.0; // Convert the voltage to degrees Celsius
- if (degreesC < minTemp) { // minThreshold was initialized to 1023 -- so, if it's less, reset the threshold level.
- minTemp = degreesC;
- }
- if (degreesC > maxTemp) { // maxThreshold was initialized to 0 -- so, if it's bigger, reset the threshold level.
- maxTemp = degreesC;
- }
- EEPROM.put(0, minTemp);
- EEPROM.put(8, maxTemp);
- }
- //Function to read and return
- //floating-point value (true voltage)
- //on analog pin
- float getVoltage(int pin) {
- return (analogRead(pin) * 0.004882814);
- // This equation converts the 0 to 1023 value that analogRead()
- // returns, into a 0.0 to 5.0 value that is the true voltage
- // being read at that pin.
- }
Add Comment
Please, Sign In to add comment