From 52e3ab8cdc030b38a0ec5d7e1082a7edfca00655 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 1 Jul 2020 10:52:26 +0200 Subject: [PATCH] update lightChecker --- src/lightChecker.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/lightChecker.cpp b/src/lightChecker.cpp index e69de29..1a30e1e 100644 --- a/src/lightChecker.cpp +++ b/src/lightChecker.cpp @@ -0,0 +1,61 @@ +#include + +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]); +} \ No newline at end of file