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> // Required for 16 MHz Adafruit Trinket
- #endif
- #define PIN 0
- #define NUMPIXELS 8
- #define BRIGHTNESS 15
- #define TIME_BLUE 15
- #define TIME_RED 10
- #define BLINK_INTERVAL 500 //в миллисекундах
- Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- void setup() {
- #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
- clock_prescale_set(clock_div_1);
- #endif
- pixels.begin();
- long timb = TIME_BLUE;
- long timr = TIME_RED;
- long blink = BLINK_INTERVAL;
- pixels.clear();
- //all blue
- for (int i=0; i<NUMPIXELS; i++){
- pixels.setPixelColor(i, pixels.Color(0, 0, BRIGHTNESS));
- }
- pixels.show();
- //blue part
- long intb = (timb*1000)/NUMPIXELS;
- long lastb = millis();
- bool state = true;
- for(int i=NUMPIXELS; i>0; i--) {
- while(lastb + intb > blink + millis()){
- if(state){
- pixels.setPixelColor(i-1, pixels.Color(BRIGHTNESS, 0, 0));
- pixels.show();
- state = false;
- }
- else{
- pixels.setPixelColor(i-1, pixels.Color(0, 0, BRIGHTNESS));
- pixels.show();
- state = true;
- }
- delay(blink);
- }
- pixels.setPixelColor(i-1, pixels.Color(BRIGHTNESS, 0, 0));
- pixels.show();
- state = true;
- delay(lastb + intb - millis());
- lastb = millis();
- }
- //all red
- for (int i=0; i<NUMPIXELS; i++){
- pixels.setPixelColor(i, pixels.Color(BRIGHTNESS, 0, 0));
- pixels.show();
- }
- //red blink
- long intr = (timr*1000)/NUMPIXELS;
- long lastr = millis();
- for(int i=NUMPIXELS; i>0; i--) {
- while(lastr + intr > blink + millis()){
- if(state){
- pixels.setPixelColor(i-1, pixels.Color(0, 0, 0));
- pixels.show();
- state = false;
- }
- else{
- pixels.setPixelColor(i-1, pixels.Color(BRIGHTNESS, 0, 0));
- pixels.show();
- state = true;
- }
- delay(blink);
- }
- pixels.setPixelColor(i-1, pixels.Color(0, 0, 0));
- pixels.show();
- state = true;
- delay(lastr + intr - millis());
- lastr = millis();
- }
- }
- void loop(){
- for (int i=0; i<NUMPIXELS; i++){
- pixels.setPixelColor(i, pixels.Color(BRIGHTNESS, 0, 0));
- pixels.show();
- }
- delay(500);
- for (int i=0; i<NUMPIXELS; i++){
- pixels.setPixelColor(i, pixels.Color(0, BRIGHTNESS, 0));
- pixels.show();
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement