arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

kylskap_fix.ino (2834B)


      1 #include <OLED_I2C.h>
      2 #include <SimpleDHT.h>
      3 
      4 // for DHT11, 
      5 //      VCC: 5V or 3V
      6 //      GND: GND
      7 //      DATA: 2
      8 int pinDHT11 = 2;
      9 SimpleDHT11 dht11(pinDHT11);
     10 
     11 
     12 OLED  myOLED(SDA, SCL, 8);
     13 
     14 extern uint8_t SmallFont[];
     15 long startTime = millis();
     16 //cooking time 20 min
     17 long setTimeMinutes = 30;
     18 long setTime = 0;
     19 long cookingTime = millis();
     20 long cookingTimeLeft = millis();
     21 int minutes;
     22 int seconds;
     23 boolean StartTimer = true;
     24 //15 psi == 3.0
     25 float voltageSet = 3.0;
     26 
     27 
     28 /*
     29   ReadAnalogVoltage
     30 
     31   Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
     32   Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
     33   Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
     34 
     35   This example code is in the public domain.
     36 
     37   http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
     38 */
     39 boolean relay_on = false;
     40 
     41 // the setup routine runs once when you press reset:
     42 void setup() {
     43   // initialize serial communication at 9600 bits per second:
     44   Serial.begin(9600);
     45   pinMode(8, OUTPUT);
     46   pinMode(7, INPUT_PULLUP); //knapp 1
     47   pinMode(9, INPUT_PULLUP); //knapp 3  
     48   pinMode(10, INPUT_PULLUP); //knapp 4
     49   relay_on = false;
     50   myOLED.begin();
     51   myOLED.setFont(SmallFont);
     52 }
     53 
     54 // the loop routine runs over and over again forever:
     55 void loop() {
     56 
     57   myOLED.clrScr();
     58   myOLED.print("Pressure: " + String(voltage), LEFT, 0);
     59   if (voltage < (voltageSet - 0.25) && cookingTimeLeft > 0) {
     60     myOLED.print("Heating up... ", LEFT, 16);
     61   }
     62   else if (cookingTimeLeft < 0) {
     63     myOLED.print("Set timer: " + String(setTimeMinutes) + "m", LEFT, 16);
     64   }
     65   else {
     66     cookingTime = millis() - startTime;
     67     cookingTimeLeft = setTime - cookingTime;
     68     minutes = (cookingTimeLeft / 1000)  / 60;
     69     seconds = (int)((cookingTimeLeft / 1000) % 60);
     70     myOLED.print("CookingTime: " + String(minutes) + "m " + String(seconds) + "s", LEFT, 16);
     71     myOLED.print(String(cookingTimeLeft), LEFT, 32);
     72   }
     73   
     74   myOLED.update();
     75   delay (100);
     76 
     77   if (voltage > voltageSet){
     78     if (relay_on == true){
     79       digitalWrite(8, HIGH); //relay
     80       relay_on = false;
     81     }
     82   }
     83   if (cookingTimeLeft < 0) {
     84     digitalWrite(8, HIGH); //relay
     85     relay_on = false;
     86   }
     87   if (cookingTimeLeft > 0) {
     88     if (voltage < (voltageSet - 0.2)){
     89       if (relay_on == false){
     90         digitalWrite(8, LOW); //relay
     91         relay_on = true;
     92       }
     93     }
     94   }
     95   if (digitalRead(7) == LOW){
     96      setTimeMinutes += 1;
     97      delay (100);
     98   }
     99   if (digitalRead(9) == LOW){
    100      setTimeMinutes -= 1;
    101      delay (100);
    102   }
    103   if (digitalRead(10) == LOW){
    104      startTime = millis();
    105      setTime = setTimeMinutes * 60 * 1000;
    106      cookingTime = millis() - startTime;
    107      cookingTimeLeft = setTime - cookingTime;
    108   }
    109   // print out the value you read:
    110   Serial.println(voltage);
    111 }