Last active
October 15, 2018 03:15
-
-
Save Data-ptr/c1a30d1338ccf49cf436c591724e2826 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // A little macro that takes a percentage and chnages it to 0-255 | |
| // | |
| #define MAX_VALUE 255 | |
| #define PER_TO_VAL(percent) ((MAX_VALUE/100) * percent) | |
| typedef enum DmxCh { | |
| RED = 1, | |
| GREEN = 2, | |
| BLUE = 3 | |
| } DmxCh; | |
| bool set_rgb_value(int red, int green, int blue) { | |
| // Make sure all the values are valid | |
| if( //--------------------------------- | |
| !valid_range_value(red ) || | |
| !valid_range_value(green) || | |
| !valid_range_value(blue ) | |
| ) { //--------------------------------- | |
| return 0; | |
| } | |
| // Set each of the colors | |
| dmx_master.setChannelValue(RED, red ); | |
| dmx_master.setChannelValue(GREEN, green); | |
| dmx_master.setChannelValue(BLUE, blue ); | |
| return 1; | |
| } | |
| void set_rgb_percentage(int red, int green, int blue) { | |
| // Make sure all the percentages are valid | |
| if( //--------------------------------- | |
| !valid_range_percentage(red ) || | |
| !valid_range_percentage(green) || | |
| !valid_range_percentage(blue ) | |
| ) { //--------------------------------- | |
| return 0; | |
| } | |
| // Set each of the colors | |
| dmx_master.setChannelValue(RED, PER_TO_VAL(red) ); | |
| dmx_master.setChannelValue(GREEN, PER_TO_VAL(green)); | |
| dmx_master.setChannelValue(BLUE, PER_TO_VAL(blue) ); | |
| return 1; | |
| } | |
| bool valid_range_value(int value) { | |
| return valid_range(0, 255, value); | |
| } | |
| bool valid_range_percentage(int percentage) { | |
| return valid_range(0, 100, percentage); | |
| } | |
| bool valid_range(int min, int max, int value) { | |
| if(value >= min && value <= max) { | |
| return 1; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment