Marco Colli April 2012 Uses the properties of the RGB Colour Cube The RGB colour space can be viewed as a cube of colour. If we assume a cube of dimension 1, then the coordinates of the vertices for the cubve will range from (0,0,0) to (1,1,1) (all black to all white). The transitions between each vertex will be a smooth colour flow and we can exploit this by using the path coordinates as the LED transition effect. */// Output pins for PWM#define R_PIN 4 // Red LED#define G_PIN 0 // Green LED#define B_PIN 1 // Blue LED

// Constants for readability are better than magic numbers// Used to adjust the limits for the LED, especially if it has a lower ON threshold#define MIN_RGB_VALUE 10 // no smaller than 0. #define MAX_RGB_VALUE 245 // no bigger than 255.

void traverse(int dx, int dy, int dz)// Move along the colour line from where we are to the next vertex of the cube.// The transition is achieved by applying the 'delta' value to the coordinate.// By definition all the coordinates will complete the transition at the same // time as we only have one loop index.{ if ((dx == 0) && (dy == 0) && (dz == 0)) // no point looping if we are staying in the same spot! return;

// Now just loop through the path, traversing from one point to the next for (int i = 0; i < 2*MAX_PATH_SIZE; i++) { // !! loop index is double what the path index is as it is a nybble index !! v1 = v2; if (i&1) // odd number is the second element and ... v2 = path[i>>1] & 0xf; // ... the bottom nybble (index /2) or ... else // ... even number is the first element and ... v2 = path[i>>1] >> 4; // ... the top nybble

There's a few easy ways to do it. You can do it in the calculations that construct the values you're outputting, you can change the values you define for the maximum and minimum (and change the direction of your traverse) or you can do it in the analogWrite() like was outlined above:

Marco Colli April 2012 Uses the properties of the RGB Colour Cube The RGB colour space can be viewed as a cube of colour. If we assume a cube of dimension 1, then the coordinates of the vertices for the cubve will range from (0,0,0) to (1,1,1) (all black to all white). The transitions between each vertex will be a smooth colour flow and we can exploit this by using the path coordinates as the LED transition effect. */// Tranistion Setup

// Constants for readability are better than magic numbers// Used to adjust the limits for the LED, especially if it has a lower ON threshold#define MIN_RGB_VALUE 10 // no smaller than 0. #define MAX_RGB_VALUE 255 // no bigger than 255.

void traverse(int dx, int dy, int dz)// Move along the colour line from where we are to the next vertex of the cube.// The transition is achieved by applying the 'delta' value to the coordinate.// By definition all the coordinates will complete the transition at the same // time as we only have one loop index.{ if ((dx == 0) && (dy == 0) && (dz == 0)) // no point looping if we are staying in the same spot! return;

// Now just loop through the path, traversing from one point to the next for (int i = 0; i < 2*MAX_PATH_SIZE; i++) { // !! loop index is double what the path index is as it is a nybble index !! v1 = v2; if (i&1) // odd number is the second element and ... v2 = path[i>>1] & 0xf; // ... the bottom nybble (index /2) or ... else // ... even number is the first element and ... v2 = path[i>>1] >> 4; // ... the top nybble