2 sketche in 1

Hallo leute ich bin neu beim arduino programieren.
ich möchte an fasching mit einem selbstgemachten kostüm gehen und habe mir unzählige leds in allen farben darauf geklebt mit wiederständen versehen und verkabelt. auf einer lochrasterplatiene habe ich mit bc546 transistoren eine verstärkung gebaut die ich mit 5v aus nem powerbank versorge.
dieses ganze möchte ich mit einem arduino mega ansteuern.

Der knackpunkt ist, das Ich auf dem kostüm zusätzlich einen adafruit neopixelring habe.
mein problem: ich habe zwei programme die ich nutzen will (eines für die leds, eines für den neopixelring).
da ich noch ein anfänger im programmieren bin wollte ich fragen ob mir hier einer helfen kann.
ich habe unzählige anleitungen im internet gelesen um programme zu verbinden undalles ausprobiert.

BITTE KANN MIR JEMAN UND BESTENFALLS FÜR MICH DIESE PROGRAMME VEREINEN:

  1. programm:
    zu finden auf dieser webseite:

http://bit.ly/2EnuaJQ

2.programm:
zu finden auf dieser webseite:

die pins sind mir egal die kann ich selber ändern.

Wenn dir jemand helfen soll, dann solltest du mindestens die Sketche hier im Forum posten.
Und zwar diese in Code-Tags setzen, damit alle die lesen können.

ok hier sind die programme:

int pinArray[] = {0,0,0,6,7,8,9,10,11,12,13,0,0,0};

int pinCount = 14;

int activePin = 2;

int dx = 1;

int poti = 0;

int mintime = 0;

void setup() {

 Serial.begin(9600);

 for (int i=0; i< pinCount; i++) {
   if (pinArray[i] != 0) {
     pinMode(pinArray[i], OUTPUT);
   }
 }
}

void loop() {

 for (int i=0; i<pinCount; i++) {
   digitalWriteNot0(pinArray[i], LOW);
 }

 if (activePin == (pinCount-1)) {
   activePin = (pinCount - 2);
   dx = -1;
 }

 if (activePin == 0) {
   activePin = 1;
   dx = 1;
 }

 activePin += dx;


 poti = analogRead(0);


 if (poti < 1023) {
  
   digitalWriteNot0(pinArray[activePin], HIGH);
   
   digitalWriteNot0(pinArray[activePin-dx], HIGH);
  
   digitalWriteNot0(pinArray[activePin-2*dx], HIGH);

 }

 Serial.print(poti);
 Serial.print(" - ");
 Serial.println(activePin);

 delay(mintime+analogRead(0)/4);

}

void digitalWriteNot0(int pin, boolean state) {
 if (pin > 0) {
   digitalWrite(pin, state);
 }
}

und das zweite:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h>
#endif

#define PIN 5

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
 // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
 #if defined (__AVR_ATtiny85__)
   if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
 #endif
 // End of trinket special code


 strip.begin();
 strip.show(); // Initialize all pixels to 'off'
}

void loop() {
 // Some example procedures showing how to display to the pixels:
 colorWipe(strip.Color(255, 0, 0), 50); // Red
 colorWipe(strip.Color(0, 255, 0), 50); // Green
 colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
 // Send a theater pixel chase in...
 theaterChase(strip.Color(127, 127, 127), 50); // White
 theaterChase(strip.Color(127, 0, 0), 50); // Red
 theaterChase(strip.Color(0, 0, 127), 50); // Blue

 rainbow(20);
 rainbowCycle(20);
 theaterChaseRainbow(50);
}

// 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);
 }
}

void rainbow(uint8_t wait) {
 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);
 }
}

// Slightly different, this makes the rainbow equally distributed throughout
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);
 }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
 for (int j=0; j<10; j++) {  //do 10 cycles of chasing
   for (int q=0; q < 3; q++) {
     for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
       strip.setPixelColor(i+q, c);    //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
     }
   }
 }
}

//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
     }
   }
 }
}

// 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);
}

Hi

Wenn ich Das recht verstehe, soll der eine Sketch die LEDs mehr oder minder zufällig und mit variabler Geschwindigkeit blinken lassen.
Der Andere lässt den RGB-Stripe lustig vor sich hin faden.

Im ersten Sketch ist ein delay() enthalten - sehe gerade, im Zweiten auch - Das klappt so dann nicht wirklich - Du müsstest also die Sketche auf millis() umschreiben. (Suchwort: blinkwithoutdelay oder Nachtwächtererklärung)

Wenn beide Sketche alleine per millis() laufen, kannst Du die Innereien von Sketch 1 in den Sketch 2 einbringen.

MfG

@postmaster-ino
da das leider neuland für mich ist frage ich ja nach ob mir hir jemand helfen.
sonst müsste ich den ring mit einem zusätzlichen arduino betreiben.
leider habe ich nur zwei arduino mega und keinen nano.
das wäre etwas zu groß.
auserdem hätter der mega die leistung und pin kapazitäten für beide prohramme zusammen.

Hi

Einen fertigen Sketch wirst Du hier eher nicht bekommen - der Sinn des Forum ist Hilfe zur Selbsthilfe (und auch sehen, was die Anderen tolles mit den Arduinos anstellen).

Die Nachtwächtererklärung

Lies Dir Das erst Mal durch, ist leichte Kost. Dann versuchst Du Dich daran, im Neopixel-Sketch die delay() raus zu bekommen, also erst Mal, wo Die überall stehen und was für einen Sinn Die Da haben.

delay() blockiert Dir den Arduino - in der Zeit macht Der Nichts - in Deinem Fall soll aber rumgeblinkt und gefadet werden - gleichzeitig.

Bei Problemen helfen wir Dir gerne, auch sind noch ein paar Tage Zeit - denke, Das bekommen wir schon hin.
(so wie ich die Narretei verstanden habe, bin Da nicht so involviert)

MfG

das verstehe ich nicht ganz
wenn ich die delays rausgesucht habe was soll ich dan tun?

Hi

Du musst verstehen, was diese delay() machen (klar: Pause, aber wofür ist diese Pause gut?)
Dann musst Du Dir überlegen, wie Du diese Pause, Deren Sinn Du ja jetzt verinnerlicht hast, per millis() nachbilden kannst.
Der Hintergrund ist Der: Mit Blick auf millis() (der Systemuhr) kannst Du entscheiden, ob die Pause bereits vorbei ist und diesen Code ausführen.
Wenn die Pause noch nicht vorbei ist, wird dieser Abschnitt NICHT ausgeführt - gleichzeitig haben wir Zeit für den anderen Code, Der ja auch irgend wann ausgeführt werden soll.
Klar kann es auch vorkommen, daß sämtlicher Code ausgeführt wird - ist dann halt so und wohl auch so gewünscht.
Der Vorteil besteht darin, den Code erst auszuführen, wenn Er dran ist - den Rest der Zeit wird nur drauf gewartet, daß wieder 'was dran ist'.

<Pseudocode>
If (Systemuhr-StartletzteBlinkLED>=Wartezeit_BlinkLED){
   StartletzteBlinkLED=Systemuhr;
   ... Code der Blink-LED ...
}
If (Systemuhr-StartletzteRGBStript>=Wartezeit_RGBStript){
   StartletzteRGBStript=Systemuhr;
   ... Code des RGB-Stripe ...
}
</Pseudocode>

Das ist der Inhalt Deiner loop().
Wenn keine der beiden Teile schon wieder dran ist, führst Du Diese nicht aus und kommst direkt wieder dazu zu prüfen, ob die Wartezeit um ist.
Pro 'eigenständigem Programmabschnitt' brauchst Du den Merker der Startzeit und die Wartezeit (Letztere kann wohl const sein).

Den Nachtwächter hast Du verstanden?

MfG

Den Nachtwächter hast Du verstanden?

nee leider nicht......

Also den Nachtwächter hatte ich mir mal angeschaut, bin da selbst nicht klargekommen.
Ich bleib bei dem BlinkWithoutDelay Beispiel und gut is.

Für Fasching wird es etwas kurz programmieren zu lernen. Der Notfallplan wäre wohl tatsächlich der zweite Arduino.

Wenn du mit der Delay-Zeit des Neopixel-Sketch zurecht kommst, dann könntest du die Loop des ersten Sketch z.B. in void Lauflicht() umbennen. Dort das Delay herauslöschen

Dann kannst du dieses Lauflicht in die Unterfunktionen des zweiten Sketch bei den Delays einfügen.

Ungetestet, habe es quick&dirty zusammen kopiert:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h>
#endif

#define PIN 5

Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

int pinArray[] = {0,0,0,6,7,8,9,10,11,12,13,0,0,0};

int pinCount = 14;

int activePin = 2;

int dx = 1;

int poti = 0;

int mintime = 0;

void setup() { //Setup aus beiden Sketch zusammenkopiert

 Serial.begin(9600);

 for (int i=0; i< pinCount; i++) {
   if (pinArray[i] != 0) {
     pinMode(pinArray[i], OUTPUT);
   }
 }

// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
 #if defined (__AVR_ATtiny85__)
   if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
 #endif
 // End of trinket special code


 strip.begin();
 strip.show(); // Initialize all pixels to 'off'
}
}

void lauflicht() { //loop erster Sketch

 for (int i=0; i<pinCount; i++) {
   digitalWriteNot0(pinArray[i], LOW);
 }

 if (activePin == (pinCount-1)) {
   activePin = (pinCount - 2);
   dx = -1;
 }

 if (activePin == 0) {
   activePin = 1;
   dx = 1;
 }

 activePin += dx;


 poti = analogRead(0);


 if (poti < 1023) {
  
   digitalWriteNot0(pinArray[activePin], HIGH);
   
   digitalWriteNot0(pinArray[activePin-dx], HIGH);
  
   digitalWriteNot0(pinArray[activePin-2*dx], HIGH);

 }

 Serial.print(poti);
 Serial.print(" - ");
 Serial.println(activePin);
}

void digitalWriteNot0(int pin, boolean state) {
 if (pin > 0) {
   digitalWrite(pin, state);
 }
}

void loop() {
 // Some example procedures showing how to display to the pixels:
 colorWipe(strip.Color(255, 0, 0), 50); // Red
 colorWipe(strip.Color(0, 255, 0), 50); // Green
 colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
 // Send a theater pixel chase in...
 theaterChase(strip.Color(127, 127, 127), 50); // White
 theaterChase(strip.Color(127, 0, 0), 50); // Red
 theaterChase(strip.Color(0, 0, 127), 50); // Blue

 rainbow(20);
 rainbowCycle(20);
 theaterChaseRainbow(50);
}

// 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();
   lauflicht(); // hier eingefügt
   delay(wait);
 }
}

void rainbow(uint8_t wait) {
 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();
   lauflicht();
   delay(wait);
 }
}

// Slightly different, this makes the rainbow equally distributed throughout
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();
   lauflicht();
   delay(wait);
 }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
 for (int j=0; j<10; j++) {  //do 10 cycles of chasing
   for (int q=0; q < 3; q++) {
     for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
       strip.setPixelColor(i+q, c);    //turn every third pixel on
     }
     strip.show();
     lauflicht();
     delay(wait);

     for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
       strip.setPixelColor(i+q, 0);        //turn every third pixel off
     }
   }
 }
}

//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();
     lauflicht();
     delay(wait);

     for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
       strip.setPixelColor(i+q, 0);        //turn every third pixel off
     }
   }
 }
}

// 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);
}

Hallo,

Also ich finde den Nachtwächter Super!

Vielleicht sollte man dazuschreiben, dass mit delay (), der Nachtwächter die 15min nur da steht und sich sogar im Falle, das plötzlich Einbrecher auftauchen, er nichts dagegen tun kann. Er weiß es nicht einmal!

Edit: Verwendest Du dieses Produkt?

delay(mintime + analogRead(0) / 4); // <- Wenn Du das hinbekommst SOLLTE der Rest kein Problem sein.

lg dony

Hallo nochmal,

@Theseus: Du hast folgendes vorm Setup übersehen:

Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

Ich habe den Code auch zusammengeführt und formatiert. Allerdings habe ich nicht Deinen Aufbau und keinen NeoPixel Ring, deshalb weiß ich leider nicht wie lange diese delay() im Adafruit Code sind. Ich habe das delay() in der loop geändert.
Bitte poste den Produkt Link, Deines NeoPixel Ring.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

int pinArray[] = {0, 0, 0, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0};
int pinCount = 14;
int activePin = 2;
int dx = 1;
int poti = 0;
int mintime = 0;

const byte neoPixelPin = 5; // Damit das DEFINE raus kommt

Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, neoPixelPin, NEO_GRB + NEO_KHZ800);

void setup() {
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif

  Serial.begin(9600);

  for (int i = 0; i < pinCount; i++) {
    if (pinArray[i] != 0) {
      pinMode(pinArray[i], OUTPUT);
    }
  }

  //  Adafruit Code
  strip.begin();
  strip.show();

}

