#!/usr/bin/python

# ===========================================================================
# Hatalogico KNIGHT RIDER for 8 LEDs - powered by Adafruit's Libraries
# -------------------------------------------------
# Date: 12/4/2015
# Author: <NAME>
#
# BIG THANKS TO ADAFRUIT INDUSTRIES FOR MAKING THIS POSSIBLE AND EASY
# ===========================================================================

import time, os, sys

# DETERMINE CURRENT PATH
scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))
os.chdir(scriptPath)
# APPEND FOLDER OF REQUIRED LIBRARY
sys.path.append("Adafruit/Adafruit_PWM_Servo_Driver")
# FINALLY LOAD THE LIBRARY
from Adafruit_PWM_Servo_Driver import PWM

LED_PIN_0 = 1
LED_PIN_1 = 3
LED_PIN_2 = 5
LED_PIN_3 = 7
LED_PIN_4 = 9
LED_PIN_5 = 11
LED_PIN_6 = 13
LED_PIN_7 = 15

BRIGHT_STEP_0=0
BRIGHT_STEP_1=2048
BRIGHT_STEP_2=3070
BRIGHT_STEP_3=3500
BRIGHT_STEP_4=3800
BRIGHT_STEP_5=4048
BRIGHT_STEP_6=4095
BRIGHT_STEP_7=4095

# BUILD 16 ARRAYS OF 8 POSITIONS/VALUES FOR PWM LOOP
position = {} 
position[0] = [ BRIGHT_STEP_0, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[1] = [ BRIGHT_STEP_0, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[2] = [ BRIGHT_STEP_0, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[3] = [ BRIGHT_STEP_0, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[4] = [ BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7 ]
position[5] = [ BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6 ]
position[6] = [ BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5 ]
position[7] = [ BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4 ]
position[8] = [ BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3 ]
position[9] = [ BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2 ]
position[10] = [ BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1 ]
position[11] = [ BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0 ]
position[12] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_0 ]
position[13] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_0 ]
position[14] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_0 ]
position[15] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_0 ]

# SETUP THE PWM DRIVER (I2C ADDRESS IS 70 BY DEFAULT ON HATALOGICO)
# EACH CHANNEL RANGES FROM 0 (off) TO 4095 (on)
pwm = PWM(0x70)
# SET FREQUENCY
pwm.setPWMFreq(120)

while (True):
	for posNo in range(0, 16, +1):
		pwm.setPWM(LED_PIN_0, 0, position[ posNo ][0])
		pwm.setPWM(LED_PIN_1, 0, position[ posNo ][1])
		pwm.setPWM(LED_PIN_2, 0, position[ posNo ][2])
		pwm.setPWM(LED_PIN_3, 0, position[ posNo ][3])
		pwm.setPWM(LED_PIN_4, 0, position[ posNo ][4])
		pwm.setPWM(LED_PIN_5, 0, position[ posNo ][5])
		pwm.setPWM(LED_PIN_6, 0, position[ posNo ][6])
		pwm.setPWM(LED_PIN_7, 0, position[ posNo ][7])
		
		# HAVE A LITTLE NAP
		time.sleep(0.05)

	for posNo in range(15, -1, -1):
		pwm.setPWM(LED_PIN_0, 0, position[ posNo ][0])
		pwm.setPWM(LED_PIN_1, 0, position[ posNo ][1])
		pwm.setPWM(LED_PIN_2, 0, position[ posNo ][2])
		pwm.setPWM(LED_PIN_3, 0, position[ posNo ][3])
		pwm.setPWM(LED_PIN_4, 0, position[ posNo ][4])
		pwm.setPWM(LED_PIN_5, 0, position[ posNo ][5])
		pwm.setPWM(LED_PIN_6, 0, position[ posNo ][6])
		pwm.setPWM(LED_PIN_7, 0, position[ posNo ][7])
		
		# HAVE A LITTLE NAP
		time.sleep(0.05)
#!/usr/bin/python

# ===========================================================================
# Hatalogico KNIGHT RIDER for 8 LEDs - powered by Adafruit's Libraries
# -------------------------------------------------
# Date: 12/4/2015
# Author: <NAME>
#
# BIG THANKS TO ADAFRUIT INDUSTRIES FOR MAKING THIS POSSIBLE AND EASY
# ===========================================================================

import time, os, sys

# DETERMINE CURRENT PATH
scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))
os.chdir(scriptPath)
# APPEND FOLDER OF REQUIRED LIBRARY
sys.path.append("Adafruit/Adafruit_PWM_Servo_Driver")
# FINALLY LOAD THE LIBRARY
from Adafruit_PWM_Servo_Driver import PWM

