Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.77 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 AdaFruit NeoPixel library
  3.  
  4. #include <Adafruit_NeoPixel.h>
  5. #ifdef __AVR__
  6.   #include <avr/power.h>
  7. #endif
  8.  
  9. // Which pin on the Arduino is connected to the NeoPixels?
  10. // On a Trinket or Gemma we suggest changing this to 1
  11. #define PIN            D5
  12.  
  13. // How many NeoPixels are attached to the Arduino?
  14. #define NUMPIXELS     8
  15.  
  16. // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
  17. // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
  18. // example for more information on possible values.
  19. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  20.  
  21. #define STATE_BOOT    1
  22. #define STATE_ON      2
  23. #define STATE_WORKING 3
  24. #define STATE_MESH    4
  25. #define STATE_ERR     5
  26.  
  27. #define BLINK_MS      2000
  28. #define MAX_BRIGHT    255
  29.  
  30. int delayval = 500; // delay for half a second
  31.  
  32. int state = STATE_BOOT;
  33. long dbgtime = millis();
  34.  
  35. int bright;
  36.  
  37. void setup() {
  38.   // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  39. #if defined (__AVR_ATtiny85__)
  40.   if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  41. #endif
  42.   // End of trinket special code
  43.  
  44.   pixels.begin(); // This initializes the NeoPixel library.
  45. }
  46.  
  47. void loop() {
  48.  
  49.   // switch states for debug
  50.  
  51.   if(millis() >= dbgtime + 6000) {
  52.     dbgtime = millis();
  53.     state++;
  54.     if (state > 5) state = STATE_BOOT;
  55.   }
  56.  
  57.   // brightness value for blinking
  58.  
  59.   bright = (int) ((sin(2.0f * 3.14159f / BLINK_MS * (millis() % BLINK_MS)) + 1.0) / 2.0 * MAX_BRIGHT + 0.5);
  60.  
  61.  
  62.   //display state on ring
  63.   switch(state) {
  64.    
  65.     case STATE_BOOT:
  66.       for(int i=0;i<NUMPIXELS;i++){
  67.         pixels.setPixelColor(i, pixels.Color(0,bright,0));
  68.         pixels.show();
  69.       }
  70.       break;
  71.    
  72.     case STATE_ON:
  73.       for(int i=0;i<NUMPIXELS;i++){
  74.         pixels.setPixelColor(i, pixels.Color(0, MAX_BRIGHT, 0));
  75.         pixels.show();
  76.       }
  77.       break;
  78.  
  79.      case STATE_WORKING:
  80.       for(int i=0;i<NUMPIXELS;i++){
  81.         pixels.setPixelColor(i, pixels.Color((MAX_BRIGHT-bright)*10/12, MAX_BRIGHT, 0));
  82.         pixels.show();
  83.       }
  84.       break;
  85.    
  86.     case STATE_MESH:
  87.       for(int i=0;i<NUMPIXELS;i++){
  88.         if(i==7 || i==0 || i==3 || i==4)
  89.           pixels.setPixelColor(i, pixels.Color(0, bright, 0));
  90.         else
  91.           pixels.setPixelColor(i, pixels.Color(0, MAX_BRIGHT - bright, 0));
  92.         pixels.show();
  93.       }
  94.       break;
  95.  
  96.      case STATE_ERR:
  97.       for(int i=0;i<NUMPIXELS;i++){
  98.         pixels.setPixelColor(i, pixels.Color(bright, 0, 0));
  99.         pixels.show();
  100.       }
  101.       break;
  102.   }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement