Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials_colors [2016/02/24 05:49]
admin created
tutorials_colors [2016/11/25 17:54]
admin
Line 3: Line 3:
 You can fully control the RGB LED and make it shine any color you wish in full 24-bit glory by playing with the intensity of the shades of Red, Green and Blue. You will need to use the analogWrite() function instead. You can fully control the RGB LED and make it shine any color you wish in full 24-bit glory by playing with the intensity of the shades of Red, Green and Blue. You will need to use the analogWrite() function instead.
  
-<code C> +<html><script src="​https:​//gist.github.com/deathmeek/b39b2fcb10545a88113ef9d6eed141d7.js">​</script></html>
-  +
-int greenLED ​11;     //green LED on Arduino pin 11            +
-int redLED = 8;        //red LED on pin 8 +
-int blueLED = 10;      //blue LED on pin 10  +
-  +
-void setup() ​                   // run once, when the sketch starts +
-+
-  pinMode(greenLED,​ OUTPUT); ​     // sets the digital pin as output +
-  pinMode(redLED,​ OUTPUT); +
-  pinMode(blueLED,​ OUTPUT); +
-+
- +
-// controls the RGB LED +
-void color(unsigned char red, unsigned char green, unsigned char blue) +
-+
-  analogWrite(redLED,​ 255-red); +
-  analogWrite(greenLED,​ 255-green);​ +
-  analogWrite(blueLED,​ 255-blue);​ +
-+
-  +
-void loop() ​                    // run over and over again +
-+
-  unsigned char color_rgb[3];​ +
-  +
-  // Start off with red. +
-  color_rgb[0] = 255; +
-  color_rgb[1] = 0; +
-  color_rgb[2] = 0;   +
-  +
-  ​// Choose the colours to increment and decrement. +
-  for (int decColour = 0; decColour ​3; decColour += 1) { +
-    int incColour = decColour == 2 ? 0 : decColour + 1; +
-  +
-    ​// cross-fade the two colours. +
-    for(int i = 0; i < 255; i += 1) { +
-      color_rgb[decColour] -= 1; +
-      color_rgb[incColour] += 1; +
-  +
-      color(color_rgb[0],​ color_rgb[1],​ color_rgb[2]);​ +
-      delay(15);​ +
-}}} +
-</code+
  
 <​note>​ You can make the LED display any color, but you will need to use //​analogWrite()//​ </​note>​ <​note>​ You can make the LED display any color, but you will need to use //​analogWrite()//​ </​note>​
Line 58: Line 16:
 \\ \\
 \\ \\
 +
 +<note tip>Want to actually measure things with the sensor node? Check out how to read the [[tutorials_temperature|temperature]]!</​note>​