update lightChecker
This commit is contained in:
parent
2827573bbc
commit
52e3ab8cdc
@ -0,0 +1,61 @@
|
|||||||
|
#include <header.h>
|
||||||
|
|
||||||
|
int valueNM;
|
||||||
|
// Colors in Array: purple, blue, green, yellow, orange, red, white
|
||||||
|
int colorValueArray[][3] = {{125,0,125}, {0,0,255}, {0,255,0}, {255,255,0}, {255,140,0}, {255,0,0}, {255,255,255}};
|
||||||
|
int colorCounter = 6;
|
||||||
|
|
||||||
|
// Setting PWM properties
|
||||||
|
const int freq = 5000;
|
||||||
|
const int ledChannelRed = 0;
|
||||||
|
const int ledChannelGreen = 1;
|
||||||
|
const int ledChannelBlue= 2;
|
||||||
|
const int resolution = 8;
|
||||||
|
|
||||||
|
void setupPWM() {
|
||||||
|
// Set pins as output
|
||||||
|
pinMode(PIN_LED_R, OUTPUT);
|
||||||
|
pinMode(PIN_LED_G, OUTPUT);
|
||||||
|
pinMode(PIN_LED_B, OUTPUT);
|
||||||
|
|
||||||
|
// Configure LED PWM functionalitites
|
||||||
|
ledcSetup(ledChannelRed, freq, resolution);
|
||||||
|
ledcSetup(ledChannelGreen, freq, resolution);
|
||||||
|
ledcSetup(ledChannelBlue, freq, resolution);
|
||||||
|
|
||||||
|
// Attach the channel to the GPIO2 to be controlled
|
||||||
|
ledcAttachPin(PIN_LED_R, ledChannelRed);
|
||||||
|
ledcAttachPin(PIN_LED_G, ledChannelGreen);
|
||||||
|
ledcAttachPin(PIN_LED_B, ledChannelBlue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void readValueNM() {
|
||||||
|
// ValueNM = Read from database
|
||||||
|
}
|
||||||
|
|
||||||
|
void getColorBasedOnValueNM() {
|
||||||
|
if (valueNM <= 420) {
|
||||||
|
colorCounter = 0;
|
||||||
|
}
|
||||||
|
else if (valueNM <= 490) {
|
||||||
|
colorCounter = 1;
|
||||||
|
}
|
||||||
|
else if (valueNM <= 575) {
|
||||||
|
colorCounter = 2;
|
||||||
|
}
|
||||||
|
else if (valueNM <= 585) {
|
||||||
|
colorCounter = 3;
|
||||||
|
}
|
||||||
|
else if (valueNM <= 650) {
|
||||||
|
colorCounter = 4;
|
||||||
|
}
|
||||||
|
else if (valueNM > 650) { // 650 to 750 is red
|
||||||
|
colorCounter = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void activateLight() {
|
||||||
|
ledcWrite(ledChannelRed, colorValueArray[colorCounter][0]);
|
||||||
|
ledcWrite(ledChannelGreen, colorValueArray[colorCounter][1]);
|
||||||
|
ledcWrite(ledChannelBlue, colorValueArray[colorCounter][2]);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user