Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. // NeoPixel Ring simple sketch (c) 2013 Shae Erisson
  2. // Released under the GPLv3 license to match the rest of the
  3. // Adafruit NeoPixel library
  4.  
  5. #include <Adafruit_NeoPixel.h>
  6. #ifdef __AVR__
  7. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  8. #endif
  9.  
  10. #define PIN 0
  11. #define NUMPIXELS 8
  12. #define BRIGHTNESS 15
  13. #define TIME_BLUE 15
  14. #define TIME_RED 10
  15. #define BLINK_INTERVAL 500 //в миллисекундах
  16. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  17.  
  18.  
  19. void setup() {
  20.  
  21. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  22. clock_prescale_set(clock_div_1);
  23. #endif
  24.  
  25. pixels.begin();
  26. long timb = TIME_BLUE;
  27. long timr = TIME_RED;
  28. long blink = BLINK_INTERVAL;
  29. pixels.clear();
  30.  
  31. //all blue
  32. for (int i=0; i<NUMPIXELS; i++){
  33. pixels.setPixelColor(i, pixels.Color(0, 0, BRIGHTNESS));
  34. }
  35. pixels.show();
  36.  
  37. //blue part
  38. long intb = (timb*1000)/NUMPIXELS;
  39. long lastb = millis();
  40. bool state = true;
  41. for(int i=NUMPIXELS; i>0; i--) {
  42. while(lastb + intb > blink + millis()){
  43. if(state){
  44. pixels.setPixelColor(i-1, pixels.Color(BRIGHTNESS, 0, 0));
  45. pixels.show();
  46. state = false;
  47. }
  48. else{
  49. pixels.setPixelColor(i-1, pixels.Color(0, 0, BRIGHTNESS));
  50. pixels.show();
  51. state = true;
  52. }
  53. delay(blink);
  54. }
  55. pixels.setPixelColor(i-1, pixels.Color(BRIGHTNESS, 0, 0));
  56. pixels.show();
  57. state = true;
  58. delay(lastb + intb - millis());
  59. lastb = millis();
  60. }
  61.  
  62. //all red
  63. for (int i=0; i<NUMPIXELS; i++){
  64. pixels.setPixelColor(i, pixels.Color(BRIGHTNESS, 0, 0));
  65. pixels.show();
  66. }
  67.  
  68. //red blink
  69. long intr = (timr*1000)/NUMPIXELS;
  70. long lastr = millis();
  71. for(int i=NUMPIXELS; i>0; i--) {
  72. while(lastr + intr > blink + millis()){
  73. if(state){
  74. pixels.setPixelColor(i-1, pixels.Color(0, 0, 0));
  75. pixels.show();
  76. state = false;
  77. }
  78. else{
  79. pixels.setPixelColor(i-1, pixels.Color(BRIGHTNESS, 0, 0));
  80. pixels.show();
  81. state = true;
  82. }
  83. delay(blink);
  84. }
  85. pixels.setPixelColor(i-1, pixels.Color(0, 0, 0));
  86. pixels.show();
  87. state = true;
  88. delay(lastr + intr - millis());
  89. lastr = millis();
  90. }
  91. }
  92.  
  93. void loop(){
  94.  
  95. for (int i=0; i<NUMPIXELS; i++){
  96. pixels.setPixelColor(i, pixels.Color(BRIGHTNESS, 0, 0));
  97. pixels.show();
  98. }
  99. delay(500);
  100.  
  101. for (int i=0; i<NUMPIXELS; i++){
  102. pixels.setPixelColor(i, pixels.Color(0, BRIGHTNESS, 0));
  103. pixels.show();
  104. }
  105. delay(1000);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement