Hi, I checked the simple simple circuit well.. but the code doesn't work correctly.. I attach photos and new code.. I put 4096 because outside of the arduino uno boards. The esp32 boards have the potentiometer which is 4096 adc max. But I put it like this because I had a doubt that here too.. it should be put like this.. but it's not like that. Idea ? Good day.
Maybe there are.. I would like to know how I can do that:
1: Red
2: Green
3: Blue
The problem is the arduino-cli cache, which always loaded the old one for me.. I emptied the temporary folder of the system and now it seems to work as I want.. In addition, I changed the potentiometer.. I am attaching semi-functional code. To make that I would like to do as I put you in the above list what should I do?.
In this piece of code: potMap = map(potValue, 0, 1023, potMinValue, potMaxValue);
that I have to change so that the 4 does not come in the serial monitor when I turn the potentiometer ?.
Thank you very much and have a nice day.
#define RED 3
#define GREEN 6
#define BLUE 5
int POT = 14;
void set_color(int R, int G, int B);
int potValue;
int potMinValue = 1;
int potMaxValue = 4;
int potMap;
const char * color;
void setup() {
Serial.begin(115200);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
set_color(0,0,0);
}
void loop() {
potValue = analogRead(POT);
potMap = map(potValue, 0, 1023, potMinValue, potMaxValue);
if (potMap == 1)
{
color = "RED";
set_color(255,0,0);
}
else if (potMap == 2)
{
color = "GREEN";
set_color(0,255,0);
}
else if(potMap == 3)
{
color = "BLUE";
set_color(0,0,255);
}else
{
color = "OFF";
set_color(0,0,0);
}
// Serial.println(color);
Serial.println(potMap);
delay(30);
}
void set_color(int R, int G, int B){
analogWrite(RED, R);
analogWrite(GREEN, G);
analogWrite(BLUE, B);
}