Created
November 5, 2019 22:08
-
-
Save bboyho/3062c2767fe8afd722ea0a0bbb569805 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
//Create brightness variable | |
//Ranging from 0.0-1.0: | |
// 0.0 is off | |
// 0.5 is 50% | |
// 1.0 is fully on | |
float brightness_LED = 0.7; | |
float knobValue = 0.0; | |
//. | |
//. | |
//. | |
//==================== CHECK POTENTIOMETER FOR BRIGHTNESS ==================== | |
void checkKnob() { | |
brightness_LED = analogRead(knobPin) / 1023.0; //potentiometer for Brightness | |
/*divide the knob into sections for brightness | |
the analogRead() will start flickering if you have more values | |
*/ | |
if (brightness_LED > 0.1 && brightness_LED <= 0.25) { | |
brightness_LED = 0.1; | |
} | |
else if (brightness_LED > 0.25 && brightness_LED <= 0.4) { | |
brightness_LED = 0.3; | |
} | |
else if (brightness_LED > 0.4 && brightness_LED <= 0.6) { | |
brightness_LED = 0.5; | |
} | |
else if (brightness_LED > 0.6 && brightness_LED <= 0.8) { | |
brightness_LED = 0.7; | |
} | |
else if (brightness_LED > 0.8 && brightness_LED <= 1.0) { | |
brightness_LED = 1.0; | |
} | |
else {//brightness_LED > 0.0 && brightness_LED <= 0.1 | |
brightness_LED = 0.0; | |
} | |
/* | |
#if DEBUG | |
Serial.print(" Brightness Value % = "); | |
Serial.println(brightness_LED * 100); | |
#endif | |
*/ | |
} | |
//==================== END CHECK POTENTIOMETER FOR BRIGHTNESS ==================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment