Samstag, 9. Februar 2013

Boblight Ubuntu with Arduino Nano

 50LEDs

LEDstream.pde on Arduino Nano

Boblight because Adalight with Processing (very slow)

####################################################################

http://code.google.com/p/boblight/wiki/Compiling


If everything goes well..... $ make $ sudo make install
Fourth step configure boblight for your controller:
Depending on your controller you should move the correct config files to /etc under ~/boblight-read-only/arduino you will find config files for different setups.

For a arduino duemilanove,
$ sudo cp ~/boblight-read-only/arduino/duemilanove.conf /etc/boblight.conf

For a arduino MEGA,
$ sudo cp ~/boblight-read-only/arduino/mega.conf /etc/boblight.conf

Next put the arduino sketch onto your arduino. For simply a arduino MEGA or Duemilanove, open the sketch located at ~/boblight-read-only/arduino/boblight_arduino_pwm/boblight_arduino_pwm.pde in the arduino IDE.

The wiring for the arduino is as follows:

For duemilanove,
connect the first LED to pins 3,5,6 (which correspond to R,G,B). and the second LED to 9,10,11. Wire all the LED's ground to the ground on your arduino.

For MEGA,
connect the first LED to pins 2,3,4 (which correspond to R,G,B). the second LED to pins 5,6,7. the third LED to pins 8,9,10. and the fourth LED to pins 11,12,13. Wire all the LED's ground to the ground on your arduino.
Fifth step: Testing the lights:
Plug your arduino into your computer's USB port and run the command:
$ boblightd
Test your lights by running in another terminal:
$ boblight-constant FF0000 This should output the color RED. Kill this process and run: $ boblight-constant 00FF00 This should output the color GREEN. Kill this process and run: $ boblight-constant 0000FF This should output the color BLUE. Kill this process.

If a color wasn't output, or the wrong color was displayed you should go check the wiring of your arduino.

Depending on how your using boblight, you should run the correct boblight client. To have the colors change based on the image being displayed on the screen you should use boblight-X11.

boblight-X11 is known not to work in full screen with certain AMD Radeon cards with the closed source drivers. Some will work with the free Radeon drivers.

If you are running boblight-X11 over ssh do:
$ export DISPLAY=:0.0

To list various options for boblight-X11 you can run boblight-X11 -l and for help boblight-X11 -help

An example one could use is:
boblight-X11 -x -i 0.03 -o value=5.0 -o saturation=2.0 -o speed=60.0
Written by: jjrh
 
Problem with Arduino Nano controller --> ln /dev/ttyUSB0 /dev/ttyS55

/etc/boblight.conf

[global]
interface       127.0.0.1
port            19333


[device]
name            ambilight
type               momo
output          /dev/ttyS55
channels        150             #c'est le nombre de LED multiplié par 3. Dans cette exemple 75 = 25Ledx3
prefix        41 64 61 00 31 64     #50 LEDs
interval        10000
rate            115200
debug           off #turn this on to see what it's doing with the serial port
delayafteropen    1000000

[color]
name            red
rgb             0000FF
#rgb             FF0000
adjust            0.7
gamma           1.0

[color]
name            green
rgb             00FF00
adjust            1.0
gamma           1.0

[color]
name            blue
rgb             FF0000
#rgb             0000FF
adjust            1.0
gamma           1.0



[light]
name            1
color           red     ambilight 1
color           green   ambilight 2
color           blue    ambilight 3
hscan           47.08 52.97
vscan           90 100

[light]
name            2
color           red     ambilight 4
color           green   ambilight 5
color           blue    ambilight 6
hscan           41.2 47.08
vscan           90 100

[light]
name            3
color           red     ambilight 7
color           green   ambilight 8
color           blue    ambilight 9
hscan           35.31 41.19
vscan           90 100

[light]
name            4
color           red     ambilight 10
color           green   ambilight 11
color           blue    ambilight 12
hscan           29.43 35.31
vscan           90 100

[light]
name            5
color           red     ambilight 13
color           green   ambilight 14
color           blue    ambilight 15
hscan           23.54 29.42
vscan           90 100

[light]
name            6
color           red     ambilight 16
color           green   ambilight 17
color           blue    ambilight 18
hscan           17.66 23.54
vscan           90 100

[light]
name            7
color           red     ambilight 19
color           green   ambilight 20
color           blue    ambilight 21
hscan           11.77 17.65
vscan           90 100

[light]
name            8
color           red     ambilight 22
color           green   ambilight 23
color           blue    ambilight 24
hscan           5.89 11.77
vscan           90 100

[light]
name            9
color           red     ambilight 25
color           green   ambilight 26
color           blue    ambilight 27
hscan           0 5.88
vscan           90 100

[light]
name            10
color           red     ambilight 28
color           green   ambilight 29
color           blue    ambilight 30
hscan           0 5.88
vscan           80 90

[light]
name            11
color           red     ambilight 31
color           green   ambilight 32
color           blue    ambilight 33
hscan           0 5.88
vscan           70 80

[light]
name            12
color           red     ambilight 34
color           green   ambilight 35
color           blue    ambilight 36
hscan           0 5.88
vscan           60 70

[light]
name            13
color           red     ambilight 37
color           green   ambilight 38
color           blue    ambilight 39
hscan           0 5.88
vscan           50 60

[light]
name            14
color           red     ambilight 40
color           green   ambilight 41
color           blue    ambilight 42
hscan           0 5.88
vscan           40 50

[light]
name            15
color           red     ambilight 43
color           green   ambilight 44
color           blue    ambilight 45
hscan           0 5.88
vscan           30 40

[light]
name            16
color           red     ambilight 46
color           green   ambilight 47
color           blue    ambilight 48
hscan           0 5.88
vscan           20 30

[light]
name            17
color           red     ambilight 49
color           green   ambilight 50
color           blue    ambilight 51
hscan           0 5.88
vscan           10 20

[light]
name            18
color           red     ambilight 52
color           green   ambilight 53
color           blue    ambilight 54
hscan           0 5.88
vscan           0 10

[light]
name            19
color           red     ambilight 55
color           green   ambilight 56
color           blue    ambilight 57
hscan           5.88 11.76
vscan           0 10

[light]
name            20
color           red     ambilight 58
color           green   ambilight 59
color           blue    ambilight 60
hscan           11.76 17.65
vscan           0 10

[light]
name            21
color           red     ambilight 61
color           green   ambilight 62
color           blue    ambilight 63
hscan           17.65 23.53
vscan           0 10

[light]
name            22
color           red     ambilight 64
color           green   ambilight 65
color           blue    ambilight 66
hscan           23.53 29.41
vscan           0 10

[light]
name            23
color           red     ambilight 67
color           green   ambilight 68
color           blue    ambilight 69
hscan           29.41 35.29
vscan           0 10

[light]
name            24
color           red     ambilight 70
color           green   ambilight 71
color           blue    ambilight 72
hscan           35.29 41.18
vscan           0 10

[light]
name            25
color           red     ambilight 73
color           green   ambilight 74
color           blue    ambilight 75
hscan           41.18 47.06
vscan           0 10

[light]
name            26
color           red     ambilight 76
color           green   ambilight 77
color           blue    ambilight 78
hscan           47.06 52.94
vscan           0 10

[light]
name            27
color           red     ambilight 79
color           green   ambilight 80
color           blue    ambilight 81
hscan           52.94 58.82
vscan           0 10

[light]
name            28
color           red     ambilight 82
color           green   ambilight 83
color           blue    ambilight 84
hscan           58.82 64.71
vscan           0 10

