Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <avr/power.h>
  3. #include <Keyboard.h>
  4.  
  5. const int osutapa = 10;
  6. const int osutapb = 3;
  7.  
  8. #define PIN 9
  9. #define NUMPIXELS 1
  10. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  11.  
  12. void setup() {
  13. pinMode(osutapa, INPUT_PULLUP);
  14. pinMode(osutapb, INPUT_PULLUP);
  15. Keyboard.begin();
  16. pixels.begin();
  17. }
  18.  
  19. void loop() {
  20.  
  21. if (digitalRead(osutapa) == LOW){
  22. Keyboard.press('z');
  23. } else {
  24. Keyboard.release('z');
  25. }
  26. if (digitalRead(osutapb) == LOW){
  27. Keyboard.press('x');
  28. } else {
  29. Keyboard.release('x');
  30. }
  31.  
  32. //hue from 0 to 360 degrees
  33. for(int hue = 0; hue < 360; hue++) {
  34.  
  35. // saturation and value = 1
  36. setLedColorHSV(hue, 1, 1);
  37. delay(50);
  38. }
  39. }
  40.  
  41. // thanks to http://forum.arduino.cc/index.php?topic=307655.5
  42. void setLedColorHSV(int h, double s, double v) {
  43.  
  44. double r=0;
  45. double g=0;
  46. double b=0;
  47. double hf=h/60.0;
  48.  
  49. int i=(int)floor(h/60.0);
  50. double f = h/60.0 - i;
  51. double pv = v * (1 - s);
  52. double qv = v * (1 - s*f);
  53. double tv = v * (1 - s * (1 - f));
  54.  
  55. switch (i)
  56. {
  57. case 0:
  58. r = v;
  59. g = tv;
  60. b = pv;
  61. break;
  62. case 1:
  63. r = qv;
  64. g = v;
  65. b = pv;
  66. break;
  67. case 2:
  68. r = pv;
  69. g = v;
  70. b = tv;
  71. break;
  72. case 3:
  73. r = pv;
  74. g = qv;
  75. b = v;
  76. break;
  77. case 4:
  78. r = tv;
  79. g = pv;
  80. b = v;
  81. break;
  82. case 5:
  83. r = v;
  84. g = pv;
  85. b = qv;
  86. break;
  87. }
  88.  
  89. //set each component to a integer value between 0 and 255
  90. int red = constrain((int)255*r,0,255);
  91. int green = constrain((int)255*g,0,255);
  92. int blue = constrain((int)255*b,0,255);
  93.  
  94. pixels.setPixelColor(0, pixels.Color(red, green, blue));
  95. pixels.show();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement