Created
February 12, 2015 08:53
-
-
Save MisterRager/97b9689d8399b154b7f7 to your computer and use it in GitHub Desktop.
apa102 demonstration on nodemcu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_frame = string.char( | |
0x00, 0x00, 0x00, 0x00 | |
) | |
end_frame = string.char( | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff | |
) | |
--color order is BGR | |
rainbow_pattern = string.char( | |
0xff, 0x00, 0x00, 0xff, | |
0xff, 0x00, 0xbb, 0xdd, | |
0xff, 0x00, 0xdd, 0xbb, | |
0xff, 0x00, 0xff, 0x00, | |
0xff, 0xbb, 0xdd, 0x00, | |
0xff, 0xdd, 0xbb, 0x00, | |
0xff, 0xff, 0x00, 0x00, | |
0xff, 0xdd, 0x00, 0xbb, | |
0xff, 0xbb, 0x00, 0xdd | |
) | |
rainbow_count = string.len(rainbow_pattern) | |
led_count = 150 | |
pin=8 | |
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0); | |
gpio.mode(pin, gpio.OUTPUT) | |
rainbows = (led_count * 4) / rainbow_count | |
partial_rainbow = rainbows % 1; | |
print( | |
spi.send( | |
1, | |
start_frame..string.rep( | |
rainbow_pattern, | |
rainbows - partial_rainbow | |
)..string.sub( | |
rainbow_pattern, | |
1, | |
partial_rainbow * rainbow_count | |
)..end_frame | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment