|
| 1 | +#define THERM_PIN A0 |
| 2 | +#define SERVO_PIN 12 |
| 3 | +#define R_PIN 11 |
| 4 | +#define LED_PIN 9 |
| 5 | +#define G_PIN 6 |
| 6 | +#define B_PIN 5 |
| 7 | +#define RELAY_PIN 4 |
| 8 | +#define BTN_PIN 3 |
| 9 | +#define TACHO_PIN 2 |
| 10 | + |
| 11 | +#include <GyverOS.h> |
| 12 | +GyverOS<9> OS; |
| 13 | + |
| 14 | +#include <GyverNTC.h> |
| 15 | +GyverNTC therm(THERM_PIN, 10000, 3950); |
| 16 | +float thermAverage = 0; |
| 17 | + |
| 18 | +#include <Tachometer.h> |
| 19 | +Tachometer tacho; |
| 20 | + |
| 21 | +#include <microDS3231.h> |
| 22 | +MicroDS3231 rtc; |
| 23 | + |
| 24 | +#include <Servo.h> |
| 25 | +Servo servo; |
| 26 | + |
| 27 | +#include <LiquidCrystal_I2C.h> |
| 28 | +LiquidCrystal_I2C lcd(0x27, 16, 2); // адрес дисплея 0x3f или 0x27 |
| 29 | + |
| 30 | +#include <EncButton.h> |
| 31 | +EncButton<EB_TICK, BTN_PIN> btn(INPUT_PULLUP); |
| 32 | + |
| 33 | +#include <GRGB.h> |
| 34 | +GRGB led(COMMON_CATHODE, R_PIN, G_PIN, B_PIN); |
| 35 | + |
| 36 | +float thr = 30; |
| 37 | + |
| 38 | +void setup() { |
| 39 | + Serial.begin(9600); |
| 40 | + attachInterrupt(0, isr, FALLING); |
| 41 | + pinMode(RELAY_PIN, OUTPUT); |
| 42 | + pinMode(LED_PIN, OUTPUT); |
| 43 | + if (rtc.lostPower()) { // при потере питания |
| 44 | + rtc.setTime(COMPILE_TIME); // установить время компиляции |
| 45 | + } |
| 46 | + servo.attach(SERVO_PIN); |
| 47 | + |
| 48 | + lcd.init(); // инициализация |
| 49 | + lcd.backlight(); // включить подсветку |
| 50 | + |
| 51 | + OS.attach(0, task0, 80); |
| 52 | + OS.attach(1, task1, 500); |
| 53 | + OS.attach(2, task2, 1000); |
| 54 | + OS.attach(3, task3, 500); |
| 55 | + OS.attach(4, task4, 1000); |
| 56 | + OS.attach(5, task5, 1000); |
| 57 | + OS.attach(6, task6, 500); |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +void isr() { |
| 62 | + tacho.tick(); |
| 63 | +} |
| 64 | + |
| 65 | +void task0() { |
| 66 | + static float average = 0; |
| 67 | + static byte counter = 0; |
| 68 | + if (++counter >= 10) { |
| 69 | + counter = 0; |
| 70 | + thermAverage = average / 10.0; |
| 71 | + average = 0; |
| 72 | + } |
| 73 | + average += therm.getTempAverage(); |
| 74 | +} |
| 75 | + |
| 76 | +void task1() { |
| 77 | + Serial.print(thermAverage); |
| 78 | + Serial.print(','); |
| 79 | + Serial.println(tacho.getHz()); |
| 80 | +} |
| 81 | + |
| 82 | +void task2() { |
| 83 | + if (thermAverage >= thr) digitalWrite(RELAY_PIN, 1); |
| 84 | + else digitalWrite(RELAY_PIN, 0); |
| 85 | +} |
| 86 | + |
| 87 | +void task3() { |
| 88 | + digitalWrite(LED_PIN, !digitalRead(LED_PIN)); |
| 89 | +} |
| 90 | + |
| 91 | +void task4() { |
| 92 | + servo.write(map(rtc.getSeconds(), 0, 59, 0, 180)); |
| 93 | +} |
| 94 | + |
| 95 | +void task5() { |
| 96 | + lcd.home(); |
| 97 | + lcd.print(rtc.getTimeString()); |
| 98 | + lcd.setCursor(0, 1); |
| 99 | + lcd.print(thermAverage); |
| 100 | + lcd.print('('); |
| 101 | + lcd.print(thr); |
| 102 | + lcd.print(')'); |
| 103 | + lcd.print(' '); |
| 104 | + lcd.print(digitalRead(RELAY_PIN) ? "ON " : "OFF"); |
| 105 | +} |
| 106 | + |
| 107 | +void task6() { |
| 108 | + led.setWheel8(map(round(thermAverage), 25, 35, 80, 0)); |
| 109 | +} |
| 110 | + |
| 111 | +void loop() { |
| 112 | + OS.tick(); |
| 113 | + |
| 114 | + btn.tick(); |
| 115 | + if (btn.isClick()) { |
| 116 | + static bool flag = 0; |
| 117 | + if (flag) OS.stop(3); |
| 118 | + else OS.start(3); |
| 119 | + flag = !flag; |
| 120 | + } |
| 121 | + |
| 122 | + static float dir = 0.5; |
| 123 | + if (btn.isPress()) { |
| 124 | + dir = -dir; |
| 125 | + } |
| 126 | + |
| 127 | + if (btn.isStep()) { |
| 128 | + thr += dir; |
| 129 | + OS.exec(5); |
| 130 | + } |
| 131 | +} |
0 commit comments