Trap met verschillende lengtes ledstrips

Arduino specifieke Software
Berichten: 6
Geregistreerd: 12 Dec 2017, 21:46

Trap met verschillende lengtes ledstrips

Berichtdoor mauricebrammer » 17 Dec 2017, 14:44

Goede middag allemaal,

Sinds kort ben ik lekker aan het knutselen met een Arduino UNO in combinatie met een ledstrip (ws2812b leds). Naast de leuke effecten waarmee ik testte wil ik de trap gaan verlichten (14 treden).

Alles had ik voor elkaar echter lijkt het mij toch mooier om de trappen over de gehele lengte te voorzien van led strips. Daar zit nu mijn issue dat de trap treden niet allemaal hetzelfde zijn.

Ik heb hieronder de gebruikte code (voor gelijke trappen) al iets aangepast, maar momenteel zit ik "vast". Geen idee of ik op deze manier de leds het beste kan aansturen en hoe ik deze groepen van leds aangestuurd krijg in de resterende code.
In deze test opstelling heb ik 1 strip van 90 leds opgedeeld in 4 stukken met elk een eigen aantal leds. De pir functie en de fading blauwe leds werken goed. (De trap aansturing rekent nu nog op 15 treden van ieder 6 leds bij vaste lengtes.)

Heeft er iemand tips en tricks hoe ik deze setup werkend kan krijgen? Ik heb al behoorlijk lopen zoeken naar voorbeelden, maar of ik zoek verkeerd of maar heel weinig mensen hebben een trap zoals die van ons.

Code: Alles selecteren
// Aangepaste trap

#include <Adafruit_NeoPixel.h>

#define PIN 6

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

// Set up Variables
 unsigned long timeOut=60000; // timestamp to remember when the PIR was triggered.
 int downUp = 0;              // variable to rememer the direction of travel up or down the stairs
 int alarmPinTop = 10;        // PIR at the top of the stairs
 int alarmPinBottom =11;      // PIR at the bottom of the stairs
 int alarmValueTop = LOW;    // Variable to hold the PIR status
 int alarmValueBottom = LOW; // Variable to hold the PIR status
 int ledPin = 13;           // LED on the arduino board flashes when PIR activated
 int colourArray[350];      // An array to hold RGB values
 int change = 1;            // used in 'breathing' the LED's
 int breathe = 0;           // used in 'breathing' the LED's
 
//4 groepen van leds, elke groep is een trede. Deze test 4 tredes.
int group0[] =  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1};
int group1[] =  {21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, -1};
int group2[] =  {43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, -1};
int group3[] =  {69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, -1};

void setup() {
   strip.begin();
   strip.setBrightness(40); //adjust brightness here
   strip.show(); // Initialize all pixels to 'off'
   Serial.begin (9600);  // only requred for debugging
   pinMode(ledPin, OUTPUT);  // initilise the onboard pin 13 LED as an indicator
   pinMode(alarmPinTop, INPUT_PULLUP);     // for PIR at top of stairs initialise the input pin and use the internal restistor
   pinMode(alarmPinBottom, INPUT_PULLUP);  // for PIR at bottom of stairs initialise the input pin and use the internal restistor
   delay (2000); // it takes the sensor 2 seconds to scan the area around it before it can
   //detect infrared presence.

}
// set van 2 leds vanaf de buitenkant oplichten met 1 led aan het begin van de buitenkant ertussen
void loop() {

    if (timeOut+20700 < millis()) {        // idle state - 'breathe' the top and bottom LED to show program is looping
       uint32_t blue = (0, 0, breathe);
       breathe = breathe + change;
       strip.setPixelColor(1, blue);
       strip.setPixelColor(2, blue);
       strip.setPixelColor(18, blue);
       strip.setPixelColor(19, blue);
       strip.setPixelColor(22, blue);
       strip.setPixelColor(23, blue);
       strip.setPixelColor(40, blue);
       strip.setPixelColor(41, blue);
       strip.setPixelColor(44, blue);
       strip.setPixelColor(45, blue);
       strip.setPixelColor(66, blue);
       strip.setPixelColor(67, blue);
       strip.setPixelColor(70, blue);
       strip.setPixelColor(71, blue);
       strip.setPixelColor(87, blue);
       strip.setPixelColor(88, blue);
       strip.show();
       if (breathe == 100 || breathe == 0) change = -change;     
       if (breathe == 100 || breathe == 0); delay (100);           
       delay(10);

     
  }
  // Pir detectie
    alarmValueTop = digitalRead(alarmPinTop);    // Constantly poll the PIR at the top of the stairs
    //Serial.println(alarmPinTop);
    alarmValueBottom = digitalRead(alarmPinBottom);  // Constantly poll the PIR at the bottom of the stairs
    //Serial.println(alarmPinBottom);
   
    if (alarmValueTop == HIGH && downUp != 2)  {      // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.
      timeOut=millis();  // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 1;
      //clearStrip();
      topdown();         // lights up the strip from top down
    }
 
    if (alarmValueBottom == HIGH && downUp != 1)  {    // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.
      timeOut=millis();    // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 2;
      //clearStrip();
      bottomup();         // lights up the strip from bottom up
    }

    if (timeOut+15000 < millis() && timeOut+20000 < millis()) {    //switch off LED's in the direction of travel.
       if (downUp == 1) {
          colourWipeDown(strip.Color(0, 0, 0), 100); // Off
       }
       if (downUp == 2)  {
        colourWipeUp(strip.Color(0, 0, 0), 100);   // Off
       }
      downUp = 0;
     
    }
         
}

 void topdown() {
    Serial.println ("detected top");                  // Helpful debug message
    colourWipeDown(strip.Color(255, 255, 250), 25 );  // Warm White
 }

 void bottomup() {
    Serial.println ("detected bottom");            // Helpful debug message
    colourWipeUp(strip.Color(255, 255, 250), 50);  // Warm White + tijd van wachten tussen elke trede
  }

