Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NeoPixel Ring simple sketch (c) 2013 Shae Erisson
- // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- // Which pin on the Arduino is connected to the NeoPixels?
- // On a Trinket or Gemma we suggest changing this to 1
- #define PIN D5
- // How many NeoPixels are attached to the Arduino?
- #define NUMPIXELS 8
- // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
- // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
- // example for more information on possible values.
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- #define STATE_BOOT 1
- #define STATE_ON 2
- #define STATE_WORKING 3
- #define STATE_MESH 4
- #define STATE_ERR 5
- #define BLINK_MS 2000
- #define MAX_BRIGHT 255
- int delayval = 500; // delay for half a second
- int state = STATE_BOOT;
- long dbgtime = millis();
- int bright;
- void setup() {
- // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
- #if defined (__AVR_ATtiny85__)
- if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
- #endif
- // End of trinket special code
- pixels.begin(); // This initializes the NeoPixel library.
- }
- void loop() {
- // switch states for debug
- if(millis() >= dbgtime + 6000) {
- dbgtime = millis();
- state++;
- if (state > 5) state = STATE_BOOT;
- }
- // brightness value for blinking
- bright = (int) ((sin(2.0f * 3.14159f / BLINK_MS * (millis() % BLINK_MS)) + 1.0) / 2.0 * MAX_BRIGHT + 0.5);
- //display state on ring
- switch(state) {
- case STATE_BOOT:
- for(int i=0;i<NUMPIXELS;i++){
- pixels.setPixelColor(i, pixels.Color(0,bright,0));
- pixels.show();
- }
- break;
- case STATE_ON:
- for(int i=0;i<NUMPIXELS;i++){
- pixels.setPixelColor(i, pixels.Color(0, MAX_BRIGHT, 0));
- pixels.show();
- }
- break;
- case STATE_WORKING:
- for(int i=0;i<NUMPIXELS;i++){
- pixels.setPixelColor(i, pixels.Color((MAX_BRIGHT-bright)*10/12, MAX_BRIGHT, 0));
- pixels.show();
- }
- break;
- case STATE_MESH:
- for(int i=0;i<NUMPIXELS;i++){
- if(i==7 || i==0 || i==3 || i==4)
- pixels.setPixelColor(i, pixels.Color(0, bright, 0));
- else
- pixels.setPixelColor(i, pixels.Color(0, MAX_BRIGHT - bright, 0));
- pixels.show();
- }
- break;
- case STATE_ERR:
- for(int i=0;i<NUMPIXELS;i++){
- pixels.setPixelColor(i, pixels.Color(bright, 0, 0));
- pixels.show();
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement