Servus Leute,
leider komme ich mit meinen Kenntnissen nicht weiter und brauche dringend euren Rat und know-how.
kurz zum Project: Ich habe einen Neopixel 24 Bit RGB LED Ring, den ich über Arduino mini Pro und HC-06 BT Modul ansteuere. Die App zum BT steuern habe ich vom MIT Inventor 2 mir schnell und einfach zusammengebaut. Ich kann simple Sachen wie Farben wechseln (also vorher im Code generiert) und Funktionen ablaufen lassen ABER was ich noch nicht hinkriege ist, dass ich z.B. ein Case Fall z.B. Rainbowcycle solange laufen lassen kann, bis ich einen anderen Case durch BT auswähle. ICh habe mich schon durch google durchgewühlt aber mir fehlen die richtigen suchwörter oder einfach das Verständniss. Aus diesem Grunde bitte ich um eure Unterstützung, um in dem Projekt einfach mal Ruhe zu bekommen und mich auf die einzelnen Funktionen und Farbspiele zu konzentrieren.
Also nochmal die Konkrete Problemeatik. Ich möchte eine Schleife eines cases solange laufen lassen, bis ich etwas anderes über Bluetooth auswähle.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_RGB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(6, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
char data;
data = Serial.read();
Serial.write(Serial.read());
switch (data)
{
case 'E':
colorSet(strip.Color(0, 0, 0), 0);//aus muss oben stehen, sonst wenn app geschlossen laufen alle funktionen durch
break; // stoppt den Ablauf von case
case 'A':
rainbowCycle(20); // erst läuft der Rainbow Cycle Zyklus ab
colorSet(strip.Color(0, 0, 0), 0); // dann gehen die LEDs aus ansosnten würden sie nach ablauf vom Rainbow Zyclus farbig stehen bleiben
break;
case 'B':
// colorWipe(random(0, 100), 20); // colorWipe(random(0, 255), 20); // random Helligkeit
do { // verzweifelter Versuch mit do whole Schleife ohne Erfolg // WAS WÄRE denn richtig?
colorWipe(strip.Color(random(0, 100), random(0, 100), random(0, 100)), 50);
delay(50);
data = Serial.read();
Serial.write(Serial.read());
} while (data = 'B');
break;
case 'C':
theaterChaseRainbow(20); // Die Zahl in der Klammer gibt an wie schnell die schleife drehen soll hier 20ms
colorSet(strip.Color(0, 0, 0), 0);
break;
case 'D':
//brighten();
// darken();
break;
case 'F':
colorSet(strip.Color(0, 0, 30), 0);//Blue
break;
default:
colorSet(strip.Color(0, 0, 0), 0);
digitalWrite(6, LOW);
}
}
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 1; j++) { // 1 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);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
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)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
void colorSet(uint32_t c, uint8_t wait) { // From NeoPixel Library
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(wait);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
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);
}
ich hoffe ich habe keinen Admin oder jemanden sonst verärgert.
Und bedanke mich schon im voraus für alle Hinweise, die mich Konstruktiv weiter bringen.