Misc files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shine_of_the_rainbow.ino 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <CommonBusEncoders.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #include <HID-Project.h>
  4. #define LED_PIN 4
  5. #define LED_COUNT 12
  6. #define DIMDELAY 1000
  7. #define DIMMAX 50
  8. #define DIMMIN 10
  9. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);
  10. long RGBpos = 0;
  11. int delay_count = 0;
  12. byte LEDbrightness = 50;
  13. int dimdelay_count = 0;
  14. CommonBusEncoders encoders(1, 2, 3, 1);
  15. void setup() {
  16. //Setup APA106 LEDs
  17. strip.begin();
  18. strip.show();
  19. strip.setBrightness(LEDbrightness);
  20. //Setup encoder
  21. encoders.setDebounce(16);
  22. encoders.resetChronoAfter(10000);
  23. encoders.addEncoder(1, 4, 5, 1, 100, 199);
  24. //Start Consumer keyboard
  25. Consumer.begin();
  26. //Serial debugging
  27. //Serial.begin(9600);
  28. }
  29. void loop() {
  30. dimled();
  31. if (delay_count > 20) {
  32. strip.setBrightness(LEDbrightness);
  33. rainbow(RGBpos);
  34. RGBpos = (RGBpos += 256);
  35. if (RGBpos > 5 * 65536) RGBpos = 0;
  36. delay_count = 0;
  37. }
  38. int code = encoders.readAll();
  39. if (code != 0) {
  40. //Serial.println(code);
  41. LEDbrightness = DIMMAX;
  42. strip.setBrightness(LEDbrightness);
  43. strip.show();
  44. }
  45. if (code == 101) Consumer.write(MEDIA_VOLUME_DOWN);
  46. if (code == 100) Consumer.write(MEDIA_VOLUME_UP);
  47. if (code == 199) Consumer.write(MEDIA_VOLUME_MUTE);
  48. delay(1);
  49. delay_count++;
  50. }
  51. void dimled() {
  52. dimdelay_count++;
  53. if (dimdelay_count > DIMDELAY) {
  54. dimdelay_count = 0;
  55. LEDbrightness--;
  56. if (LEDbrightness <= DIMMIN) {
  57. LEDbrightness = DIMMIN;
  58. }
  59. //Serial.println(LEDbrightness);
  60. strip.setBrightness(LEDbrightness);
  61. strip.show();
  62. }
  63. }
  64. void rainbow(long firstPixelHue) {
  65. for (int i = 0; i < strip.numPixels(); i++) {
  66. int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  67. strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  68. }
  69. strip.show();
  70. }