max6675 + энкодер
- Войдите на сайт для отправки комментариев
Вс, 22/05/2016 - 17:17
Здравствуйте!!! Использую для управления энкодер с RotaryEncoder.h все прекрастно работает, но стоит вывести на lcd температуру с max6675 энкодер тормозит
// Загрузка ЖК - библиотека и кодер #include <LiquidCrystal.h> #include <RotaryEncoder.h> #include "max6675.h" int thermoDO = 10; //он же SO int thermoCS = 9; int thermoCLK = 8; //он же SCK MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO); // Инициализировать LCD LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // штырьки кодировщика RotaryEncoder encoder(A0, A1); int buttonPin = A2; int result = 1; long lcdUpdate; void setup() { // put your setup code here, to run once: lcd.begin(20, 4); lcd.setCursor(0, 0); lcd.print(""); digitalWrite(buttonPin, HIGH); } //setup() void loop() { //Выводим температуру на lcd // lcd.setCursor (1, 1); // lcd.print(thermocouple.readCelsius()); // delay(300); static int pos = 0; encoder.tick(); int newPos = encoder.getPosition(); if (pos < newPos) result++; if (pos > newPos) result--; if (result > 5) result = 1; if (result < 1) result = 5; if (pos != newPos) pos = newPos; if (millis() - lcdUpdate >= 100) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Please Select"); if (result == 1) { lcd.setCursor(3, 3); lcd.print("FIRST"); } if (result == 2) { lcd.setCursor(3, 3); lcd.print("SECOND"); } if (result == 3) { lcd.setCursor(3, 3); lcd.print("THIRD"); } if (result == 4) { lcd.setCursor(3, 3); lcd.print("FOURTH"); } if (result == 5) { lcd.setCursor(3, 3); lcd.print("FIFTH"); } lcdUpdate = millis(); if (digitalRead(buttonPin) == LOW) { lcd.setCursor(8, 2); lcd.print("SELECT"); } } }
Сильно тормозит? В 34 строке delay зачем?
можно даже сказать что не реагируе ( , иногда срабатывает при вращении 1 щелчок за 3-5 сек. Без delay не будет обновлятся показания термопары
// lcd.print(thermocouple.readCelsius());
То ли я слеповат стал... Не найду что-то откуда дисплей данные берёт.
8 строка
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);