// Hieronder nog het deel wat er vanuit gaat dat er een gelijk aantal leds zijn per trede. 90 leds en 15 tredes.

 // Fade light each step strip
 void colourWipeDown(uint32_t c, uint16_t wait) {

 for (uint16_t j = 0; j < 15; j++){ // het aantal strips is hierin 15
 int start = strip.numPixels()/15 *j; //aantal led /15 = 6
 Serial.println(j);
   
    for (uint16_t i = start; i < start + 6; i++){ // het aantal leds per trede 6. 90 /6 = 15
     strip.setPixelColor(i, c);
        }
        strip.show(); 
  delay(wait);
  }
 }

void clearStrip(){
  for (int l=0; l<strip.numPixels(); l++){
    strip.setPixelColor(l, (0,0,0));
  }
     
}
 // Fade light each step strip
 void colourWipeUp(uint32_t c, uint16_t wait) {
   for (uint16_t j = 15; j > 0; j--){
   int start = strip.numPixels()/15 *j;
   Serial.println(j);
      //start = start-1;
          for (uint16_t i = start; i > start - 6; i--){
           strip.setPixelColor(i-1, c);
         }
          strip.show();
  delay(wait);
  } 
 
 }

 

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Trap met verschillende lengtes ledstrips

Berichtdoor nicoverduin » 17 Dec 2017, 15:04

Waarom ga je niet uit van de langste lengte? Voor de strip maakt het niets uit. als de strip 10 lang is en je zou er 50 naartoe sturen, dan toont hij gewoon de laatste 10.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 6
Geregistreerd: 12 Dec 2017, 21:46

Re: Trap met verschillende lengtes ledstrips

Berichtdoor mauricebrammer » 17 Dec 2017, 15:28

Dat is een interessant idee :)

Echter zit ik dit in mijn hoofd voor te stellen. In deze test opzet zou ik dan 4 x 26 leds hebben. In totaal 104.
Ga ik die 104 delen door 4 treden dan lichten er 26 leds in volgorde op (het is 1 strip aan elkaar). Terwijl de eerste trede 21 leds heeft (dan "virtueel" 26).
Ik kan natuurlijk eenvoudig zeggen ik plaats de overige leds aan de binnenkant van de trap om de 26 te halen, maar dan wil ik eigenlijk voorkomen).

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Trap met verschillende lengtes ledstrips

Berichtdoor nicoverduin » 17 Dec 2017, 16:12

Nu vertel je weer wat anders. Als ik je begrijp wil je dus een strip over 4 treden verdelen?
Tip: Ik zou eerst eens experimenteren met zo'n strip..... Waarom... Omdat je, naar het lijkt nog niet echt een idee hebt hoe je met zo'n strip om moet gaan.
Enne voor de duidelijkheid heb ik ooit een project gedaan met ruim 300 leds in serie die verdeeld waren over verschillende segmenten met verschillende patronen (en kleuren) en ook nog eens lopende onderdelen over de hele strip. En alles op een UNO. Dus het kan.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 6
Geregistreerd: 12 Dec 2017, 21:46

