Processing Ambient Light Sensor Library

Based on Amit Singh experiments with the »Ambient Light Sensor« I developed a JNI (Java Native Interface) for reading the sensor values.

This sensor is built-in in every MacBookPro and is intended for adjusting the keyboards and displays brightness depending on the lighting conditions. The sensors are located under both speaker covers.

Download the Processing-Library lmu.zip and unzip it to the “libraries” folder of your Processing installation. The source code is included in the “src” folder.

methods:

// both sensor values in an array
public static int[] getLMUArray();
 
// left sensor value
public static int getLMULeft();
 
// right sensor value
public static int getLMURight();

example:

import lmu.*; 
 
int lmu_left;
int lmu_right;
float multi;
 
void setup()
{
  size(800,800);
  frameRate(20);
 
  // initial sensor values
  int[] lmu_start = LmuTracker.getLMUArray();
  lmu_left  = lmu_start[0];
  lmu_right = lmu_start[1];
  multi = 255.0 / (lmu_left);
} 
 
void draw()
{
  // get current sensor values
  int[] vals = LmuTracker.getLMUArray();
  int li = (int)(vals[0] * multi);
  int re = (int)(vals[1] * multi);
 
  background(255);
 
  // left sensor
  fill(li);
  rect(0, 0, width/2, height);
 
  // right sensor
  fill(re);
  rect(width/2, 0, width/2, height);
}

Download Processing Library (lmu.zip)
Download Processing Development Environment


Update 03.12.2008
http://blog.formatlos.de/2008/12/03/ambientlightsensor-updated/



One Response (Add Your Comment)

Trackbacks:

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Other Entries

About

Martin Rädlinger is an Interactive Developer & Designer. He specializes in interactive coding predominantly with ActionScript, but every new challenge is welcome. If you like his work feel free to get in touch with him. At the moment he's available for freelance work.

Contact

Martin Rädlinger
mail: mr [at] formatlos.de
web: www.formatlos.de
xing: Martin Rädlinger
linkedin: Martin Rädlinger
skype: martinraedlinger