title: Arduino LED RGB Control and Convert Hex to RGB
body: <p>I have an RGB LED and have pins to 9, 10, 11 and a pin to ground.</p>
  
  <p>What's I have to do, is to control this LED and light it up with a HEXADECIMAL color choosed in the Serial Monitor.</p>
  
  <pre><code>    int redPin = 9;    // the pin that the red LED is attached to
      int greenPin = 10; // the pin that the green LED is attached to
      int bluePin = 11; // the pin that the blue LED is attached to
  
  
  void setup(){
               Serial.begin(115200);
               pinMode(4,OUTPUT);
               pinMode(redPin, OUTPUT);
               pinMode(greenPin, OUTPUT);
               pinMode(bluePin, OUTPUT);
               Serial.println("Bonjour");
               digitalWrite(4,HIGH);
  }
  
          void loop(){
  
  
  
        while(Serial.available()){
  
     Serial.begin(115200);
  
  for(int i=0;i&lt;5;i++){
  
    hexstring[i] = Serial.read();
  
  }
  int number = (int) strtol( &amp;hexstring, NULL, 16);
  int r = number &gt;&gt; 16;
  int g = number &gt;&gt; 8 &amp; 0xFF;
  int b = number &amp; 0xFF;
  
          colorRGB(redInt,greenInt,blueInt);
  }
  
  
  
  
       void colorRGB(int red, int green, int blue){
               analogWrite(redPin,constrain(red,0,255));
               analogWrite(greenPin,constrain(green,0,255));
               analogWrite(bluePin,constrain(blue,0,255));
  
          }
  </code></pre>
  
  <p>1st erreur in this line : </p>
  
  <pre><code>int number = (int) strtol( &amp;hexstring, NULL, 16)
  </code></pre>
  
  <p>I wanted to try just the first part by picking up and HEX color :</p>
  
  <pre><code> String hexstring = "#FFFFFF";
      int number = (int) strtol( &amp;hexstring[1], NULL, 16);
      int r = number &gt;&gt; 16;
      int g = number &gt;&gt; 8 &amp; 0xFF;
      int b = number &amp; 0xFF;
  </code></pre>
  
  <p>No Error but the LED don't light up !
  Could anyone help me ?! PLEASE !!</p>