tryckkastruln

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

tryckkastruln.ino (2893B)


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