Re: Trap met verschillende lengtes ledstrips

Berichtdoor mauricebrammer » 17 Dec 2017, 16:43

Klopt helemaal, uiteindelijk komt elke trede aan elkaar (+/- 300 leds). Het zou dus gezien kunnen worden als 1 grote led strip verdeeld over 14 groepjes van x aantal leds per groep.

Kleuren, effecten lopen momenteel hier over de strip hier en dat lukt allemaal. Zo ook de trap versie waarbij elke trede hetzelfde aantal leds bevat. Deze opzetten maken allemaal gebruik van totaal aantal leds en niet verdeeld in groepen.

Dat is nu net het gedeelte waar ik niet uit kom of geen voorbeeld van kan vinden hoe verschillende hoeveelheden leds aangestuurd kunnen worden in deze of een andere opzet waar met groepjes led wordt gewerkt.

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Trap met verschillende lengtes ledstrips

Berichtdoor nicoverduin » 17 Dec 2017, 17:17

Een ledstrip kun je zien als een grote tabel. Elke trede in die tabel heeft een startpunt en het aalntal leds voor die trede. Je hebt dus een 2e tabel nodig die aangeeft wat de start index is het aantal leds. Die verwijst dus weer naar de ledstrip tabel
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Trap met verschillende lengtes ledstrips

Berichtdoor shooter » 17 Dec 2017, 18:56

zet die groepnummers ook in een array, dan heb je dus een aantal group die elk een aantal leds bevatten.
die zet je klaar door ze ieder een effect te geven, en dan begin je ze achter elkaar uit te sturen, dus eerst group [0].led[0] dan group[0] led [1] als de code -1 is dan group[1] led[0] enz.
dan staan ze allemaal achter elkaar.
Zorg wel dat de voeding op elke trede opnieuw aangesloten is, je hebt wel je data lijnen die dan van achter naar voor moeten lopen, alhoewel je ook met die draadjes kunt zigzaggen, dat is in software op te lossen door de array nummers te veranderen.
paul deelen
shooter@home.nl

Berichten: 6
Geregistreerd: 12 Dec 2017, 21:46

Re: Trap met verschillende lengtes ledstrips

Berichtdoor mauricebrammer » 17 Dec 2017, 19:43

Ik ga daar eens verder mee experimenteren.

Uiteindelijk ga ik vanuit de rechterkant (binnenkant trap) de strip laten beginnen. De datalijn zal dan inderdaad zigzaggend verbonden worden (Op dit moment nog).
Voeding ga ik waarschijnlijk opsplitsen in 3 delen, maar dat ligt er een beetje aan welke voeding ik ga inzetten.

Eerst maar eens mijn test opstelling van 4 strips voor elkaar krijgen :)

Berichten: 6
Geregistreerd: 12 Dec 2017, 21:46

Re: Trap met verschillende lengtes ledstrips

Berichtdoor mauricebrammer » 16 Jan 2018, 20:04

Het is even geleden, maar met behulp van een collega van het werk is het toch gelukt. Momenteel al druk bezig met het installeren van de strips op de trap zelf en uiteindelijk moet de code nog wat uitgebreid worden, maar wilde alvast de test opstelling/code met jullie delen. Vervolg komt later.

Code: Alles selecteren
// Aangepaste trap

#include <Adafruit_NeoPixel.h>

#define PIN 6

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

// Set up Variables
 unsigned long timeOut=60000; // timestamp to remember when the PIR was triggered.
 int downUp = 0;              // variable to rememer the direction of travel up or down the stairs
 int alarmPinTop = 10;        // PIR at the top of the stairs
 int alarmPinBottom =11;      // PIR at the bottom of the stairs
 int alarmValueTop = LOW;    // Variable to hold the PIR status
 int alarmValueBottom = LOW; // Variable to hold the PIR status
 int ledPin = 13;           // LED on the arduino board flashes when PIR activated
 int colourArray[350];      // An array to hold RGB values
 int change = 1;            // used in 'breathing' the LED's
 int breathe = 0;           // used in 'breathing' the LED's
 
//Trap trede groepen

int begintrede[4] = {0, 21, 43, 69};
int eindtrede[4] = {20, 42, 68, 89};

