Skip to content

Instantly share code, notes, and snippets.

@bboyho
Created November 5, 2019 22:08
Show Gist options
  • Save bboyho/3062c2767fe8afd722ea0a0bbb569805 to your computer and use it in GitHub Desktop.
Save bboyho/3062c2767fe8afd722ea0a0bbb569805 to your computer and use it in GitHub Desktop.
//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