void loop() {

  for (int i = 0; i < pinCount; i++) {
    digitalWriteNot0(pinArray[i], LOW);
  }

  if (activePin == (pinCount - 1)) {
    activePin = (pinCount - 2);
    dx = -1;
  }

  if (activePin == 0) {
    activePin = 1;
    dx = 1;
  }

  activePin += dx;
  poti = analogRead(0);

  if (poti < 1023) {
    digitalWriteNot0(pinArray[activePin], HIGH);
    digitalWriteNot0(pinArray[activePin - dx], HIGH);
    digitalWriteNot0(pinArray[activePin - 2 * dx], HIGH);
  }

  Serial.print(poti);
  Serial.print(" - ");
  Serial.println(activePin);

  //delay(mintime+analogRead(0)/4); // <- Ich habe das Testweise mal rausgenommen.
  delay(5); // <- Wenn Du das hinbekommst sollte der Rest kein Problem sein IMHO, ich weiß leider nicht was dieses delay () macht.
}

// Funktion aus dem anderen Code
void digitalWriteNot0(int pin, boolean state) {
  if (pin > 0) {
    digitalWrite(pin, state);
  }
}

//###########################################
// Adafruit Funktionen <- Leider mit delay()!
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);
  }
}

void rainbow(uint8_t wait) {
  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);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
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);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q < 3; q++) {
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //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
      }
    }
  }
}

//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
      }
    }
  }
}

// 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);
}

lg dony

dony:
Hallo nochmal,

@Theseus: Du hast folgendes vorm Setup übersehen:

Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

Danke für den Hinweis, habe es oben gleich ergänzt.

Ich bin gespannt, ob meine Sketchmischung funktioniert. Mangels Aufbau kann ich es selber nicht testen.

Hi

Habe den Theseus->dony-Code Mal Probelaufen lassen.
Da ich nur WS2812B angeschlossen habe, wurde der Code etwas angepasst (damit nicht immer der ganze definierte RGB-Stripe mitblitzt - im Original also ganz ok).
Ich lasse die ersten 12 LEDs des Stripe 'als Stripe' laufen, die 'Anderen Pixel' als simulierte normale LEDs.

Mein Stripe hängt an Pin 13, weshalb die Pinne 5 und 13 Ihre Plätze tauschten - wurde in den Kommentaren aber erwähnt.

/*RGP-Stripes (WS2812B) + normale LEDs als Lauflicht.
 * 
 * Die RGB-Strip-LEDs flimmern/blitzen/wechseln die Farbe ect.pp. non stop
 * In jeder Runde wird auch das Lauflicht aufgerufen.
 * Im Ursprungscode lief so das Lauflicht schneller, wenn die Schleife kürzer war (weniger Unterbrechungen durch stripe.show())
 * Habe Das per millis() raus geholt.
 * 
 * Die Lauflichtgeschwindigkeit ist mit 100 (100ms Pause zwischen den einzelnen Schritten) noch etwas größer, als möglich wäre
 * Wenn Dir das Lauflicht also zu träge ist, kannst Du die wartezeit_lauflicht noch etwas verkleinern.
 * 
 * Theseus->dony-Sketch überarbeitet und 'Probeblinken lassen' by postmaster_ino
 * http://forum.arduino.cc/index.php?topic=527454.msg3597233#msg3597233
 */
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 13        //Hier hatte ich Deine 5 in meine 13 geändert

//weshalb hier auch die 5 auftaucht, aber die 13 nicht mehr - Du musst für Deinen Aufbau hier wieder die 5 zur Null machen und hinter der 12 eine 13 eintragen
byte pinArray[] = {0, 0, 0, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0};



const byte pinCount = 14;         //Hier die Anzahl an Neopixel eintragen, Die als 'normale LED' dienen - also für Karnevall =0


const byte rgb_pixel = 12;        //Hier die Anzahl an NeoPixel eintragen
Adafruit_NeoPixel strip = Adafruit_NeoPixel(rgb_pixel + pinCount, PIN, NEO_GRB + NEO_KHZ800);


byte activePin = 2;

int dx = 1;

uint16_t poti = 0;

uint32_t lastmillis;
uint32_t wartezeit_lauflicht = 100; //alle 100ms soll das Lauflicht 'Eins weiter'

