Dobra, pomyślałem że zrobię wszystko na nowa bo był już bałagan. Zrobiłem nowy kod i działa wszystko dobrze. Ale jest jeden problem że jak chcę więcej przycisków to więcej zmiennych muszę (teraz mam 2 zmienne do przycisków czyli P1 i P2). W dalszym ciągu nie wiem jak zrobić tą jedną zmienną. Jeżeli można to napisz fragment kodu gdzie co wpisać. Przerwa działa na animacji RAIBOW oraz COLORWIPE.
Kod:
Kod:
Kod:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(25, PIN, NEO_GRB + NEO_KHZ800);
//przyciski
#define switch_0 0
#define switch_1 1
volatile int stan;
volatile int P1;
volatile int P2;
void setup() {
pinMode(switch_0, INPUT_PULLUP);
pinMode(switch_1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(switch_0), animation_0, FALLING);
attachInterrupt(digitalPinToInterrupt(switch_1), animation_1, FALLING);
strip.begin();
strip.show();
}
void loop() {
}
void animation_0() {
stan = 0;
przyciski(stan);
}
void animation_1() {
stan = 1;
przyciski(stan);
}
void przyciski(volatile int i) {
switch (i) {
case 1: P2 = 0;
rainbow(20);
break;
case 0: P1 = 0;
colorWipe(strip.Color(255, 0, 0), 50);
break;
}
}
void colorWipe(uint32_t c, uint8_t wait) {
P2 = 1;
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
if (P1 == 1) {
return;
}
}
}
void rainbow(uint8_t wait) {
P1 = 1;
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
if (P2 == 1) {
return;
}
}
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
void theaterChase(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) {
for (int q = 0; q < 3; q++) {
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, c);
}
strip.show();
delay(wait);
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0);
}
}
}
}
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j < 256; j++) {
for (int q = 0; q < 3; q++) {
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, Wheel( (i + j) % 255));
}
strip.show();
delay(wait);
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0);
}
}
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}