codice programmazione

salve la mia domanda x i led rgb cambiarli colore qualcuno ha idea di come fare? led con 4 piedini, per fare uscire vari colori come faccio a impostarlo dal arduino?
io pensavo esempio di un efetto variatore..
ma quale il codice x poterlo fare?

Mettendo su Google "led rgb arduino" vengono fuori 270.000 risultati in circa 0.16 secondi....
:sweat_smile:

._. si ma non ce il codice se qualcuno poteva spiegarmi cortesemente,perpiacereeeeee :fearful: :fearful: :fearful: sto sfollando D: almeno sapere il codice del variatore come farlo

int red = 9; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 11; //this sets the blue led pin

int valuer;
int valueg;
int valueb;

void setup() {
 pinMode(red, OUTPUT);
 pinMode(green, OUTPUT);
 pinMode(blue, OUTPUT);
 
 valuer = (255);
 valueg = (255);
 valueb = (255);
}

void loop() {  

  int valuer = analogRead(0);
  valuer = map(valuer, 0, 1023, 0, 255);
  analogWrite(red, valuer);
  
  int valueg = analogRead(1);
  valueg = map(valueg, 0, 1023, 0, 255);
  analogWrite(green, valueg);
  
  int valueb = analogRead(2);
  valueb = map(valueb, 0, 1023, 0, 255);
  analogWrite(blue, valueb);

}

un esempio di quando facevo prove, con 3 potenziometri provi tutte le combinazioni di colore
forse usavo dei catodo comune, con arduino son piu' comodi gli anodo comune
ho un altro esempio con anche il display 16x2, leggi i valori r g b ottenendo il colore che desideri

#include <LiquidCrystal.h>
//(lcd pin 16 a gnd - lcd pin 15 a +5v for backlight)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);



void setup() {

lcd.begin(16, 2);

lcd.print("    R   G   B   ");

}

void loop() {  
  
  lcd.clear();

  int valuer = analogRead(0);
  valuer = map(valuer, 0, 1023, 0, 255);
  
  lcd.setCursor(4, 1);
  lcd.print(valuer);
  
  int valueg = analogRead(1);
  valueg = map(valueg, 0, 1023, 0, 255);
  
  lcd.setCursor(8, 1);
  lcd.print(valueg);
  
  int valueb = analogRead(2);
  valueb = map(valueb, 0, 1023, 0, 255);
  
  lcd.setCursor(12, 1);
  lcd.print(valueb);

analogWrite(9, valuer);
analogWrite(10, valueg);
analogWrite(11, valueb);

}

--> http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227743029/all

Un esempio di codice postato da Federico Vanzati

#define LED_RED 9
#define LED_GREEN 10
#define LED_BLUE 11
#define POT 5

unsigned long interval = 1000;
unsigned long previousMillis = 0;

void setup()
{
  Serial.begin(9600);

}

void loop()
{

  color_wheel();

}// Loop...


void RGB_led(int red_led, int green_led, int blue_led)
{
  analogWrite(LED_RED, red_led);
  analogWrite(LED_GREEN, green_led);
  analogWrite(LED_BLUE, blue_led);
}

void color_wheel()
{
  int red_val = 255;
  int green_val = 0;
  int blue_val = 0;
  int offset;

  int wheel = map(analogRead(POT), 0, 1023, 0, 1535);

  if( wheel <= 255 )  //Rosso al max + Verde in crescita
    green_val = wheel;  // ottengo al max il Giallo
  else if( wheel <= 511 )  //Verde al max + Rosso in diminuzione
  {
    red_val = abs(wheel - 511);  //Rosso va da 255 a 0
    green_val = 255;  //Verde lo tengo al max
  }
  else if( wheel <= 767 )  //Verde al max + Blu in crescita
  {				//(0, 255, 255) = Ciano
    red_val = 0;
    green_val = 255;  //Verde al max
    blue_val = wheel - 511;  //Blu in crescita da 0 a 255
  }
  else if( wheel <= 1023 )  //Blu al max + Verde in diminuzione
  {     //(0, 0, 255) = Blu
    red_val = 0;
    green_val =  abs(wheel - 1023); //Verde in diminuzione da 255 a 0
    blue_val = 255;  //Blu fisso al max
  }
  else if( wheel <= 1279 )   //Blu al max + Rosso in crescita
  {				  //(255, 0, 255) = Magenta
    red_val = wheel - 1023;  //Rosso aumenta da 0 a 255
    blue_val = 255;  //Blu fisso al max
  }
  else {	 //Rosso al max + Blu in diminuzione
    blue_val = abs(wheel - 1535);
  }


  if(millis() - previousMillis > interval)
   {
   previousMillis = millis();

   Serial.print("pot: ");
   Serial.print(wheel);
   Serial.print(", red: ");
   Serial.print(red_val);
   Serial.print(", green: ");
   Serial.print(green_val);
   Serial.print(", blue: ");
   Serial.println(blue_val);

   }

  RGB_led(red_val, green_val, blue_val);

}