ph1p / ikea-led-obegraensad

ESP32/Arduino hack for the ikea OBEGRÄNSAD led wall lamp
MIT License
578 stars 78 forks source link

Pixel-wise brightness #19

Closed letalvoj closed 1 year ago

letalvoj commented 1 year ago

One of the original modes (the Matrix rain like falling stripes) has two different tones. The bottom most dot is more bright than the rest of the stripe.

Screenshot 2023-01-23 at 22 09 52

@ph1p have you mentioned that? It be nice to control the brightness.

mlemarrec commented 1 year ago

Hello, There is no way to change the brightness of only one pixel. Ikea play with the retinal persistence.

Here a code to do it with an other library: https://github.com/mlemarrec/ObegransadPanel

  int8_t* rainBuf = (int8_t*) malloc(16 * sizeof(int8_t));
  bool raintInit = false;

  void rain() {

    if( !raintInit ) {
      for( uint8_t x = 0; x<16; x++) {
        rainBuf[x] = random( -64, -1);
      }
      raintInit = true;
    }

    // 8 loop for retina persistence
    for( uint8_t i = 0; i<8; i++) {
      panel.clear();
      analogWrite(PIN_ENABLE, 192);delay(1);
      for( int8_t x = 15; x >= 0; x-- ){
        for( int8_t y = 4; y >= 0; y-- ){
          panel.drawPixel( x, rainBuf[x]+y, 1);
        }
      }
      panel.scan();
      delay(2);

      panel.clear();
      analogWrite(PIN_ENABLE, 0);delay(1);
      for( int8_t x = 15; x >= 0; x-- ){
        panel.drawPixel( x, rainBuf[x]+4, 1);
      }
      panel.scan(); 
      delay(8);
    }  

    for( uint8_t x=0; x<16; x++){
        if( rainBuf[x] < 16) { rainBuf[x]++; }
        else { rainBuf[x] = random( -64, -1);}
    }

  }
mlemarrec commented 1 year ago

And here an other code (k2000 effect) with 3 brightess and retina persistance:

int8_t k2000x = 3;
int8_t k2000d = 1;

void k2000() {

  uint8_t xmin = 3;
  uint8_t xmax = 15 - xmin;

  uint8_t ymin = 7;
  uint8_t ymax = 15 - ymin -1;

  // loop for retinal persistence
  for( uint8_t i = 0; i< 10; i++) {

    panel.clear();
    analogWrite(PIN_ENABLE, 192);delay(1);

    for( int8_t y = ymin; y <= ymax; y++ ){
      for( int8_t x = xmin; x <= xmax; x++ ){
        if( x >= k2000x - 2 && x <= k2000x + 2 ) {
          panel.drawPixel( x, y, 1);
        }        
      }
    }
    panel.scan();
    delay(2);

    panel.clear();
    analogWrite(PIN_ENABLE, 96);delay(1);
    for( int8_t y = ymin; y <= ymax; y++ ){  
      if( k2000x - 1 >= xmin) { panel.drawPixel( k2000x-1, y, 1); }
      panel.drawPixel( k2000x, y, 1);
      if( k2000x + 1 <= xmax) { panel.drawPixel( k2000x+1, y, 1); }

    }
    panel.scan(); 
    delay(4);

    panel.clear();
    analogWrite(PIN_ENABLE, 0);delay(1);
    for( int8_t y = ymin; y <= ymax; y++ ){  
      panel.drawPixel( k2000x, y, 1);
    }
    panel.scan(); 
    delay(6);    
  }  

  if( k2000d == 1) { k2000x++; }
  else { k2000x--; }

  if( k2000x == xmin) { k2000d = 1; }
  if( k2000x == xmax) { k2000d = 0; }

}
ph1p commented 1 year ago

Now possible :)