ltest.py 607 Bytes
Newer Older
Federico Meloda's avatar
Federico Meloda committed
1 2 3 4 5 6 7 8
#!/usr/bin/env python3

from time import sleep
from random import randint

import spidev
import ws2812

Federico Meloda's avatar
Federico Meloda committed
9 10 11
c = 0
rand = 1

Federico Meloda's avatar
Federico Meloda committed
12 13

def get_color():
Federico Meloda's avatar
Federico Meloda committed
14 15 16 17 18 19 20 21
    global c
    global rand
    if c+rand > 80:
        rand = randint(1, 8)*(-1)
        return(80, 255, 0)
    elif c+rand < 0:
        rand = randint(1, 8)
        return(0, 255, 0)
Federico Meloda's avatar
Federico Meloda committed
22
    else:
Federico Meloda's avatar
Federico Meloda committed
23 24
        c = c + rand
        return (c, 255, 0)
Federico Meloda's avatar
Federico Meloda committed
25 26 27 28 29


def light_flame():
    spi = spidev.SpiDev()
    spi.open(1, 0)
Federico Meloda's avatar
Federico Meloda committed
30

Federico Meloda's avatar
Federico Meloda committed
31 32
    while True:
        ws2812.write2812(spi, [get_color() * 4])
Federico Meloda's avatar
Federico Meloda committed
33 34
        sleep(0.001)

Federico Meloda's avatar
Federico Meloda committed
35 36 37 38

def main():
    light_flame()

Federico Meloda's avatar
Federico Meloda committed
39

Federico Meloda's avatar
Federico Meloda committed
40 41
if __name__ == "__main__":
    main()