[light]
name            29
color           red     ambilight 85
color           green   ambilight 86
color           blue    ambilight 87
hscan           64.71 70.59
vscan           0 10

[light]
name            30
color           red     ambilight 88
color           green   ambilight 89
color           blue    ambilight 90
hscan           70.59 76.47
vscan           0 10

[light]
name            31
color           red     ambilight 91
color           green   ambilight 92
color           blue    ambilight 93
hscan           76.47 82.35
vscan           0 10

[light]
name            32
color           red     ambilight 94
color           green   ambilight 95
color           blue    ambilight 96
hscan           82.35 88.23
vscan           0 10

[light]
name            33
color           red     ambilight 97
color           green   ambilight 98
color           blue    ambilight 99
hscan           88.23 94.12
vscan           0 10

[light]
name            34
color           red     ambilight 100
color           green   ambilight 101
color           blue    ambilight 102
hscan           94.12 100
vscan           0 10

[light]
name            35
color           red     ambilight 103
color           green   ambilight 104
color           blue    ambilight 105
hscan           94.12 100
vscan           10 20

[light]
name            36
color           red     ambilight 106
color           green   ambilight 107
color           blue    ambilight 108
hscan           94.12 100
vscan           20 30

[light]
name            37
color           red     ambilight 109
color           green   ambilight 110
color           blue    ambilight 111
hscan           94.12 100
vscan           30 40

[light]
name            38
color           red     ambilight 112
color           green   ambilight 113
color           blue    ambilight 114
hscan           94.12 100
vscan           40 50

[light]
name            39
color           red     ambilight 115
color           green   ambilight 116
color           blue    ambilight 117
hscan           94.12 100
vscan           50 60

[light]
name            40
color           red     ambilight 118
color           green   ambilight 119
color           blue    ambilight 120
hscan           94.12 100
vscan           60 70

[light]
name            41
color           red     ambilight 121
color           green   ambilight 122
color           blue    ambilight 123
hscan           94.12 100
vscan           70 80

[light]
name            42
color           red     ambilight 124
color           green   ambilight 125
color           blue    ambilight 126
hscan           94.12 100
vscan           80 90

[light]
name            43
color           red     ambilight 127
color           green   ambilight 128
color           blue    ambilight 129
hscan           94.12 100
vscan           90 100

[light]
name            44
color           red     ambilight 130
color           green   ambilight 131
color           blue    ambilight 132
hscan           88.24 94.12
vscan           90 100

[light]
name            45
color           red     ambilight 133
color           green   ambilight 134
color           blue    ambilight 135
hscan           82.35 88.24
vscan           90 100

[light]
name            46
color           red     ambilight 136
color           green   ambilight 137
color           blue    ambilight 138
hscan           76.47 82.35
vscan           90 100

[light]
name            47
color           red     ambilight 139
color           green   ambilight 140
color           blue    ambilight 141
hscan           70.59 76.47
vscan           90 100

[light]
name            48
color           red     ambilight 142
color           green   ambilight 143
color           blue    ambilight 144
hscan           64.71 70.59
vscan           90 100

[light]
name            49
color           red     ambilight 145
color           green   ambilight 146
color           blue    ambilight 147
hscan           58.82 64.71
vscan           90 100

[light]
name            50
color           red     ambilight 148
color           green   ambilight 149
color           blue    ambilight 150
hscan           52.94 58.82
vscan           90 100

----------------------------------------------------------------------------
 Test:

terminal 1: boblightd
terminal 2: boblight-X11

######################################################################




Dienstag, 5. Februar 2013

Adalight + Processing 50 LEDs RedBlue switched

sources:
http://learn.adafruit.com/adalight-diy-ambient-tv-lighting/advanced-topics




problem: ws2801 LED stripes Red<->Blue transposed

some adjustments in code of processing sketch necessary for the colors also for the amount of LEDs (50)


 Update
solution:
sketch:



// "Adalight" is a do-it-yourself facsimile of the Philips Ambilight concept
// for desktop computers and home theater PCs.  This is the host PC-side code
// written in Processing, intended for use with a USB-connected Arduino
// microcontroller running the accompanying LED streaming code.  Requires one
// or more strands of Digital RGB LED Pixels (Adafruit product ID #322,
// specifically the newer WS2801-based type, strand of 25) and a 5 Volt power
// supply (such as Adafruit #276).  You may need to adapt the code and the
// hardware arrangement for your specific display configuration.
// Screen capture adapted from code by Cedrik Kiefer (processing.org forum)

// --------------------------------------------------------------------
//   This file is part of Adalight.

//   Adalight is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as
//   published by the Free Software Foundation, either version 3 of
//   the License, or (at your option) any later version.

//   Adalight is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.

//   You should have received a copy of the GNU Lesser General Public
//   License along with Adalight.  If not, see
//   <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------

import java.awt.*;
import java.awt.image.*;
import processing.serial.*;

// CONFIGURABLE PROGRAM CONSTANTS --------------------------------------------

// Minimum LED brightness; some users prefer a small amount of backlighting
// at all times, regardless of screen content.  Higher values are brighter,
// or set to 0 to disable this feature.

static final short minBrightness = 120;

// LED transition speed; it's sometimes distracting if LEDs instantaneously
// track screen contents (such as during bright flashing sequences), so this
// feature enables a gradual fade to each new LED state.  Higher numbers yield
// slower transitions (max of 255), or set to 0 to disable this feature
// (immediate transition of all LEDs).

static final short fade = 75;

// Pixel size for the live preview image.

static final int pixelSize = 20;

// Depending on many factors, it may be faster either to capture full
// screens and process only the pixels needed, or to capture multiple
// smaller sub-blocks bounding each region to be processed.  Try both,
// look at the reported frame rates in the Processing output console,
// and run with whichever works best for you.

static final boolean useFullScreenCaps = true;

// Serial device timeout (in milliseconds), for locating Arduino device
// running the corresponding LEDstream code.  See notes later in the code...
// in some situations you may want to entirely comment out that block.

static final int timeout = 5000; // 5 seconds

// PER-DISPLAY INFORMATION ---------------------------------------------------

// This array contains details for each display that the software will
// process.  If you have screen(s) attached that are not among those being
// "Adalighted," they should not be in this list.  Each triplet in this
// array represents one display.  The first number is the system screen
// number...typically the "primary" display on most systems is identified
// as screen #1, but since arrays are indexed from zero, use 0 to indicate
// the first screen, 1 to indicate the second screen, and so forth.  This
// is the ONLY place system screen numbers are used...ANY subsequent
// references to displays are an index into this list, NOT necessarily the
// same as the system screen number.  For example, if you have a three-
// screen setup and are illuminating only the third display, use '2' for
// the screen number here...and then, in subsequent section, '0' will be
// used to refer to the first/only display in this list.
// The second and third numbers of each triplet represent the width and
// height of a grid of LED pixels attached to the perimeter of this display.
// For example, '9,6' = 9 LEDs across, 6 LEDs down.

static final int displays[][] = new int[][] {
   {0,17,10} // Screen 0, 9 LEDs across, 6 LEDs down
//   {0,9,6} // Screen 0, 9 LEDs across, 6 LEDs down
//,{1,9,6} // Screen 1, also 9 LEDs across and 6 LEDs down
};

// PER-LED INFORMATION -------------------------------------------------------

