LED display
This commit is contained in:
parent
dcbd0b6234
commit
9933a70ae3
@ -15,6 +15,7 @@ lib_deps = https://github.com/milesburton/Arduino-Temperature-Control-Library
|
|||||||
bblanchon/ArduinoJson
|
bblanchon/ArduinoJson
|
||||||
Wire
|
Wire
|
||||||
https://github.com/phassel/ArduPID/
|
https://github.com/phassel/ArduPID/
|
||||||
|
https://github.com/wayoda/LedControl
|
||||||
|
|
||||||
[env:TEST32]
|
[env:TEST32]
|
||||||
upload_port = 10.42.0.66
|
upload_port = 10.42.0.66
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "LedControl.h"
|
||||||
|
|
||||||
#define SENSOR_GPIO D4
|
#define SENSOR_GPIO D4
|
||||||
#define CONTROL_GPIO D2
|
#define CONTROL_GPIO D2
|
||||||
@ -25,6 +26,8 @@ DallasSensor sensor(dallas, 0x3D0417C1D740FF28, "temperatur.ist", 0.1, 5, 60 * 1
|
|||||||
|
|
||||||
ArduPID pid;
|
ArduPID pid;
|
||||||
|
|
||||||
|
LedControl lc = LedControl(13, 14, 15, 1);
|
||||||
|
|
||||||
double proportional = PID_DEFAULT_P;
|
double proportional = PID_DEFAULT_P;
|
||||||
|
|
||||||
double integral = PID_DEFAULT_I;
|
double integral = PID_DEFAULT_I;
|
||||||
@ -39,6 +42,10 @@ double temperatureCurrent = NAN;
|
|||||||
|
|
||||||
double heaterPWM = 0;
|
double heaterPWM = 0;
|
||||||
|
|
||||||
|
void writeDecimal(int *digit, double value);
|
||||||
|
|
||||||
|
void displayLoop();
|
||||||
|
|
||||||
void patrixSetup() {
|
void patrixSetup() {
|
||||||
dallas.begin();
|
dallas.begin();
|
||||||
analogWriteResolution(CONTROL_PWM_BITS);
|
analogWriteResolution(CONTROL_PWM_BITS);
|
||||||
@ -54,6 +61,8 @@ void patrixLoop() {
|
|||||||
dallas.loop();
|
dallas.loop();
|
||||||
sensor.loop();
|
sensor.loop();
|
||||||
|
|
||||||
|
displayLoop();
|
||||||
|
|
||||||
temperatureCurrent = sensor.getLastValue();
|
temperatureCurrent = sensor.getLastValue();
|
||||||
if (!isnan(temperatureCurrent)) {
|
if (!isnan(temperatureCurrent)) {
|
||||||
pid.compute();
|
pid.compute();
|
||||||
@ -89,6 +98,31 @@ void patrixLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void displayLoop() {
|
||||||
|
static unsigned long lastDisplayInit = 0;
|
||||||
|
if (lastDisplayInit == 0 || millis() - lastDisplayInit > 60 * 60 * 1000) {
|
||||||
|
lastDisplayInit = millis();
|
||||||
|
lc.shutdown(0, true);
|
||||||
|
lc.shutdown(0, false);
|
||||||
|
lc.setIntensity(0, 4);
|
||||||
|
lc.clearDisplay(0);
|
||||||
|
}
|
||||||
|
int digit = 0;
|
||||||
|
writeDecimal(&digit, temperatureCurrent);
|
||||||
|
digit++;
|
||||||
|
digit++;
|
||||||
|
writeDecimal(&digit, temperatureTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeDecimal(int *digit, double value) {
|
||||||
|
const int integer = (int) value;
|
||||||
|
const int decimal = (int) ((value - integer) * 10) % 10;
|
||||||
|
lc.setDigit(0, (*digit)++, decimal, false);
|
||||||
|
lc.setDigit(0, (*digit)++, integer % 10, true);
|
||||||
|
lc.setDigit(0, (*digit)++, integer / 10 % 10, false);
|
||||||
|
}
|
||||||
|
|
||||||
bool setDouble(const char *name, double *destinationPtr, double min, double max) {
|
bool setDouble(const char *name, double *destinationPtr, double min, double max) {
|
||||||
const char *valueStr = strtok(nullptr, "");
|
const char *valueStr = strtok(nullptr, "");
|
||||||
if (valueStr == nullptr) {
|
if (valueStr == nullptr) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user