#!/usr/bin/env python
from time import time, sleep
from math import sin, pi
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--colour", '-c', help ='integer 0-255 r,g,b', default="10,40,0")
parser.add_argument("--flash", '-f', help ='square wave (Hz)',
                    type=float)
parser.add_argument("--pulse", '-p', help ='sine wave (Hz)',
                    type=float)
parser.add_argument("--resolution", '-r', help ='updates per second',
                    default = 20.0, type=float)

args = parser.parse_args()

off = [0,0,0]
colours = {'orange': '80,40,0', 'red':'80,0,0', 'green':'10,40,0', 'blue':'0,0,80', 'white':'40,40,40'}

def cie1931(L):
    L = L*100.0/255.0
    if L <= 8:
        return (L/902.3)*255.0
    else:
        return ((L+16.0)/116.0)**3.0 *255.0

def set_led(colour):
    #print "set led to {}".format(colour)
    spi.write("".join(chr(int(i)) for i in colour))
    spi.flush()

with open("/dev/spidev0.0", 'w') as spi:
#if True:
    colour = colours.get(args.colour, args.colour)
    colour = [int(cie1931(float(c))) for c in colour.split(',')]
    set_led(colour)
    while args.flash:
        set_led(off)
        sleep(1.0/args.flash)
        set_led(colour)
        sleep(1.0/args.flash)
    while args.pulse:
        s = sin(2*pi*time()*args.pulse)
        s = (s+1.0)/2.0
        c = [i*s for i in colour]
        set_led(c)
        sleep(1.0/(args.resolution))


    		

add basic script