// This array contains the 2D coordinates corresponding to each pixel in the
// LED strand, in the order that they're connected (i.e. the first element
// here belongs to the first LED in the strand, second element is the second
// LED, and so forth).  Each triplet in this array consists of a display
// number (an index into the display array above, NOT necessarily the same as
// the system screen number) and an X and Y coordinate specified in the grid
// units given for that display.  {0,0,0} is the top-left corner of the first
// display in the array.
// For our example purposes, the coordinate list below forms a ring around
// the perimeter of a single screen, with a one pixel gap at the bottom to
// accommodate a monitor stand.  Modify this to match your own setup:



//50LEDs
//falsch aufgeklebt bzgl. Bild 1=1, 50=2, 49=3,...2=50
static final int leds[][] = new int[][] {
// 1        2       3          4       5         6        7        8       9
//{0,8,9}, {0,7,9}, {0,6,9}, {0,5,9}, {0,4,9}, {0,3,9}, {0,2,9}, {0,1,9}, {0,0,9},    // Bottom edge, left half
{0,8,9}, {0,9,9},  {0,10,9},{0,11,9},{0,12,9},{0,13,9},{0,14,9}, {0,15,9},{0,16,9},



// 35      36          37        38        39        40        41        42
//{0,0,8}, {0,0,7}, {0,0,6}, {0,0,5}, {0,0,4}, {0,0,3}, {0,0,2}, {0,0,1}, {0,0,0},   
{0,16,8},{0,16,7},{0,16,6}, {0,16,5},{0,16,4},{0,16,3},  {0,16,2},{0,16,1},          // Right edge


//{0,1,0}, {0,2,0}, {0,3,0}, {0,4,0}, {0,5,0}, {0,6,0}, {0,7,0}, {0,8,0},               // Top edge
//{0,9,0}, {0,10,0}, {0,11,0}, {0,12,0}, {0,13,0}, {0,14,0}, {0,15,0}, {0,16,0},       // More top edge
{0,16,0},{0,15,0},{0,14,0},{0,13,0},{0,12,0},{0,11,0},{0,10,0},{0,9,0},
 {0,8,0},{0,7,0}, {0,6,0},{0,5,0},{0,4,0},{0,3,0}, {0,2,0}, {0,1,0},


// 10      11        12      13        14       15      16        17      18
//{0,16,1}, {0,16,2}, {0,16,3}, {0,16,4}, {0,16,5}, {0,16,6}, {0,16,7}, {0,16,8},   // Left edge
{0,0,0},{0,0,1},{0,0,2},{0,0,3},{0,0,4},{0,0,5},{0,0,6},{0,0,7},{0,0,8},

// 43        44      45        46      47      48        49        50
//{0,16,9},  {0,15,9}, {0,14,9}, {0,13,9}, {0,12,9}, {0,11,9}, {0,10,9}, {0,9,9},            // Bottom edge, right half
{0,0,9}, {0,1,9},{0,2,9}, {0,3,9},{0,4,9}, {0,5,9},{0,6,9}, {0,7,9},

//50LEDs
//static final int leds[][] = new int[][] {
// 1        2       3          4       5         6        7        8       9
//{0,8,9}, {0,7,9}, {0,6,9}, {0,5,9}, {0,4,9}, {0,3,9}, {0,2,9}, {0,1,9}, {0,0,9},    // Bottom edge, left half
// 10      11        12      13        14       15      16        17      18
//{0,16,1}, {0,16,2}, {0,16,3}, {0,16,4}, {0,16,5}, {0,16,6}, {0,16,7}, {0,16,8},     // Right edge


//{0,1,0}, {0,2,0}, {0,3,0}, {0,4,0}, {0,5,0}, {0,6,0}, {0,7,0}, {0,8,0},             // Top edge
//{0,9,0}, {0,10,0}, {0,11,0}, {0,12,0}, {0,13,0}, {0,14,0}, {0,15,0}, {0,16,0},     // More top edge

// 35      36          37        38        39        40        41        42
//{0,0,8}, {0,0,7}, {0,0,6}, {0,0,5}, {0,0,4}, {0,0,3}, {0,0,2}, {0,0,1}, {0,0,0},    // Left edge

// 43        44      45        46      47      48        49        50
//{0,16,9},  {0,15,9}, {0,14,9}, {0,13,9}, {0,12,9}, {0,11,9}, {0,10,9}, {0,9,9},            // Bottom edge, right half

//25LEDs
//static final int leds[][] = new int[][] {
//  {0,3,5}, {0,2,5}, {0,1,5}, {0,0,5}, // Bottom edge, left half
//  {0,0,4}, {0,0,3}, {0,0,2}, {0,0,1}, // Left edge
//  {0,0,0}, {0,1,0}, {0,2,0}, {0,3,0}, {0,4,0}, // Top edge
//           {0,5,0}, {0,6,0}, {0,7,0}, {0,8,0}, // More top edge
//  {0,8,1}, {0,8,2}, {0,8,3}, {0,8,4}, // Right edge
//  {0,8,5}, {0,7,5}, {0,6,5}, {0,5,5}  // Bottom edge, right half

/* Hypothetical second display has the same arrangement as the first.
   But you might not want both displays completely ringed with LEDs;
   the screens might be positioned where they share an edge in common.
 ,{1,3,5}, {1,2,5}, {1,1,5}, {1,0,5}, // Bottom edge, left half
  {1,0,4}, {1,0,3}, {1,0,2}, {1,0,1}, // Left edge
  {1,0,0}, {1,1,0}, {1,2,0}, {1,3,0}, {1,4,0}, // Top edge
           {1,5,0}, {1,6,0}, {1,7,0}, {1,8,0}, // More top edge
  {1,8,1}, {1,8,2}, {1,8,3}, {1,8,4}, // Right edge
  {1,8,5}, {1,7,5}, {1,6,5}, {1,5,5}  // Bottom edge, right half
*/
};

// GLOBAL VARIABLES ---- You probably won't need to modify any of this -------

byte[]           serialData  = new byte[6 + leds.length * 3];
short[][]        ledColor    = new short[leds.length][3],
                 prevColor   = new short[leds.length][3];
byte[][]         gamma       = new byte[256][3];
int              nDisplays   = displays.length;
Robot[]          bot         = new Robot[displays.length];
Rectangle[]      dispBounds  = new Rectangle[displays.length],
                 ledBounds;  // Alloc'd only if per-LED captures
int[][]          pixelOffset = new int[leds.length][256],
                 screenData; // Alloc'd only if full-screen captures
PImage[]         preview     = new PImage[displays.length];
Serial           port;
DisposeHandler   dh; // For disabling LEDs on exit

// INITIALIZATION ------------------------------------------------------------

