spacepaste

  1.  
  2. #Sample Code for Light Sensor Found at http://www.uugear.com/portfolio/using-light-sensor-module-with-raspberry-pi/
  3. import RPi.GPIO as GPIO
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setup(4,GPIO.IN)
  6. for i in range(0,5):
  7. print GPIO.input(4)
  8. #Im trying to use the light sensor to change the brightness in a script I have for a string of Ws2811x LEDs
  9. #Does the LED_BRIGHTNESS code make sense? I really have no idea what I'm doing.
  10. import urllib2
  11. import xml.etree.ElementTree as ET
  12. import time
  13. from neopixel import *
  14. import sys
  15. import os
  16. #Light Sensor Code
  17. import RPi.GPIO as GPIO
  18. GPIO.setmode(GPIO.BCM)
  19. GPIO.setup(4,GPIO.IN)
  20. # LED strip configuration:
  21. LED_COUNT = 95 # Number of LED pixels.
  22. LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
  23. #LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
  24. LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
  25. LED_DMA = 5 # DMA channel to use for generating signal (try 5)
  26. for i in range(0,5):
  27. print LED_BRIGHTNESS = 100 # Set to 0 for darkest and 255 for brightest
  28. for i in range(3,5):
  29. print LED_BRIGHTNESS = 255
  30. LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
  31. LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
  32. LED_STRIP = ws.WS2811_STRIP_GRB # Strip type and colour ordering
  33. strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)
  34. strip.begin()
  35.