// Franzininho WiFi RGB LED with Slide Potentiometer

#define B_POT 1
#define G_POT 2
#define R_POT 3
#define B_PIN 4
#define G_PIN 5
#define R_PIN 6

// Variable for storing the potentiometer value
uint8_t potRValue = 0;
uint8_t potGValue = 0;
uint8_t potBValue = 0;

uint8_t readPot(int pin) {
  return map(analogRead(pin), 0, 1023, 0, 255);
}

void setup() {
  Serial.begin(115200);
  delay(10);

  pinMode(R_POT, INPUT);
  pinMode(G_POT, INPUT);
  pinMode(B_POT, INPUT);

  pinMode(R_PIN, OUTPUT);
  pinMode(G_PIN, OUTPUT);
  pinMode(B_PIN, OUTPUT);
}

void loop() {
  potRValue = readPot(R_POT);
  potGValue = readPot(G_POT);
  potBValue = readPot(B_POT);

  analogWrite(R_PIN, potRValue);
  analogWrite(G_PIN, potGValue);
  analogWrite(B_PIN, potBValue);

  Serial.printf("RGB(%d, %d, %d)\n", potRValue, potGValue, potBValue);
  delay(500);
}
Loading
franzininho-wifi