LED_PIN_0 = 1
LED_PIN_1 = 3
LED_PIN_2 = 5
LED_PIN_3 = 7
LED_PIN_4 = 9
LED_PIN_5 = 11
LED_PIN_6 = 13
LED_PIN_7 = 15

BRIGHT_STEP_0=0
BRIGHT_STEP_1=2048
BRIGHT_STEP_2=3070
BRIGHT_STEP_3=3500
BRIGHT_STEP_4=3800
BRIGHT_STEP_5=4048
BRIGHT_STEP_6=4095
BRIGHT_STEP_7=4095

# BUILD 16 ARRAYS OF 8 POSITIONS/VALUES FOR PWM LOOP
position = {} 
position[0] = [ BRIGHT_STEP_0, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[1] = [ BRIGHT_STEP_0, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[2] = [ BRIGHT_STEP_0, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[3] = [ BRIGHT_STEP_0, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7, BRIGHT_STEP_7 ]
position[4] = [ BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6, BRIGHT_STEP_7 ]
position[5] = [ BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5, BRIGHT_STEP_6 ]
position[6] = [ BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4, BRIGHT_STEP_5 ]
position[7] = [ BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3, BRIGHT_STEP_4 ]
position[8] = [ BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2, BRIGHT_STEP_3 ]
position[9] = [ BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1, BRIGHT_STEP_2 ]
position[10] = [ BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0, BRIGHT_STEP_1 ]
position[11] = [ BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_1, BRIGHT_STEP_0 ]
position[12] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_2, BRIGHT_STEP_0 ]
position[13] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_3, BRIGHT_STEP_0 ]
position[14] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_4, BRIGHT_STEP_0 ]
position[15] = [ BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_7, BRIGHT_STEP_6, BRIGHT_STEP_5, BRIGHT_STEP_0 ]

# SETUP THE PWM DRIVER (I2C ADDRESS IS 70 BY DEFAULT ON HATALOGICO)
# EACH CHANNEL RANGES FROM 0 (off) TO 4095 (on)
pwm = PWM(0x70)
# SET FREQUENCY
pwm.setPWMFreq(120)

while (True):
	for posNo in range(0, 16, +1):
		pwm.setPWM(LED_PIN_0, 0, position[ posNo ][0])
		pwm.setPWM(LED_PIN_1, 0, position[ posNo ][1])
		pwm.setPWM(LED_PIN_2, 0, position[ posNo ][2])
		pwm.setPWM(LED_PIN_3, 0, position[ posNo ][3])
		pwm.setPWM(LED_PIN_4, 0, position[ posNo ][4])
		pwm.setPWM(LED_PIN_5, 0, position[ posNo ][5])
		pwm.setPWM(LED_PIN_6, 0, position[ posNo ][6])
		pwm.setPWM(LED_PIN_7, 0, position[ posNo ][7])
		
		# HAVE A LITTLE NAP
		time.sleep(0.05)

	for posNo in range(15, -1, -1):
		pwm.setPWM(LED_PIN_0, 0, position[ posNo ][0])
		pwm.setPWM(LED_PIN_1, 0, position[ posNo ][1])
		pwm.setPWM(LED_PIN_2, 0, position[ posNo ][2])
		pwm.setPWM(LED_PIN_3, 0, position[ posNo ][3])
		pwm.setPWM(LED_PIN_4, 0, position[ posNo ][4])
		pwm.setPWM(LED_PIN_5, 0, position[ posNo ][5])
		pwm.setPWM(LED_PIN_6, 0, position[ posNo ][6])
		pwm.setPWM(LED_PIN_7, 0, position[ posNo ][7])
		
		# HAVE A LITTLE NAP
		time.sleep(0.05)
#!/usr/bin/python # =========================================================================== # Hatalogico KNIGHT RIDER for 8 LEDs - powered by Adafruit's Libraries # ------------------------------------------------- # Date: 12/4/2015 # Author: <NAME> # # BIG THANKS TO ADAFRUIT INDUSTRIES FOR MAKING THIS POSSIBLE AND EASY # =========================================================================== # DETERMINE CURRENT PATH # APPEND FOLDER OF REQUIRED LIBRARY # FINALLY LOAD THE LIBRARY # BUILD 16 ARRAYS OF 8 POSITIONS/VALUES FOR PWM LOOP # SETUP THE PWM DRIVER (I2C ADDRESS IS 70 BY DEFAULT ON HATALOGICO) # EACH CHANNEL RANGES FROM 0 (off) TO 4095 (on) # SET FREQUENCY # HAVE A LITTLE NAP # HAVE A LITTLE NAP