added lightChecker class and some basic pwm stuff
This commit is contained in:
parent
2dfe3e5246
commit
2827573bbc
@ -1,92 +0,0 @@
|
||||
#include <header.h>
|
||||
|
||||
enum colorTypes {
|
||||
purple,
|
||||
blue,
|
||||
green,
|
||||
yellow,
|
||||
orange,
|
||||
red,
|
||||
white
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
colorTypes color = white;
|
||||
|
||||
//Setting PWM properties
|
||||
const int freqRed = 5000;
|
||||
const int freqGreen = 5000;
|
||||
const int freqBlue = 5000;
|
||||
const int ledChannelRed = 0;
|
||||
const int ledChannelGreen = 1;
|
||||
const int ledChannelBlue= 2;
|
||||
const int resolutionRed = 8;
|
||||
const int resolutionGreen = 8;
|
||||
const int resolutionBlue = 8;
|
||||
|
||||
void setupPWM() {
|
||||
ledcSetup(ledChannelRed, freqRed, resolutionRed);
|
||||
ledcSetup(ledChannelGreen, freqGreen, resolutionGreen);
|
||||
ledcSetup(ledChannelBlue, freqBlue, resolutionBlue);
|
||||
|
||||
ledcAttachPin()
|
||||
}
|
||||
|
||||
void readValueNM() {
|
||||
//valueNM = Read from database
|
||||
}
|
||||
|
||||
void getColorBasedOnValueNM() {
|
||||
if (valueNM <= 420) {
|
||||
color = purple;
|
||||
}
|
||||
else if (valueNM <= 490) {
|
||||
color = blue;
|
||||
}
|
||||
else if (valueNM <= 575) {
|
||||
color = green;
|
||||
}
|
||||
else if (valueNM <= 585) {
|
||||
color = yellow;
|
||||
}
|
||||
else if (valueNM <= 650) {
|
||||
color = orange;
|
||||
}
|
||||
else if (valueNM > 650) { //650 to 750 is red
|
||||
color = red;
|
||||
}
|
||||
}
|
||||
|
||||
void activateLight(int duration) {
|
||||
switch (color) {
|
||||
case purple:
|
||||
colorCounter = 0;
|
||||
break;
|
||||
case blue:
|
||||
colorCounter = 1;
|
||||
break;
|
||||
case green:
|
||||
colorCounter = 2;
|
||||
break;
|
||||
case yellow:
|
||||
colorCounter = 3;
|
||||
break;
|
||||
case orange:
|
||||
colorCounter = 4;
|
||||
break;
|
||||
case red:
|
||||
colorCounter = 5;
|
||||
break;
|
||||
case white:
|
||||
colorCounter = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
void activateLight() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -62,4 +62,8 @@ extern float readTemperature();
|
||||
|
||||
// mqtt & wifi
|
||||
extern void setupConnections();
|
||||
extern void publishMessage(const char *topic, const char *msg);
|
||||
extern void publishMessage(const char *topic, const char *msg);
|
||||
|
||||
// RGB PWM LED
|
||||
extern void setupPWM();
|
||||
extern void activateLight();
|
||||
0
src/lightChecker.cpp
Normal file
0
src/lightChecker.cpp
Normal file
@ -12,6 +12,7 @@ void setup() {
|
||||
pingTimer = millis();
|
||||
setupConnections();
|
||||
setupLightSensor();
|
||||
setupPWM();
|
||||
setupTemperatureSensor();
|
||||
setupCapacitiveSoilMoistureSensor();
|
||||
Serial.println("Setup complete...");
|
||||
@ -47,6 +48,8 @@ void loop() {
|
||||
publishMessage("smartgarden/updates/esp-N2Ff4kaDgs45/temperature", buffer);
|
||||
Serial.print("\n");
|
||||
|
||||
activateLight();
|
||||
|
||||
pingTimer = millis();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user