diff options
author | Jakob Stendahl <14180120+JakobST1n@users.noreply.github.com> | 2021-10-11 20:02:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 20:02:04 +0200 |
commit | c67531161e56488166a33232f87566309ba8676e (patch) | |
tree | 846e59a020e80bea48557d5a06af5728e44961ff /docs/Scripting | |
parent | e6880cd8ccf82d993f222cb14b4860581654acb8 (diff) | |
parent | c1b6eec770b885a9829e1f62bad5cc99389ca429 (diff) | |
download | Luxcena-Neo-c67531161e56488166a33232f87566309ba8676e.tar.gz Luxcena-Neo-c67531161e56488166a33232f87566309ba8676e.zip |
Merge pull request #24 from JakobST1n/rebuild
v1.0.0
Diffstat (limited to 'docs/Scripting')
-rw-r--r-- | docs/Scripting/Examples/strandtest.md | 90 | ||||
-rw-r--r-- | docs/Scripting/SupportLib/README.md | 130 |
2 files changed, 94 insertions, 126 deletions
diff --git a/docs/Scripting/Examples/strandtest.md b/docs/Scripting/Examples/strandtest.md deleted file mode 100644 index 89173d3..0000000 --- a/docs/Scripting/Examples/strandtest.md +++ /dev/null @@ -1,90 +0,0 @@ -# Strandtest - ---- -This script just does some fancy patterns to show of the neopixels' capabilities. -Runs in an endless loop, take a look at the code to see what it does more -precisely. - -```Python -import LuxcenaNeo as neo # Can be imported as LuxcenaNeo as well. but anything else and it will fail... -import time - -def colorWipe(color, wait_ms=50): - """Wipe color across display a pixel at a time.""" - for i in range(neo.strip.numPixels()): - neo.strip.setPixelColor(i, color) - neo.strip.show() - time.sleep(wait_ms/1000.0) - -def theaterChase(color, wait_ms=50, iterations=10): - """Movie theater light style chaser animation.""" - for j in range(iterations): - for q in range(3): - for i in range(0, neo.strip.numPixels(), 3): - neo.strip.setPixelColor(i+q, color) - neo.strip.show() - time.sleep(wait_ms/1000.0) - for i in range(0, neo.strip.numPixels(), 3): - neo.strip.setPixelColor(i+q, 0) - -def wheel(pos): - """Generate rainbow colors across 0-255 positions.""" - if pos < 85: - return neo.Color(pos * 3, 255 - pos * 3, 0) - elif pos < 170: - pos -= 85 - return neo.Color(255 - pos * 3, 0, pos * 3) - else: - pos -= 170 - return neo.Color(0, pos * 3, 255 - pos * 3) - -def rainbow(wait_ms=20, iterations=1): - """Draw rainbow that fades across all pixels at once.""" - for j in range(256*iterations): - for i in range(neo.strip.numPixels()): - neo.strip.setPixelColor(i, wheel((i+j) & 255)) - neo.strip.show() - time.sleep(wait_ms/1000.0) - -def rainbowCycle(wait_ms=20, iterations=5): - """Draw rainbow that uniformly distributes itself across all pixels.""" - for j in range(256*iterations): - for i in range(strip.numPixels()): - neo,strip.setPixelColor(i, wheel(((i * 256 / neo.strip.numPixels()) + j) & 255)) - neo.strip.show() - time.sleep(wait_ms/1000.0) - -def theaterChaseRainbow(wait_ms=50): - """Rainbow movie theater light style chaser animation.""" - for j in range(256): - for q in range(3): - for i in range(0, neo.strip.numPixels(), 3): - neo.strip.setPixelColor(i+q, wheel((i+j) % 255)) - neo.strip.show() - time.sleep(wait_ms/1000.0) - for i in range(0, neo.strip.numPixels(), 3): - neo.strip.setPixelColor(i+q, 0) - - -class Main(neo.NeoBehaviour): - - def onStart(self): - # Change the brightness of the strip - neo.strip.setBrightness(100) - - # Do an endless loop with some default neopixel test patterns - while True: - colorWipe(neo.Color(255, 0, 0)) # Red wipe - colorWipe(neo.Color(0, 255, 0)) # Blue wipe - colorWipe(neo.Color(0, 0, 255)) # Green wipe - - theaterChase(neo.Color(127, 127, 127)) # White theater chase - theaterChase(neo.Color(127, 0, 0)) # Red theater chase - theaterChase(neo.Color( 0, 0, 127)) # Blue theater chase - - rainbow() - rainbowCycle() - theaterChaseRainbow() - - -``` diff --git a/docs/Scripting/SupportLib/README.md b/docs/Scripting/SupportLib/README.md index 537a6ba..c2c7a99 100644 --- a/docs/Scripting/SupportLib/README.md +++ b/docs/Scripting/SupportLib/README.md @@ -1,66 +1,124 @@ # Support Library +The script/mode file has to contain a `Main` class, which is inherited from `NeoBehaviour` like this: +```python +from luxcena_neo import NeoBehaviour + +class Main(NeoBehaviour): + def on_start(self): + strip.setPixelColor(0, "#fafafa") + +``` +The `strip` will be available anywhere in your script whe it is started using `neo_runtime`. + +--- + +## `class` NeoBehaviour +This is the class your `Main` should inherit from. +This has some special methods that you can override. + +*NOTE:* Do not override `__init__` unless you know +what you are doing! This contains code that +is crucial for `neo_runtime`. + +### def declare_variables(`self`) +When the runtime executes this, the method `self.declare(Variable)` is available. This is where +you can add variables that show up in the UI. +Take a look at the `Variable` class further down on this site. + +### def on_start(`self`) +This is run once at the start of the program. This is a logical place +to initialize variables where you need to remember state, but you +don't want to put the variable in the UI. + +### def each_tick(self): +This will run as often as possible. If nothing else happens, it will run every one millisecond. + +### def each_second(self): +This will run at most once a second, it might be longer if some other function is doing some work that takes a long time (more that a second). + +### def each_minute(self): +This will run at most once a minute, it might be longer if some other function is doing some work that takes a long time (more that a minute). + +### def each_hour(self): +This will run at most once a hour, it might be longer if some other function is doing some work that takes a long time (more that a hour). + +### def each_day(self): +This will run at most once a day, it might be longer if some other function is doing some work that takes a long time (more that a day). + +### deltatime +For each of the `each_` methods, you can add a second argument to the +definition. If you do, that will be the time in seconds since last time +the function ran. +```python +def each_tick(self, dt): + print(dt) +def each_minute(self, deltatime): + print(dt) +``` +The name of the parameter doesn't matter. For the example above, +in an ideal world, this would print `0.1` every millisecond, and `60` every minute. Because the world isnt ideal, the deltatime is likely +going to be slightly longer than the ideal. + --- ## `class` Strip This is the object you are refeering to when you want to do things with LED's. You shouldn't have to do instantiate your own new strip-object as you can use the one set up by the software itself. -```python -LuxcenaNeo.strip -or -neo.strip -``` -### Strip.show() +### strip.show() Display all the changes made to the LEDs, on the actual LEDs. -### Strip.setPixelColor(`n`, `color`) +### strip.set_pixel_color(`n`, `*color`) Set LED at position n to the provided 24-bit color value (in RGB order). -### Strip.setPixelColorXY(`x`, `y`, `color`) +### strip.set_pixel_color_XY(`x`, `y`, `*color`) Set LED at position (x, y) in the defined matrix to the provided 24-bit color value (in RGB order). -### Strip.setPixelColorRGB(`n`, `red`, `green`, `blue`, `white = 0`) -Set LED at position n to the provided red, green, and blue color. -Each color component should be a value from 0 to 255 (where 0 is the -lowest intensity and 255 is the highest intensity). - -### Strip.setPixelColorXYRGB(`x`, `y`, `red`, `green`, `blue`, `white = 0`) -Set LED at position (x, y) in the defined matrix to the provided red, green, and blue color. -Each color component should be a value from 0 to 255 (where 0 is the -lowest intensity and 255 is the highest intensity). - -### Strip.setSegmentColorRGB(`segment`, `red`, `green`, `blue`, `white = 0`) +### strip.set_segment_color(`segment`, `*color`) Set a whole segment to the provided red, green and blue color. Each color component should be a value from 0 to 255 (where 0 is the lowest intensity and 255 is the highest intensity). -### Strip.setBrightness(`brightness`) -Scale each LED in the buffer by the provided brightness. A brightness -of 0 is the darkest and 255 is the brightest. - -### Strip.getBrightness(): -Get the brightness value for each LED in the buffer. A brightness -of 0 is the darkest and 255 is the brightest. - -### Strip.getPixels(): +### strip.get_pixels(): Return an object which allows access to the LED display data as if it were a sequence of 24-bit RGB values. -### Strip.numPixels(): +### strip.num_pixels(): Return the number of pixels in the display. -### Strip.getPixelColor(`n`) +### strip.get_pixel_color(`n`) Get the 24-bit RGB color value for the LED at position n. +## `*color`` +All functions that take in this, will automatically parse the value provided. + +If parameter is only a str, it will be treated as a hex value. e.g. `set_pixel_color(0, "#fafafa")` +If parameter is a tuple, the first three items in that tuple will be treated as a rgb value. e.g. `set_pixel_color(0, (255, 238, 10))` +If parameter is a int, it will be treated as a 24-bit color value. e.g. `set_pixel_color(0, 2812873)` +If there are 3 parameters, these will be treated as a rgb value. e.g. `set_pixel_color(0, 255, 238, 10)` +This means that all of these have the same effect: +```python +set_pixel_color(0, "#fafafa") +set_pixel_color(0, 16448250) +set_pixel_color(0, 250, 250, 250) +set_pixel_color(0, (250, 250, 250)) +``` + --- -## Color(`red`, `green`, `blue`, `white = 0`) -Convert the provided red, green, blue color to a 24-bit color value. -Each color component should be a value 0-255 where 0 is the lowest intensity -and 255 is the highest intensity. +These are in `utils`, can be imported with `from luxcena_neo import utils`. + +## utils.hex_to_rgb(`value`) +Convert provided hex color to a tuple with rgb colors. (r, g, b). + +## utils.rgb_to_hex(`rgb`) +Converts rgb colors in tuple to hex string. + +## utils.rgb_from_twentyfour_bit(`color`) +Takes a 24bit color value and returns a rgb tuple. -## hexColor(`value`) -Convert the provided hexadecimal color to a 24-bit color value. +## utils.rgb_from_twentyfour_bit(`color`) +Takes a 24bit color value and returns a hex string. |