#!/usr/bin/env python

import time

#import the adxl345 and neopixel module
import adxl345
from neopixel import *


class Accelerometer(adxl345.ADXL345):

    g_range = {
        2: adxl345.RANGE_2G,
        4: adxl345.RANGE_4G,
        8: adxl345.RANGE_8G,
        16: adxl345.RANGE_16G,
    }

    def __init__(self, limit=2):
         super(Accelerometer, self).__init__()
         self.setRange(self.g_range.get(limit, 0))



class LightStrip(Adafruit_NeoPixel):

    def __init__(self, count, limit, pin=18):
        LED_COUNT   = count   # Number of LED pixels.
        LED_PIN     = pin     # GPIO pin connected to the pixels (must support PWM!).
        LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
        LED_DMA     = 5       # DMA channel to use for generating signal (try 5)
        LED_INVERT  = False   # True to invert the signal (when using NPN transistor level shift)

        self.limit = limit

        # Create NeoPixel object with appropriate configuration.    
        #Adafruit_NeoPixel.__init__(self, LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT)
        super(LightStrip, self).__init__(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT)

        # Intialize the library (must be called once before other functions).
        self.begin()

    def draw(self, axes):
        mod = 255 / float(self.limit)

        red = abs(int(axes['x']*mod))
        blue = abs(int(axes['y']*mod))
        green = abs(int(axes['z']*mod))
        color = Color(red, green, blue)

        self.set_color(self, color, bright)
        self.set_brightness(self, red+green+blue)
        self.show()

    # Define functions which animate LEDs in various ways.
    def set_color(self, color):
        """Wipe color across display a pixel at a time."""
        for i in range(self.numPixels()):
            self.setPixelColor(i, color)


    def set_brightness(self, bright):
        bright = 255 if bright > 255 else bright
        self.setBrightness(bright)


def main():
    LIMIT = 16

    #accel = ADXL345()
    accel = Accelerometer(LIMIT)
    #strip = get_strip(25)
    strip = LightStrip(25, LIMIT)

    print "Light Force Engage!: Ctrl-C to exit."
    

    while True:
        axes = accel.getAxes(True)
        strip.draw(axes)
        
if __name__ == "main":
    main()

@@ -15,16 +15,26 @@
  python%0A
+import sys
 %0Aimport 
@@ -669,258 +669,8 @@
     
-LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)%0A        LED_DMA     = 5       # DMA channel to use for generating signal (try 5)%0A        LED_INVERT  = False   # True to invert the signal (when using NPN transistor level shift)%0A
 %0A   
@@ -767,104 +767,8 @@
    %0A
-        #Adafruit_NeoPixel.__init__(self, LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT)%0A
     
@@ -826,42 +826,8 @@
 _PIN
-, LED_FREQ_HZ, LED_DMA, LED_INVERT
 )%0A%0A 
@@ -1138,21 +1138,66 @@
 ed, 
-green, blue)%0A
+blue, green)%0A        print %22%25s %25s %25s%22 %25 (red, blue, green)
 %0A   
@@ -1220,27 +1220,13 @@
 lor(
-self, color, bright
+color
 )%0A  
@@ -1251,22 +1251,16 @@
 ghtness(
-self, 
 red+gree
@@ -1573,31 +1573,44 @@
     
+if 
 bright 
-=
+%3E
  255
- if
+:%0A           
  bright 
 %3E 25
@@ -1609,25 +1609,65 @@
 ght 
-%3E
+=
  255
+%0A       
  el
-se
+if
  bright
+ %3C 20:%0A            bright = 20%0A 
 %0A   
@@ -1699,16 +1699,213 @@
 right)%0A%0A
+def display_status(status, count):%0A    if not count:%0A        sys.stdout.write(%22                                            %5Cr%22)%0A        sys.stdout.write(%22%25s%5Cr%22 %25 status)%0A        sys.stdout.flush()%0A
 %0Adef mai
@@ -1929,31 +1929,8 @@
 16%0A%0A
-    #accel = ADXL345()%0A
     
@@ -1962,35 +1962,8 @@
 IT)%0A
-    #strip = get_strip(25)%0A
     
@@ -2047,16 +2047,29 @@
 .%22%0A    %0A
+    count = 0
 %0A    whi
@@ -2124,33 +2124,132 @@
     
-strip.draw(axes)%0A        
+display_status(str(axes), count)%0A        strip.draw(axes)%0A        count += 1%0A        if count %3E 100:%0A            count = 0%0A%0A
 %0Aif 

Set min and max for brightness.