void setup() { //Setup aus beiden Sketch zusammenkopiert

  Serial.begin(9600);

  for (int i = 0; i < pinCount; i++) {
    if (pinArray[i] != 0) {
      pinMode(pinArray[i], OUTPUT);
    }
  }

  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code


  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void lauflicht() { //loop erster Sketch
  if (millis() - lastmillis < wartezeit_lauflicht) {
    return;
  }
  lastmillis+=wartezeit_lauflicht;
  for (int i = 0; i < pinCount; i++) {
    digitalWriteNot0(pinArray[i], LOW);
  }

  if (activePin == (pinCount - 1)) {
    activePin = (pinCount - 2);
    dx = -1;
  }

  if (activePin == 0) {
    activePin = 1;
    dx = 1;
  }

  activePin += dx;


  poti = analogRead(0);


  if (poti < 1023) {

    digitalWriteNot0(pinArray[activePin], HIGH);

    digitalWriteNot0(pinArray[activePin - dx], HIGH);

    digitalWriteNot0(pinArray[activePin - 2 * dx], HIGH);

  }

  Serial.print(poti);
  Serial.print(" - ");
  Serial.println(activePin);
}

void digitalWriteNot0(int pin, boolean state) {
  if (pin > 0) {
    //digitalWrite(pin, state);
    //hier RGB > Position 12 (bei 5, also +7) setzen/löschen - für die normalen LEDs das digitalWrite wieder rein nehmen und Das hier auskommentieren
    strip.setPixelColor(pin + 7, state == true ? 0xFFFFFF : 0x000000);
  }
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
  //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < rgb_pixel; i++) { //strip.numPixels()
    strip.setPixelColor(i, c);
    strip.show();
    lauflicht(); // hier eingefügt
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < rgb_pixel; i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    lauflicht();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
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 < rgb_pixel; i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    lauflicht();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q < 3; q++) {
      for (uint16_t i = 0; i < rgb_pixel; i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
      }
      strip.show();
      lauflicht();
      delay(wait);

      for (uint16_t i = 0; i < rgb_pixel; i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

//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 < rgb_pixel; i = i + 3) {
        strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
      }
      strip.show();
      lauflicht();
      delay(wait);

      for (uint16_t i = 0; i < rgb_pixel; i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

// 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);
}

Hier blinkert's im Stripe-Bereich ganz furchterbar, da lobe ich mir den Lauflicht-Bereich :wink: (der blinkert nicht ganz so hektisch).
Bringe die LEDs so an, daß Du davon nicht das Meiste siehst ... oder lasse das Bier weg, sonst :confused:

Würde mir wünschen, wenn's Dich auch nach Karneval wieder hier vorbei spült - hast jetzt ja doch Deinen Sketch mundgerecht bekommen :o (bekommt hier lange nicht Jeder - quasi eine Ehre)

Viel Spaß damit und viele neidische Blicke

MfG

Edit
Theseus->dony Sketch, so viel Ehre muß sein! (hatte den Sketch irrtümlich nur dony in die Schuhe geschoben)

PS: Bis auf 50ms kannst Du runter gehen, eventuell auflaufende Ungenauigkeiten holt der Sketch bei den schnelleren Schleifen wieder auf.
Dazu habe ich mir eine kleine IF-Abfrage in die Pixel-Setz-Funktion integriert:

strip.setPixelColor(pin + 7, state == true ? wartezeit_last==wartezeit_lauflicht?0xFFFFFF:0xFF0000 : 0x000000);

Das setzt den entsprechenden 'Normal-LED-NeoPixel' auf Weiß, wenn die Wartezeit genau erreicht wurde, auf Rot, wenn wir uns verspätet haben und Schwarz, wenn der Pixel eh ausgeschaltet werden soll.
Vereinzelt blitzen weiße LEDs auf, so im Schnitt sind wir aber immer 10ms 'hinter der Zeit'.
Beim Start verschleppt sich Das bis auf knappe 300ms, Die wir 'zu spät sind', bei den kurzen Passagen wird diese Zeit aber wieder aufgeholt.
Wenn man Das nicht will, kann man auch

statt
lastmillis+=wartezeit_lauflicht;
eben
lastmillis=millis();

schreiben. Man hat dann zwar immer einen zeitlichen Versatz, Dieser wird aber nicht 'auf Biegen und Brechen' versucht, wieder aufzuholen.

So, soll erst Mal reichen.

postmaster-ino:
Edit
Theseus->dony Sketch, so viel Ehre muß sein! (hatte den Sketch irrtümlich nur dony in die Schuhe geschoben)

Richtig so! Den ich würde das Sketch doch eher Theseus->postmaster Sketch nennen, ich habe nur auf eine fehlende Zeile aufmerksam gemacht. :wink:

Mein Code ist nur zusammengeführt und Formatiert, ich hatte den 'Plan' das delay() aus dem ersten Teil zu entfernen und hoffen, das die Adafruit delays den Ablauf nicht stören. Plan B wäre eine Art Universall Lösung für die Adafruit delays gewesen.

Ich möchte keine falschen Lorberren.

lg dony

Nix >:(

Mit Gegangen, mit Gefangen, mit Gelorbeert!! (musst die Dinger ja nicht essen)

MfG

postmaster-ino:
...musst die Dinger ja nicht essen..

Na dann is ja gut. :wink:
lg dony