commit e2b727d37cb3a896202d95241420a516bbed6d7e
Author: Robin <rob@tarina.org>
Date: Wed, 7 Sep 2022 16:28:25 +0300
first
Diffstat:
A | tryckkastruln.ino | | | 104 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 104 insertions(+), 0 deletions(-)
diff --git a/tryckkastruln.ino b/tryckkastruln.ino
@@ -0,0 +1,104 @@
+#include <OLED_I2C.h>
+
+OLED myOLED(SDA, SCL, 8);
+
+extern uint8_t SmallFont[];
+long startTime = millis();
+//cooking time 20 min
+long setTimeMinutes = 30;
+long setTime = 0;
+long cookingTime = millis();
+long cookingTimeLeft = millis();
+int minutes;
+int seconds;
+boolean StartTimer = true;
+//15 psi == 3.0
+float voltageSet = 3.0;
+
+/*
+ ReadAnalogVoltage
+
+ Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
+ Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
+ Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
+
+ This example code is in the public domain.
+
+ http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
+*/
+boolean relay_on = false;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize serial communication at 9600 bits per second:
+ Serial.begin(9600);
+ pinMode(8, OUTPUT);
+ pinMode(7, INPUT_PULLUP); //knapp 1
+ pinMode(9, INPUT_PULLUP); //knapp 3
+ pinMode(10, INPUT_PULLUP); //knapp 4
+ relay_on = false;
+ myOLED.begin();
+ myOLED.setFont(SmallFont);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ // read the input on analog pin 0:
+ int sensorValue = analogRead(A0);
+ // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
+ float voltage = sensorValue * (5.0 / 1023.0);
+ myOLED.clrScr();
+ myOLED.print("Pressure: " + String(voltage), LEFT, 0);
+ if (voltage < (voltageSet - 0.25) && cookingTimeLeft > 0) {
+ myOLED.print("Heating up... ", LEFT, 16);
+ }
+ else if (cookingTimeLeft < 0) {
+ myOLED.print("Set timer: " + String(setTimeMinutes) + "m", LEFT, 16);
+ }
+ else {
+ cookingTime = millis() - startTime;
+ cookingTimeLeft = setTime - cookingTime;
+ minutes = (cookingTimeLeft / 1000) / 60;
+ seconds = (int)((cookingTimeLeft / 1000) % 60);
+ myOLED.print("CookingTime: " + String(minutes) + "m " + String(seconds) + "s", LEFT, 16);
+ myOLED.print(String(cookingTimeLeft), LEFT, 32);
+ }
+
+ myOLED.update();
+ delay (100);
+
+ if (voltage > voltageSet){
+ if (relay_on == true){
+ digitalWrite(8, HIGH); //relay
+ relay_on = false;
+ }
+ }
+ if (cookingTimeLeft < 0) {
+ digitalWrite(8, HIGH); //relay
+ relay_on = false;
+ }
+ if (cookingTimeLeft > 0) {
+ if (voltage < (voltageSet - 0.2)){
+ if (relay_on == false){
+ digitalWrite(8, LOW); //relay
+ relay_on = true;
+ }
+ }
+ }
+ if (digitalRead(7) == LOW){
+ setTimeMinutes += 1;
+ delay (100);
+ }
+ if (digitalRead(9) == LOW){
+ setTimeMinutes -= 1;
+ delay (100);
+ }
+ if (digitalRead(10) == LOW){
+ startTime = millis();
+ setTime = setTimeMinutes * 60 * 1000;
+ cookingTime = millis() - startTime;
+ cookingTimeLeft = setTime - cookingTime;
+ }
+ // print out the value you read:
+ Serial.println(voltage);
+}