void setup() {
   strip.begin();
   strip.setBrightness(40); //adjust brightness here
   strip.show(); // Initialize all pixels to 'off'
   Serial.begin (9600);  // only requred for debugging
   pinMode(ledPin, OUTPUT);  // initilise the onboard pin 13 LED as an indicator
   pinMode(alarmPinTop, INPUT_PULLUP);     // for PIR at top of stairs initialise the input pin and use the internal restistor
   pinMode(alarmPinBottom, INPUT_PULLUP);  // for PIR at bottom of stairs initialise the input pin and use the internal restistor
   delay (2000); // it takes the sensor 2 seconds to scan the area around it before it can
   //detect infrared presence.

}

void loop() {

    if (timeOut+20700 < millis()) {        // idle state - 'breathe' the top and bottom LED to show program is looping
       uint32_t blue = (0, 0, breathe);
       breathe = breathe + change;
       strip.setPixelColor(1, blue);
       strip.setPixelColor(2, blue);
       strip.setPixelColor(18, blue);
       strip.setPixelColor(19, blue);
       strip.setPixelColor(22, blue);
       strip.setPixelColor(23, blue);
       strip.setPixelColor(40, blue);
       strip.setPixelColor(41, blue);
       strip.setPixelColor(44, blue);
       strip.setPixelColor(45, blue);
       strip.setPixelColor(66, blue);
       strip.setPixelColor(67, blue);
       strip.setPixelColor(70, blue);
       strip.setPixelColor(71, blue);
       strip.setPixelColor(87, blue);
       strip.setPixelColor(88, blue);
       strip.show();
       if (breathe == 100 || breathe == 0) change = -change;     
       if (breathe == 100 || breathe == 0); delay (100);           
       delay(10);

     
  }
 
    alarmValueTop = digitalRead(alarmPinTop);    // Constantly poll the PIR at the top of the stairs
    //Serial.println(alarmPinTop);
    alarmValueBottom = digitalRead(alarmPinBottom);  // Constantly poll the PIR at the bottom of the stairs
    //Serial.println(alarmPinBottom);
   
    if (alarmValueTop == HIGH && downUp != 2)  {      // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.
      timeOut=millis();  // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 1;
      //clearStrip();
      topdown();         // lights up the strip from top down
    }
 
    if (alarmValueBottom == HIGH && downUp != 1)  {    // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.
      timeOut=millis();    // Timestamp when the PIR is triggered.  The LED cycle wil then start.
      downUp = 2;
      //clearStrip();
      bottomup();         // lights up the strip from bottom up
    }

    if (timeOut+15000 < millis() && timeOut+20000 < millis()) {    //switch off LED's in the direction of travel.
       if (downUp == 1) {
          colourWipeDown(strip.Color(0, 0, 0), 100); // Off
       }
       if (downUp == 2)  {
        colourWipeUp(strip.Color(0, 0, 0), 100);   // Off
       }
      downUp = 0;
     
    }
         
}

 void topdown() {
    Serial.println ("detected top");                  // Helpful debug message
    colourWipeDown(strip.Color(255, 255, 250), 125 );  // Warm White
 }

 void bottomup() {
    Serial.println ("detected bottom");            // Helpful debug message
    colourWipeUp(strip.Color(255, 255, 250), 250);  // Warm White + tijd van wachten tussen elke trede
  }


 // Fade light each step strip
 void colourWipeDown(uint32_t c, uint16_t wait) {

   for (uint16_t j = 0; j < 4; j++){
     Serial.println(j);
     for (uint16_t i = begintrede[j]; i <= eindtrede[j]; i++){
        strip.setPixelColor(i, c);
     }
     strip.show(); 
     delay(wait);
   }
 }

void clearStrip(){
  for (int l=0; l<strip.numPixels(); l++){
    strip.setPixelColor(l, (0,0,0));
  }
     
}
 // Fade light each step strip
 void colourWipeUp(uint32_t c, uint16_t wait) {
   for (uint16_t j = 4; j > 0; j--){
     Serial.println(j);
     for (uint16_t i = eindtrede[j]; i >= begintrede[j]; i--){
       strip.setPixelColor(i, c);
     }
     strip.show();
     delay(wait);
   } 
 }

 



Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: Trap met verschillende lengtes ledstrips

Berichtdoor Koepel » 16 Jan 2018, 20:27

Sorry dat ik wat aan te merken heb, maar het gebruik van millis() werkt niet op die manier. Nou ja, het werkt wel, de eerste 50 dagen.
Mijn stokpaardjes zijn nu eenmaal I2C en millis().

Dit is de BlinkWithoutDelay: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay.
Daar kunnen beginnen om millis() goed te gaan gebruiken.

Volgende

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 21 gasten