#define RED 26
#define GREEN 27
#define BLUE 14
#define ADC_INPUT 32
const uint16_t M = 255;
const int frequency = 1000;
const int resolution = 8;
const int RedChannel = 0;
const int GreenChannel = 1;
const int BlueChannel = 2;
float n = M/60;
int H = 0;
void setup() {
pinMode(ADC_INPUT, INPUT);
//ledcSetup(RedChannel, frequency, resolution); // Setup channel
//ledcSetup(GreenChannel, frequency, resolution); // Setup channel
//edcSetup(BlueChannel, frequency, resolution); // Setup channel
//ledcAttachPin(RED, RedChannel); // Attach channel to GPIO
//ledcAttachPin(GREEN, GreenChannel); // Attach channel to GPIO
//ledcAttachPin(BLUE, BlueChannel); // Attach channel to GPIO
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
Serial.begin(115200);
}
void loop() {
int f = analogRead(ADC_INPUT);
H = map(f, 0, 265, 0, 360);
if ((0 <= H) & (H <= 60))
{
analogWrite(RED, M);
analogWrite(BLUE, 0);
analogWrite(GREEN, (uint8_t)(H * n)); // нарастание
//ledcWrite(RedChannel, M);
//ledcWrite(BlueChannel, 0);
//ledcWrite(GreenChannel, (uint8_t)(H * n));
}
if ((60 < H) & (H <= 120))
{
analogWrite(RED, (uint8_t)(M - n*(H - 60))); // снижение
analogWrite(BLUE, 0);
analogWrite(GREEN, M);
//ledcWrite(RedChannel, (uint8_t)(M - n*(H - 60)));
//ledcWrite(BlueChannel, 0);
//ledcWrite(GreenChannel, M);
}
if ((120 < H) & (H <= 180))
{
analogWrite(RED, 0);
analogWrite(BLUE, (uint8_t)((H - 120)*n)); // нарастание
analogWrite(GREEN, M);
//ledcWrite(RedChannel, 0);
//ledcWrite(BlueChannel, (uint8_t)((H - 120)*n));
//ledcWrite(GreenChannel, M);
}
if ((180 < H) & (H <= 240))
{
analogWrite(RED, 0);
analogWrite(BLUE, M);
analogWrite(GREEN, (uint8_t)(M - n*(H - 180))); // снижение
//ledcWrite(RedChannel, 0);
//ledcWrite(BlueChannel, M);
//ledcWrite(GreenChannel, (uint8_t)(M - n*(H - 180)));
}
if ((240 < H) & (H <= 300))
{
analogWrite(RED, (uint8_t)((H - 240)*n)); // нарастание
analogWrite(BLUE, M);
analogWrite(GREEN, 0);
//ledcWrite(RedChannel, (uint8_t)((H - 240)*n));
//ledcWrite(BlueChannel, M);
//ledcWrite(GreenChannel, 0);
}
if ((300 < H) & (H < 360))
{
analogWrite(RED, M);
analogWrite(BLUE, (uint8_t)(M - n*(H - 300))); // снижение
analogWrite(GREEN, 0);
//ledcWrite(RedChannel, M);
//ledcWrite(BlueChannel, (uint8_t)(M - n*(H - 300)));
//ledcWrite(GreenChannel, 0);
}
Serial.print(f);
Serial.print("---");
Serial.println(H);
}