Guest User

Untitled

a guest
Dec 13th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <EEPROM.h>
  2.  
  3. const int buttonPin = 12; // the number of the pushbutton pin
  4. const int ledPin = 13; // the number of the LED pin
  5. const int temperaturePin = A0;
  6.  
  7. float minTemp, maxTemp; // Variables to store min and max temperature
  8.  
  9. int buttonState = 0; // variable for reading the pushbutton status
  10.  
  11. void setup() {
  12. // put your setup code here, to run once:
  13. Serial.begin(9600);
  14. pinMode(buttonPin, INPUT_PULLUP);
  15. pinMode(ledPin, OUTPUT);
  16. EEPROM.put(0, 25);
  17. EEPROM.put(8, 25);
  18. minTemp = 100.00;
  19. maxTemp = -100.00;
  20. printTemp();
  21. }
  22.  
  23. void loop() {
  24. // put your main code here, to run repeatedly:
  25. // read the state of the pushbutton value:
  26. buttonState = digitalRead(buttonPin);
  27.  
  28. saveReadings();
  29.  
  30. // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  31. if (buttonState == LOW) {
  32. // turn LED on:
  33. digitalWrite(ledPin, HIGH);
  34. printTemp();
  35. } else {
  36. // turn LED off:
  37. digitalWrite(ledPin, LOW);
  38. }
  39. }
  40.  
  41. void printTemp() {
  42. float storedMinTemp, storedMaxTemp;
  43. EEPROM.get(0, storedMinTemp);
  44. EEPROM.get(8, storedMaxTemp);
  45. Serial.print("Min: ");
  46. Serial.print(storedMinTemp);
  47. Serial.print(" Max: ");
  48. Serial.println(storedMaxTemp);
  49. delay(200);
  50. }
  51.  
  52. void saveReadings() {
  53.  
  54. float voltage, degreesC, degreesF; //Declare 3 floating point variables
  55. voltage = getVoltage(temperaturePin); //Measure the voltage at the analog pin
  56. degreesC = (voltage - 0.5) * 100.0; // Convert the voltage to degrees Celsius
  57.  
  58. if (degreesC < minTemp) { // minThreshold was initialized to 1023 -- so, if it's less, reset the threshold level.
  59. minTemp = degreesC;
  60. }
  61.  
  62. if (degreesC > maxTemp) { // maxThreshold was initialized to 0 -- so, if it's bigger, reset the threshold level.
  63. maxTemp = degreesC;
  64. }
  65.  
  66. EEPROM.put(0, minTemp);
  67. EEPROM.put(8, maxTemp);
  68.  
  69. }
  70.  
  71. //Function to read and return
  72. //floating-point value (true voltage)
  73. //on analog pin
  74.  
  75. float getVoltage(int pin) {
  76.  
  77. return (analogRead(pin) * 0.004882814);
  78. // This equation converts the 0 to 1023 value that analogRead()
  79. // returns, into a 0.0 to 5.0 value that is the true voltage
  80. // being read at that pin.
  81. }
Add Comment
Please, Sign In to add comment