// Inkludierte Libraries
#include <Adafruit_NeoPixel.h>
#include <Bounce2.h>
#include <BluetoothSerial.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_ADXL345_U.h>
#include <Wire.h>
// Variablen Deklaration
#define NEOPIN1 33
#define NEOPIN2 26
#define NUMPIXELS 75
#define DELAYVAL 5
#define BUTTON_PIN1 25
#define BUTTON_PIN2 27
#define BUZZERPIN 18
BluetoothSerial SerialBT;
//Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS,NEOPIN2,NEO_GRB + NEO_KHZ800);
Bounce2::Button button1 = Bounce2::Button();
Bounce2::Button button2 = Bounce2::Button();
int i = 0;
int j = 0;
int k = 0;
uint32_t BladeColors [] {
pixels.Color(255,0,0), //red
pixels.Color (0,255,0), //green
pixels.Color (0,0,255), //blue
pixels.Color (255,255,0), //yellow
pixels.Color (255,0,255), //pink
pixels.Color (0,255,255), //turquoise
pixels.Color (150,0,255), //purple
pixels.Color (255,255,255), //white
};
uint32_t Blade2Colors [] {
pixels2.Color(255,0,0), //red
pixels2.Color (0,255,0), //green
pixels2.Color (0,0,255), //blue
pixels2.Color (255,255,0), //yellow
pixels2.Color (255,0,255), //pink
pixels2.Color (0,255,255), //turquoise
pixels2.Color (150,0,255), //purple
pixels2.Color (255,255,255), //white
};
int BladeColorCount = 8;
void SaberOn(){
j=j+1;
for (i; i<NUMPIXELS; i++){
pixels.setPixelColor(i, BladeColors[k]);
pixels.show();
pixels2.setPixelColor(i, Blade2Colors[k]);
pixels2.show();
delay(DELAYVAL);
}
}
void SaberOff(){
j=0;
for (i; i>=0; i--){
pixels.setPixelColor(i, 0);
pixels.show();
pixels2.setPixelColor(i, 0);
pixels2.show();
delay(DELAYVAL);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pixels.begin();
pixels2.begin();
button1.attach(BUTTON_PIN1, INPUT_PULLUP);
button1.interval(5);
button1.setPressedState(LOW);
button2.attach(BUTTON_PIN2, INPUT_PULLUP);
button2.interval(5);
button2.setPressedState(LOW);
}
void loop() {
// put your main code here, to run repeatedly:
button1.update();
button2.update();
if (button1.pressed()){
SaberOn();
}
if (button1.pressed() && j>1){
SaberOff();
}
if (button2.pressed()){
k=k+1;
Serial.println(k);
if (k > BladeColorCount){
k=0;
}
}
}