// 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
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 120 // Popular NeoPixel ring size
// When setting up 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(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
const byte segment = NUMPIXELS / 6;
const byte segments[6] = {segment, segment * 2, segment * 3, segment * 4, segment * 5, segment * 6};
byte s = 0;
#define butPin 2
bool active = false;
const byte timeBut = 200;
uint64_t lastTimeBut;
byte lastButState;
void setup() {
Serial.begin(9600);
Serial.println("Отправляй любое число в стролу");
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear();
pinMode(butPin, INPUT_PULLUP);
}
void loop() {
if(!active) {
checkBut();
}
else {
//pixels.clear(); // Set all pixel colors to 'off'
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
byte j = 1;
int a = 255;
while(i >= 0 && j < 6) {
if(a < 0) {
a = 0;
}
pixels.setPixelColor(i - j, pixels.Color(a, a, a));
a -= 60;
j++;
}
// Send the updated pixel colors to the hardware.
pixels.show();
delay(DELAYVAL); // Pause before next pass through loop
if(s < 5) {
if(i >= segments[s] && i < segments[s + 1]) {
Serial.write(s + 1);
Serial.read();
while(!Serial.available()){
delay(100);
}
while(Serial.available()) {
Serial.read();
};
s++;
}
}
if(i >= NUMPIXELS - 1) {
Serial.write(s + 1);
Serial.read();
while(!Serial.available()){
delay(100);
}
while(Serial.available()) {
Serial.read();
};
s = 0;
active = false;
pixels.clear();
pixels.show();
}
}
}
}
void checkBut() {
byte stateBut = digitalRead(butPin);
if(stateBut == LOW && stateBut != lastButState) {
if(millis() - lastTimeBut > timeBut) {
lastTimeBut = millis();
active = true;
}
}
lastButState = stateBut;
}
// void expecation(byte i) {
// pixels.setPixelColor(i, pixels.Color(a, a, a));
// // for(byte j {0}; j < 6; j++) {
// // if(a < 0) {
// // a = 0;
// // }
// // pixels.setPixelColor(i - j, pixels.Color(a, a, a));
// // a -= 60;
// // j++;
// // }
// }