void setup() {
  GraphicsEnvironment     ge;
  GraphicsConfiguration[] gc;
  GraphicsDevice[]        gd;
  int                     d, i, totalWidth, maxHeight, row, col, rowOffset;
  int[]                   x = new int[16], y = new int[16];
  float                   f, range, step, start;

  dh = new DisposeHandler(this); // Init DisposeHandler ASAP

  // Open serial port.  As written here, this assumes the Arduino is the
  // first/only serial device on the system.  If that's not the case,
  // change "Serial.list()[0]" to the name of the port to be used:
  port = new Serial(this, Serial.list()[0], 115200);
  // Alternately, in certain situations the following line can be used
  // to detect the Arduino automatically.  But this works ONLY with SOME
  // Arduino boards and versions of Processing!  This is so convoluted
  // to explain, it's easier just to test it yourself and see whether
  // it works...if not, leave it commented out and use the prior port-
  // opening technique.
  // port = openPort();
  // And finally, to test the software alone without an Arduino connected,
  // don't open a port...just comment out the serial lines above.

  // Initialize screen capture code for each display's dimensions.
  dispBounds = new Rectangle[displays.length];
  if(useFullScreenCaps == true) {
    screenData = new int[displays.length][];
    // ledBounds[] not used
  } else {
    ledBounds  = new Rectangle[leds.length];
    // screenData[][] not used
  }
  ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  gd = ge.getScreenDevices();
  if(nDisplays > gd.length) nDisplays = gd.length;
  totalWidth = maxHeight = 0;
  for(d=0; d<nDisplays; d++) { // For each display...
    try {
      bot[d] = new Robot(gd[displays[d][0]]);
    }
    catch(AWTException e) {
      System.out.println("new Robot() failed");
      continue;
    }
    gc              = gd[displays[d][0]].getConfigurations();
    dispBounds[d]   = gc[0].getBounds();
    dispBounds[d].x = dispBounds[d].y = 0;
    preview[d]      = createImage(displays[d][1], displays[d][2], RGB);
    preview[d].loadPixels();
    totalWidth     += displays[d][1];
    if(d > 0) totalWidth++;
    if(displays[d][2] > maxHeight) maxHeight = displays[d][2];
  }

  // Precompute locations of every pixel to read when downsampling.
  // Saves a bunch of math on each frame, at the expense of a chunk
  // of RAM.  Number of samples is now fixed at 256; this allows for
  // some crazy optimizations in the downsampling code.
  for(i=0; i<leds.length; i++) { // For each LED...
    d = leds[i][0]; // Corresponding display index

    // Precompute columns, rows of each sampled point for this LED
    range = (float)dispBounds[d].width / (float)displays[d][1];
    step  = range / 16.0;
    start = range * (float)leds[i][1] + step * 0.5;
    for(col=0; col<16; col++) x[col] = (int)(start + step * (float)col);
    range = (float)dispBounds[d].height / (float)displays[d][2];
    step  = range / 16.0;
    start = range * (float)leds[i][2] + step * 0.5;
    for(row=0; row<16; row++) y[row] = (int)(start + step * (float)row);

    if(useFullScreenCaps == true) {
      // Get offset to each pixel within full screen capture
      for(row=0; row<16; row++) {
        for(col=0; col<16; col++) {
          pixelOffset[i][row * 16 + col] =
            y[row] * dispBounds[d].width + x[col];
        }
      }
    } else {
      // Calc min bounding rect for LED, get offset to each pixel within
      ledBounds[i] = new Rectangle(x[0], y[0], x[15]-x[0]+1, y[15]-y[0]+1);
      for(row=0; row<16; row++) {
        for(col=0; col<16; col++) {
          pixelOffset[i][row * 16 + col] =
            (y[row] - y[0]) * ledBounds[i].width + x[col] - x[0];
        }
      }
    }
  }

  for(i=0; i<prevColor.length; i++) {
    prevColor[i][0] = prevColor[i][1] = prevColor[i][2] =
      minBrightness / 3;
  }

  // Preview window shows all screens side-by-side
  size(totalWidth * pixelSize, maxHeight * pixelSize, JAVA2D);
  noSmooth();

  // A special header / magic word is expected by the corresponding LED
  // streaming code running on the Arduino.  This only needs to be initialized
  // once (not in draw() loop) because the number of LEDs remains constant:
  serialData[0] = 'A';                              // Magic word
  serialData[1] = 'd';
  serialData[2] = 'a';
  serialData[3] = (byte)((leds.length - 1) >> 8);   // LED count high byte
  serialData[4] = (byte)((leds.length - 1) & 0xff); // LED count low byte
  serialData[5] = (byte)(serialData[3] ^ serialData[4] ^ 0x55); // Checksum

  // Pre-compute gamma correction table for LED brightness levels:
  for(i=0; i<256; i++) {
    f           = pow((float)i / 255.0, 2.8);
    gamma[i][0] = (byte)(f * 255.0);
    gamma[i][1] = (byte)(f * 240.0);
    gamma[i][2] = (byte)(f * 220.0);
  }
}

// Open and return serial connection to Arduino running LEDstream code.  This
// attempts to open and read from each serial device on the system, until the
// matching "Ada\n" acknowledgement string is found.  Due to the serial
// timeout, if you have multiple serial devices/ports and the Arduino is late
// in the list, this can take seemingly forever...so if you KNOW the Arduino
// will always be on a specific port (e.g. "COM6"), you might want to comment
// out most of this to bypass the checks and instead just open that port
// directly!  (Modify last line in this method with the serial port name.)

Serial openPort() {
  String[] ports;
  String   ack;
  int      i, start;
  Serial   s;

  ports = Serial.list(); // List of all serial ports/devices on system.

  for(i=0; i<ports.length; i++) { // For each serial port...
    System.out.format("Trying serial port %s\n",ports[i]);
    try {
      s = new Serial(this, ports[i], 115200);
    }
    catch(Exception e) {
      // Can't open port, probably in use by other software.
      continue;
    }
    // Port open...watch for acknowledgement string...
    start = millis();
    while((millis() - start) < timeout) {
      if((s.available() >= 4) &&
        ((ack = s.readString()) != null) &&
        ack.contains("Ada\n")) {
          return s; // Got it!
      }
    }
    // Connection timed out.  Close port and move on to the next.
    s.stop();
  }

  // Didn't locate a device returning the acknowledgment string.
  // Maybe it's out there but running the old LEDstream code, which
  // didn't have the ACK.  Can't say for sure, so we'll take our
  // changes with the first/only serial device out there...
  return new Serial(this, ports[0], 115200);
}


// PER_FRAME PROCESSING ------------------------------------------------------

void draw () {
  BufferedImage img;
  int           d, i, j, o, c, weight, rb, g, sum, deficit, s2, r, b; //added rb variabeln
  int[]         pxls, offs;

  if(useFullScreenCaps == true ) {
    // Capture each screen in the displays array.
    for(d=0; d<nDisplays; d++) {
      img = bot[d].createScreenCapture(dispBounds[d]);
      // Get location of source pixel data
      screenData[d] =
        ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    }
  }

  weight = 257 - fade; // 'Weighting factor' for new frame vs. old
  j      = 6;          // Serial led data follows header / magic word

  // This computes a single pixel value filtered down from a rectangular
  // section of the screen.  While it would seem tempting to use the native
  // image scaling in Processing/Java, in practice this didn't look very
  // good -- either too pixelated or too blurry, no happy medium.  So
  // instead, a "manual" downsampling is done here.  In the interest of
  // speed, it doesn't actually sample every pixel within a block, just
  // a selection of 256 pixels spaced within the block...the results still
  // look reasonably smooth and are handled quickly enough for video.

  for(i=0; i<leds.length; i++) {  // For each LED...
    d = leds[i][0]; // Corresponding display index
    if(useFullScreenCaps == true) {
      // Get location of source data from prior full-screen capture:
      pxls = screenData[d];
    } else {
      // Capture section of screen (LED bounds rect) and locate data::
      img  = bot[d].createScreenCapture(ledBounds[i]);
      pxls = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    }
    offs = pixelOffset[i];
    rb = r = g = b= 0;     // rgb variablen
    for(o=0; o<256; o++) {
      c   = pxls[offs[o]];
      //rb += c & 0x00ff00ff; // Bit trickery: R+B can accumulate in one var
      r += c & 0x000000ff; // R with B value
      g  += c & 0x0000ff00;
      b += c & 0x00ff0000; //B with R value
    }

    // Blend new pixel value with the value from the prior frame
    ledColor[i][0]  = (short)((((r >> 8) & 0xff) * weight +       //8 instead of 24
                               prevColor[i][0]     * fade) >> 8);
    ledColor[i][1]  = (short)(((( g >> 16) & 0xff) * weight +
                               prevColor[i][1]     * fade) >> 8);
    ledColor[i][2]  = (short)((((b >>  24) & 0xff) * weight +
                               prevColor[i][2]     * fade) >> 8); //24 instead of 8

    // Boost pixels that fall below the minimum brightness
    sum = ledColor[i][0] + ledColor[i][1] + ledColor[i][2];
    if(sum < minBrightness) {
      if(sum == 0) { // To avoid divide-by-zero
        deficit = minBrightness / 3; // Spread equally to R,G,B
        ledColor[i][0] += deficit;
        ledColor[i][1] += deficit;
        ledColor[i][2] += deficit;
      } else {
        deficit = minBrightness - sum;
        s2      = sum * 2;
        // Spread the "brightness deficit" back into R,G,B in proportion to
        // their individual contribition to that deficit.  Rather than simply
        // boosting all pixels at the low end, this allows deep (but saturated)
        // colors to stay saturated...they don't "pink out."
        ledColor[i][0] += deficit * (sum - ledColor[i][0]) / s2;
        ledColor[i][1] += deficit * (sum - ledColor[i][1]) / s2;
        ledColor[i][2] += deficit * (sum - ledColor[i][2]) / s2;
      }
    }

    // Apply gamma curve and place in serial output buffer
    serialData[j++] = gamma[ledColor[i][0]][0];
    serialData[j++] = gamma[ledColor[i][1]][1];
    serialData[j++] = gamma[ledColor[i][2]][2];
    // Update pixels in preview image
    preview[d].pixels[leds[i][2] * displays[d][1] + leds[i][1]] =
     (ledColor[i][0] << 16) | (ledColor[i][1] << 8) | ledColor[i][2];
  }

  if(port != null) port.write(serialData); // Issue data to Arduino

  // Show live preview image(s)
  scale(pixelSize);
  for(i=d=0; d<nDisplays; d++) {
    preview[d].updatePixels();
    image(preview[d], i, 0);
    i += displays[d][1] + 1;
  }

  println(frameRate); // How are we doing?

  // Copy LED color data to prior frame array for next pass
  arraycopy(ledColor, 0, prevColor, 0, ledColor.length);
}


// CLEANUP -------------------------------------------------------------------

// The DisposeHandler is called on program exit (but before the Serial library
// is shutdown), in order to turn off the LEDs (reportedly more reliable than
// stop()).  Seems to work for the window close box and escape key exit, but
// not the 'Quit' menu option.  Thanks to phi.lho in the Processing forums.

public class DisposeHandler {
  DisposeHandler(PApplet pa) {
    pa.registerDispose(this);
  }
  public void dispose() {
    // Fill serialData (after header) with 0's, and issue to Arduino...
//    Arrays.fill(serialData, 6, serialData.length, (byte)0);
    java.util.Arrays.fill(serialData, 6, serialData.length, (byte)0);
    if(port != null) port.write(serialData);
  }
}




Freitag, 1. Februar 2013

Openelec Boblight (Ambilight)

Quellen:
http://openelec.tv/forum/44-my-openelec-setup-and-cool-things-it-can-do/21026-ambient-lighting-setup-ambient-background-lighting-for-your-home-theater
(kurzform auch in Wiki)

--> Rename boblight.conf.sample to boblight.conf and edit to suit your configuration.
Channels = LEDs * 3
http://passion-xbmc.org/sous-linux/%28tuto%29-installation-ambitv-sous-openelec-tv/



100LEDs front-view














boblight.conf für 100LEDs:
--------------------------------------------------------------------------------------------------------

[global]
interface       127.0.0.1
port            19333


[device]
name            ambilight
type            momo
output          /dev/ttyACM0
channels        300 #c'est le nombre de LED multiplié par 3. Dans cette exemple 75 = 25Ledx3
prefix            41 64 61 00 63 36
interval        10000
rate            115200
debug           off #turn this on to see what it's doing with the serial port
delayafteropen    1000000

[color]
name            red
rgb             0000FF
#rgb             FF0000
adjust            0.7
gamma           1.0

[color]
name            green
rgb             00FF00
adjust            1.0
gamma           1.0

[color]
name            blue
rgb             FF0000
#rgb             0000FF
adjust            1.0
gamma           1.0
[light]
name            1
color           red     ambilight 1
color           green   ambilight 2
color           blue    ambilight 3
hscan           48.39 51.61
vscan           95.24 100

[light]
name            2
color           red     ambilight 4
color           green   ambilight 5
color           blue    ambilight 6
hscan           45.16 48.38
vscan           95.24 100

[light]
name            3
color           red     ambilight 7
color           green   ambilight 8
color           blue    ambilight 9
hscan           41.93 45.15
vscan           95.24 100

[light]
name            4
color           red     ambilight 10
color           green   ambilight 11
color           blue    ambilight 12
hscan           38.7 41.92
vscan           95.24 100

[light]
name            5
color           red     ambilight 13
color           green   ambilight 14
color           blue    ambilight 15
hscan           35.47 38.69
vscan           95.24 100

[light]
name            6
color           red     ambilight 16
color           green   ambilight 17
color           blue    ambilight 18
hscan           32.24 35.47
vscan           95.24 100

[light]
name            7
color           red     ambilight 19
color           green   ambilight 20
color           blue    ambilight 21
hscan           29.01 32.24
vscan           95.24 100

[light]
name            8
color           red     ambilight 22
color           green   ambilight 23
color           blue    ambilight 24
hscan           25.78 29.01
vscan           95.24 100

[light]
name            9
color           red     ambilight 25
color           green   ambilight 26
color           blue    ambilight 27
hscan           22.55 25.78
vscan           95.24 100

[light]
name            10
color           red     ambilight 28
color           green   ambilight 29
color           blue    ambilight 30
hscan           19.38 22.6
vscan           95.24 100

[light]
name            11
color           red     ambilight 31
color           green   ambilight 32
color           blue    ambilight 33
hscan           16.15 19.37
vscan           95.24 100

[light]
name            12
color           red     ambilight 34
color           green   ambilight 35
color           blue    ambilight 36
hscan           12.92 16.14
vscan           95.24 100

[light]
name            13
color           red     ambilight 37
color           green   ambilight 38
color           blue    ambilight 39
hscan           9.69 12.91
vscan           95.24 100

[light]
name            14
color           red     ambilight 40
color           green   ambilight 41
color           blue    ambilight 42
hscan           6.46 9.68
vscan           95.24 100

[light]
name            15
color           red     ambilight 43
color           green   ambilight 44
color           blue    ambilight 45
hscan           3.23 6.46
vscan           95.24 100

[light]
name            16
color           red     ambilight 46
color           green   ambilight 47
color           blue    ambilight 48
hscan           0 3.23
vscan           95.24 100

[light]
name            17
color           red     ambilight 49
color           green   ambilight 50
color           blue    ambilight 51
hscan           0 3.23
vscan           90.48 95.24

[light]
name            18
color           red     ambilight 52
color           green   ambilight 53
color           blue    ambilight 54
hscan           0 3.23
vscan           85.71 90.48

[light]
name            19
color           red     ambilight 55
color           green   ambilight 56
color           blue    ambilight 57
hscan           0 3.23
vscan           80.95 85.71

[light]
name            20
color           red     ambilight 58
color           green   ambilight 59
color           blue    ambilight 60
hscan           0 3.23
vscan           76.19 80.95

[light]
name            21
color           red     ambilight 61
color           green   ambilight 62
color           blue    ambilight 63
hscan           0 3.23
vscan           71.43 76.19

[light]
name            22
color           red     ambilight 64
color           green   ambilight 65
color           blue    ambilight 66
hscan           0 3.23
vscan           66.67 71.43

[light]
name            23
color           red     ambilight 67
color           green   ambilight 68
color           blue    ambilight 69
hscan           0 3.23
vscan           61.9 66.67

[light]
name            24
color           red     ambilight 70
color           green   ambilight 71
color           blue    ambilight 72
hscan           0 3.23
vscan           57.14 61.9

[light]
name            25
color           red     ambilight 73
color           green   ambilight 74
color           blue    ambilight 75
hscan           0 3.23
vscan           52.38 57.14

[light]
name            26
color           red     ambilight 76
color           green   ambilight 77
color           blue    ambilight 78
hscan           0 3.23
vscan           47.62 52.38

[light]
name            27
color           red     ambilight 79
color           green   ambilight 80
color           blue    ambilight 81
hscan           0 3.23
vscan           42.86 47.62

[light]
name            28
color           red     ambilight 82
color           green   ambilight 83
color           blue    ambilight 84
hscan           0 3.23
vscan           38.09 42.86

[light]
name            29
color           red     ambilight 85
color           green   ambilight 86
color           blue    ambilight 87
hscan           0 3.23
vscan           33.33 38.09

[light]
name            30
color           red     ambilight 88
color           green   ambilight 89
color           blue    ambilight 90
hscan           0 3.23
vscan           28.57 33.33

[light]
name            31
color           red     ambilight 91
color           green   ambilight 92
color           blue    ambilight 93
hscan           0 3.23
vscan           23.81 28.57

[light]
name            32
color           red     ambilight 94
color           green   ambilight 95
color           blue    ambilight 96
hscan           0 3.23
vscan           19.05 23.81

[light]
name            33
color           red     ambilight 97
color           green   ambilight 98
color           blue    ambilight 99
hscan           0 3.23
vscan           14.28 19.05

[light]
name            34
color           red     ambilight 100
color           green   ambilight 101
color           blue    ambilight 102
hscan           0 3.23
vscan           9.52 14.28

[light]
name            35
color           red     ambilight 103
color           green   ambilight 104
color           blue    ambilight 105
hscan           0 3.23
vscan           4.76 9.52

[light]
name            36
color           red     ambilight 106
color           green   ambilight 107
color           blue    ambilight 108
hscan           0 3.23
vscan           0 4.76

[light]
name            37
color           red     ambilight 109
color           green   ambilight 110
color           blue    ambilight 111
hscan           3.23 6.45
vscan           0 4.76

[light]
name            38
color           red     ambilight 112
color           green   ambilight 113
color           blue    ambilight 114
hscan           6.45 9.68
vscan           0 4.76

[light]
name            39
color           red     ambilight 115
color           green   ambilight 116
color           blue    ambilight 117
hscan           9.68 12.9
vscan           0 4.76

[light]
name            40
color           red     ambilight 118
color           green   ambilight 119
color           blue    ambilight 120
hscan           12.9 16.13
vscan           0 4.76

[light]
name            41
color           red     ambilight 121
color           green   ambilight 122
color           blue    ambilight 123
hscan           16.13 19.36
vscan           0 4.76

[light]
name            42
color           red     ambilight 124
color           green   ambilight 125
color           blue    ambilight 126
hscan           19.36 22.58
vscan           0 4.76

[light]
name            43
color           red     ambilight 127
color           green   ambilight 128
color           blue    ambilight 129
hscan           22.58 25.81
vscan           0 4.76

[light]
name            44
color           red     ambilight 130
color           green   ambilight 131
color           blue    ambilight 132
hscan           25.81 29.03
vscan           0 4.76

[light]
name            45
color           red     ambilight 133
color           green   ambilight 134
color           blue    ambilight 135
hscan           29.03 32.26
vscan           0 4.76

[light]
name            46
color           red     ambilight 136
color           green   ambilight 137
color           blue    ambilight 138
hscan           32.26 35.49
vscan           0 4.76

[light]
name            47
color           red     ambilight 139
color           green   ambilight 140
color           blue    ambilight 141
hscan           35.49 38.71
vscan           0 4.76

[light]
name            48
color           red     ambilight 142
color           green   ambilight 143
color           blue    ambilight 144
hscan           38.71 41.94
vscan           0 4.76

[light]
name            49
color           red     ambilight 145
color           green   ambilight 146
color           blue    ambilight 147
hscan           41.94 45.16
vscan           0 4.76

[light]
name            50
color           red     ambilight 148
color           green   ambilight 149
color           blue    ambilight 150
hscan           45.16 48.39
vscan           0 4.76

[light]
name            51
color           red     ambilight 151
color           green   ambilight 152
color           blue    ambilight 153
hscan           48.39 51.62
vscan           0 4.76

[light]
name            52
color           red     ambilight 154
color           green   ambilight 155
color           blue    ambilight 156
hscan           51.62 54.84
vscan           0 4.76

[light]
name            53
color           red     ambilight 157
color           green   ambilight 158
color           blue    ambilight 159
hscan           54.84 58.07
vscan           0 4.76

[light]
name            54
color           red     ambilight 160
color           green   ambilight 161
color           blue    ambilight 162
hscan           58.07 61.29
vscan           0 4.76

[light]
name            55
color           red     ambilight 163
color           green   ambilight 164
color           blue    ambilight 165
hscan           61.29 64.52
vscan           0 4.76

[light]
name            56
color           red     ambilight 166
color           green   ambilight 167
color           blue    ambilight 168
hscan           64.52 67.75
vscan           0 4.76

[light]
name            57
color           red     ambilight 169
color           green   ambilight 170
color           blue    ambilight 171
hscan           67.75 70.97
vscan           0 4.76

[light]
name            58
color           red     ambilight 172
color           green   ambilight 173
color           blue    ambilight 174
hscan           70.97 74.2
vscan           0 4.76

[light]
name            59
color           red     ambilight 175
color           green   ambilight 176
color           blue    ambilight 177
hscan           74.2 77.43
vscan           0 4.76

[light]
name            60
color           red     ambilight 178
color           green   ambilight 179
color           blue    ambilight 180
hscan           77.43 80.65
vscan           0 4.76

[light]
name            61
color           red     ambilight 181
color           green   ambilight 182
color           blue    ambilight 183
hscan           80.65 83.88
vscan           0 4.76

[light]
name            62
color           red     ambilight 184
color           green   ambilight 185
color           blue    ambilight 186
hscan           83.88 87.1
vscan           0 4.76

[light]
name            63
color           red     ambilight 187
color           green   ambilight 188
color           blue    ambilight 189
hscan           87.1 90.33
vscan           0 4.76

[light]
name            64
color           red     ambilight 190
color           green   ambilight 191
color           blue    ambilight 192
hscan           90.33 93.56
vscan           0 4.76

[light]
name            65
color           red     ambilight 193
color           green   ambilight 194
color           blue    ambilight 195
hscan           93.56 96.78
vscan           0 4.76

[light]
name            66
color           red     ambilight 196
color           green   ambilight 197
color           blue    ambilight 198
hscan           96.77 100
vscan           0 4.76

[light]
name            67
color           red     ambilight 199
color           green   ambilight 200
color           blue    ambilight 201
hscan           96.77 100
vscan           4.76 9.52

[light]
name            68
color           red     ambilight 202
color           green   ambilight 203
color           blue    ambilight 204
hscan           96.77 100
vscan           9.52 14.29

[light]
name            69
color           red     ambilight 205
color           green   ambilight 206
color           blue    ambilight 207
hscan           96.77 100
vscan           14.29 19.05

[light]
name            70
color           red     ambilight 208
color           green   ambilight 209
color           blue    ambilight 210
hscan           96.77 100
vscan           19.05 23.81

[light]
name            71
color           red     ambilight 211
color           green   ambilight 212
color           blue    ambilight 213
hscan           96.77 100
vscan           23.81 28.57

[light]
name            72
color           red     ambilight 214
color           green   ambilight 215
color           blue    ambilight 216
hscan           96.77 100
vscan           28.57 33.33

[light]
name            73
color           red     ambilight 217
color           green   ambilight 218
color           blue    ambilight 219
hscan           96.77 100
vscan           33.33 38.1

[light]
name            74
color           red     ambilight 220
color           green   ambilight 221
color           blue    ambilight 222
hscan           96.77 100
vscan           38.1 42.86

[light]
name            75
color           red     ambilight 223
color           green   ambilight 224
color           blue    ambilight 225
hscan           96.77 100
vscan           42.86 47.62

[light]
name            76
color           red     ambilight 226
color           green   ambilight 227
color           blue    ambilight 228
hscan           96.77 100
vscan           47.62 52.38

[light]
name            77
color           red     ambilight 229
color           green   ambilight 230
color           blue    ambilight 231
hscan           96.77 100
vscan           52.38 57.14

[light]
name            78
color           red     ambilight 232
color           green   ambilight 233
color           blue    ambilight 234
hscan           96.77 100
vscan           57.14 61.91

[light]
name            79
color           red     ambilight 235
color           green   ambilight 236
color           blue    ambilight 237
hscan           96.77 100
vscan           61.91 66.67

[light]
name            80
color           red     ambilight 238
color           green   ambilight 239
color           blue    ambilight 240
hscan           96.77 100
vscan           66.67 71.43

[light]
name            81
color           red     ambilight 241
color           green   ambilight 242
color           blue    ambilight 243
hscan           96.77 100
vscan           71.43 76.19

[light]
name            82
color           red     ambilight 244
color           green   ambilight 245
color           blue    ambilight 246
hscan           96.77 100
vscan           76.19 80.95

[light]
name            83
color           red     ambilight 247
color           green   ambilight 248
color           blue    ambilight 249
hscan           96.77 100
vscan           80.95 85.72

[light]
name            84
color           red     ambilight 250
color           green   ambilight 251
color           blue    ambilight 252
hscan           96.77 100
vscan           85.72 90.48

[light]
name            85
color           red     ambilight 253
color           green   ambilight 254
color           blue    ambilight 255
hscan           96.77 100
vscan           90.48 95.24

[light]
name            86
color           red     ambilight 256
color           green   ambilight 257
color           blue    ambilight 258
hscan           96.77 100
vscan           95.24 100

[light]
name            87
color           red     ambilight 259
color           green   ambilight 260
color           blue    ambilight 261
hscan           93.55 96.77
vscan           95.24 100

[light]
name            88
color           red     ambilight 262
color           green   ambilight 263
color           blue    ambilight 264
hscan           90.32 93.55
vscan           95.24 100

[light]
name            89
color           red     ambilight 265
color           green   ambilight 266
color           blue    ambilight 267
hscan           87.1 90.32
vscan           95.24 100

[light]
name            90
color           red     ambilight 268
color           green   ambilight 269
color           blue    ambilight 270
hscan           83.87 87.1
vscan           95.24 100

[light]
name            91
color           red     ambilight 271
color           green   ambilight 272
color           blue    ambilight 273
hscan           80.64 83.87
vscan           95.24 100

[light]
name            92
color           red     ambilight 274
color           green   ambilight 275
color           blue    ambilight 276
hscan           77.42 80.64
vscan           95.24 100

[light]
name            93
color           red     ambilight 277
color           green   ambilight 278
color           blue    ambilight 279
hscan           74.19 77.42
vscan           95.24 100

[light]
name            94
color           red     ambilight 280
color           green   ambilight 281
color           blue    ambilight 282
hscan           70.97 74.19
vscan           95.24 100

[light]
name            95
color           red     ambilight 283
color           green   ambilight 284
color           blue    ambilight 285
hscan           67.74 70.97
vscan           95.24 100

[light]
name            96
color           red     ambilight 286
color           green   ambilight 287
color           blue    ambilight 288
hscan           64.51 67.74
vscan           95.24 100

[light]
name            97
color           red     ambilight 289
color           green   ambilight 290
color           blue    ambilight 291
hscan           61.29 64.51
vscan           95.24 100

[light]
name            98
color           red     ambilight 292
color           green   ambilight 293
color           blue    ambilight 294
hscan           58.06 61.29
vscan           95.24 100

[light]
name            99
color           red     ambilight 295
color           green   ambilight 296
color           blue    ambilight 297
hscan           54.84 58.06
vscan           95.24 100

[light]
name            100
color           red     ambilight 298
color           green   ambilight 299
color           blue    ambilight 300
hscan           51.61 54.84
vscan           95.24 100



###################################################################

Arduino-Sketch:

--------------------------------------------------------------------

// Arduino "bridge" code between host computer and WS2801-based digital
// RGB LED pixels (e.g. Adafruit product ID #322).  Intended for use
// with USB-native boards such as Teensy or Adafruit 32u4 Breakout;
// works on normal serial Arduinos, but throughput is severely limited.
// LED data is streamed, not buffered, making this suitable for larger
// installations (e.g. video wall, etc.) than could otherwise be held
// in the Arduino's limited RAM.

// Some effort is put into avoiding buffer underruns (where the output
// side becomes starved of data).  The WS2801 latch protocol, being
// delay-based, could be inadvertently triggered if the USB bus or CPU
// is swamped with other tasks.  This code buffers incoming serial data
// and introduces intentional pauses if there's a threat of the buffer
// draining prematurely.  The cost of this complexity is somewhat
// reduced throughput, the gain is that most visual glitches are
// avoided (though ultimately a function of the load on the USB bus and
// host CPU, and out of our control).

// LED data and clock lines are connected to the Arduino's SPI output.
// On traditional Arduino boards, SPI data out is digital pin 11 and
// clock is digital pin 13.  On both Teensy and the 32u4 Breakout,
// data out is pin B2, clock is B1.  LEDs should be externally
// powered -- trying to run any more than just a few off the Arduino's
// 5V line is generally a Bad Idea.  LED ground should also be
// connected to Arduino ground.

// --------------------------------------------------------------------
//   This file is part of Adalight.

//   Adalight is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as
//   published by the Free Software Foundation, either version 3 of
//   the License, or (at your option) any later version.

//   Adalight is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.

//   You should have received a copy of the GNU Lesser General Public
//   License along with Adalight.  If not, see
//   <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------

#include <SPI.h>

// LED pin for Adafruit 32u4 Breakout Board:
//#define LED_DDR  DDRE
//#define LED_PORT PORTE
//#define LED_PIN  _BV(PORTE6)
// LED pin for Teensy:
//#define LED_DDR  DDRD
//#define LED_PORT PORTD
//#define LED_PIN  _BV(PORTD6)
// LED pin for Arduino:
#define LED_DDR  DDRB
#define LED_PORT PORTB
#define LED_PIN  _BV(PORTB5)

// A 'magic word' (along with LED count & checksum) precedes each block
// of LED data; this assists the microcontroller in syncing up with the
// host-side software and properly issuing the latch (host I/O is
// likely buffered, making usleep() unreliable for latch).  You may see
// an initial glitchy frame or two until the two come into alignment.
// The magic word can be whatever sequence you like, but each character
// should be unique, and frequent pixel values like 0 and 255 are
// avoided -- fewer false positives.  The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55).  LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.

static const uint8_t magic[] = {'A','d','a'};
#define MAGICSIZE  sizeof(magic)
#define HEADERSIZE (MAGICSIZE + 3)

#define MODE_HEADER 0
#define MODE_HOLD   1
#define MODE_DATA   2

// If no serial data is received for a while, the LEDs are shut off
// automatically.  This avoids the annoying "stuck pixel" look when
// quitting LED display programs on the host computer.
static const unsigned long serialTimeout = 15000; // 15 seconds

void setup()
{
  // Dirty trick: the circular buffer for serial data is 256 bytes,
  // and the "in" and "out" indices are unsigned 8-bit types -- this
  // much simplifies the cases where in/out need to "wrap around" the
  // beginning/end of the buffer.  Otherwise there'd be a ton of bit-
  // masking and/or conditional code every time one of these indices
  // needs to change, slowing things down tremendously.
  uint8_t
    buffer[256],
    indexIn       = 0,
    indexOut      = 0,
    mode          = MODE_HEADER,
    hi, lo, chk, i, spiFlag;
  int16_t
    bytesBuffered = 0,
    hold          = 0,
    c;
  int32_t
    bytesRemaining;
  unsigned long
    startTime,
    lastByteTime,
    lastAckTime,
    t;

  LED_DDR  |=  LED_PIN; // Enable output for LED
  LED_PORT &= ~LED_PIN; // LED off

  Serial.begin(115200); // Teensy/32u4 disregards baud rate; is OK!

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz max, else flicker

  // Issue test pattern to LEDs on startup.  This helps verify that
  // wiring between the Arduino and LEDs is correct.  Not knowing the
  // actual number of LEDs connected, this sets all of them (well, up
  // to the first 25,000, so as not to be TOO time consuming) to red,
  // green, blue, then off.  Once you're confident everything is working
  // end-to-end, it's OK to comment this out and reprogram the Arduino.
  uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 };
  for(char n=3; n>=0; n--) {
    for(c=0; c<25000; c++) {
      for(i=0; i<3; i++) {
        for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); );
      }
    }
    delay(1); // One millisecond pause = latch
  }

  Serial.print("Ada\n"); // Send ACK string to host

  startTime    = micros();
  lastByteTime = lastAckTime = millis();

  // loop() is avoided as even that small bit of function overhead
  // has a measurable impact on this code's overall throughput.

  for(;;) {

    // Implementation is a simple finite-state machine.
    // Regardless of mode, check for serial input each time:
    t = millis();
    if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
      buffer[indexIn++] = c;
      bytesBuffered++;
      lastByteTime = lastAckTime = t; // Reset timeout counters
    } else {
      // No data received.  If this persists, send an ACK packet
      // to host once every second to alert it to our presence.
      if((t - lastAckTime) > 1000) {
        Serial.print("Ada\n"); // Send ACK string to host
        lastAckTime = t; // Reset counter
      }
      // If no data received for an extended time, turn off all LEDs.
      if((t - lastByteTime) > serialTimeout) {
        for(c=0; c<32767; c++) {
          for(SPDR=0; !(SPSR & _BV(SPIF)); );
        }
        delay(1); // One millisecond pause = latch
        lastByteTime = t; // Reset counter
      }
    }

    switch(mode) {

     case MODE_HEADER:

      // In header-seeking mode.  Is there enough data to check?
      if(bytesBuffered >= HEADERSIZE) {
        // Indeed.  Check for a 'magic word' match.
        for(i=0; (i<MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
        if(i == MAGICSIZE) {
          // Magic word matches.  Now how about the checksum?
          hi  = buffer[indexOut++];
          lo  = buffer[indexOut++];
          chk = buffer[indexOut++];
          if(chk == (hi ^ lo ^ 0x55)) {
            // Checksum looks valid.  Get 16-bit LED count, add 1
            // (# LEDs is always > 0) and multiply by 3 for R,G,B.
            bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
            bytesBuffered -= 3;
            spiFlag        = 0;         // No data out yet
            mode           = MODE_HOLD; // Proceed to latch wait mode
          } else {
            // Checksum didn't match; search resumes after magic word.
            indexOut  -= 3; // Rewind
          }
        } // else no header match.  Resume at first mismatched byte.
        bytesBuffered -= i;
      }
      break;

     case MODE_HOLD:

      // Ostensibly "waiting for the latch from the prior frame
      // to complete" mode, but may also revert to this mode when
      // underrun prevention necessitates a delay.

      if((micros() - startTime) < hold) break; // Still holding; keep buffering

      // Latch/delay complete.  Advance to data-issuing mode...
      LED_PORT &= ~LED_PIN;  // LED off
      mode      = MODE_DATA; // ...and fall through (no break):

     case MODE_DATA:

      while(spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
      if(bytesRemaining > 0) {
        if(bytesBuffered > 0) {
          SPDR = buffer[indexOut++];   // Issue next byte
          bytesBuffered--;
          bytesRemaining--;
          spiFlag = 1;
        }
        // If serial buffer is threatening to underrun, start
        // introducing progressively longer pauses to allow more
        // data to arrive (up to a point).
        if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) {
          startTime = micros();
          hold      = 100 + (32 - bytesBuffered) * 10;
          mode      = MODE_HOLD;
    }
      } else {
        // End of data -- issue latch:
        startTime  = micros();
        hold       = 1000;        // Latch duration = 1000 uS
        LED_PORT  |= LED_PIN;     // LED on
        mode       = MODE_HEADER; // Begin next header search
      }
    } // end switch
  } // end for(;;)
}

void loop()
{
  // Not used.  See note in setup() function.
}


###############################################################
 Blinkende LEDS (Lösung by "wicht" aus OE-Forum)
http://openelec.tv/forum/85-boblightd/2679-boblight?start=300

----------------------------------------------------------------------------------------------------------
login via ssh
cd /
nano /storage/.xbmc/addons/service.multimedia.boblightd/bin/boblightd.start
----------------------------------------------------------------------------------------------------------

Edit the file
/storage/.xbmc/addons/service.multimedia.boblightd/bin/boblightd.start

On the bottom of the file there is a line that starts with "boblight-X11". This is the application that sends the stuff on the screen to boblightd. I don't know the original content of the line, but my line looks like
boblight-X11 -x -i 0.3 -o speed=50.0 >> $LOG_FILE 2>&1

I think the "-x" is the thing that removes the flickering. I read in the boblight sources that "-x" is also slower than the normal approach, but I cannot tell. Either my HTPC is too fast or the difference is not noticeable.

Be careful: If the boblight-Addon get's updated, your change will be reverted. So copy it to another location as a back up in case you need to restore it.

Another thing: Of course this only works if you are using boblight-X11. Using the other solution (that sends only XBMC's graphic output info to boblightd) this will not work.