• The transitions are achieved by modulation pwm - modifying duty cycle - from 0 to 1 and back using sine wave -and overlay this modulation with another sine wave - sine modulating the speed of the sine wave that modulates the pwm duty cycle. This is done for each color - R, G and B - with all individual and different wave lengths - frequencies - totally six (6). Initially I had only the pwm modulation on different modulation frequencies. But even though they were all different in frequency AND also prime numbers, pretty flat rhythm was felt. Thats why I overlaid the initial waves with a second wave. The difference it very noticeable and the light intensity and color change feels more what nature shows, for example, the ocean waves that crash coming ashore and pushing bubbly water up a sandy, slightly sloped beach: it is not just a 'come and go', but more like a come a bit, retreat a little bit, and then advance more, almost like the ascend over pre-peaks to the main peak when mountain hiking.

    The modules have an IR receiver, some attiny875 chip and a 1kx8 flash EEPROM for controlling 4 banks of RGB 2 x 3 LEDs. Since this control setup did not budge anymore, I removed these three components and connected wires to the Base/Gate of 'power' bipolar Transistor / FET and control latter with pins A1, A2 and A3 of a PICO. The RGB LED side of the modules is 12V driven with the RGB LEDs on the HIGH side and the bipolar Transistor / FET on the LOW side.

    And here is the code in a very - flat - implementation.

    // someTriColors.js
    // (c)20181101 allObjects
    // reusing ir colorable interior lights
    // sine modulated sine modulated pwm...
    var itpf =   2; // interval time pwm factor
    var itdf =   5; // interval time pwm delta factor
    var pi2  = Math.PI*2, rdd = pi2 / 90;
    var pr   =  A1, pg   =  A2, pb   =  A3; // pin for r, g and b
    
    var pwmr =   0, pwmg =   0, pwmb =   0; // pwm value of r, g and b
    var pwdr = rdd, pwdg = rdd, pwdb = rdd; // pwm delta (increment)
    var itpr =   7, itpg =  11, itpb =  17; // pwm interval time of r, g and b
    var iipr      , iipg      , iipb      ; // pwm interval id of r, g and b
    
    var pddr =   0, pddg =   0, pddb =   0; // pwm delta delta
    var itdr =  30, itdg =  37, itdb =  47; // pwm delta delta interval time
    var iidr      , iidg      , iidb      ; // pwm delta delta interval id of r, g and 
    
    function adpr() {
      pwmr = ((pwmr += pwdr) < pi2) ? pwmr : 0;
      analogWrite(pr,(1 + Math.sin(pwmr)) / 2);
    }
    function adpg() {
      pwmg = ((pwmg += pwdg) < pi2) ? pwmg : 0;
      analogWrite(pg,(1 + Math.sin(pwmg)) / 2);
    }
    function adpb() {
      pwmb = ((pwmb += pwdb) < pi2) ? pwmb : 0;
      analogWrite(pb,(1 + Math.sin(pwmb)) / 2);
    }
    
    function addr() {
      pddr = ((pddr += rdd) < pi2) ? pddr : 0;
      pwdr = rdd * ((1 + Math.sin(pddr)) / 2);
    }
    function addg() {
      pddg = ((pddg += rdd) < pi2) ? pddg : 0;
      pwdg = rdd * ((1 + Math.sin(pddg)) / 2);
    }
    function addb() {
      pddb = ((pddb += rdd) < pi2) ? pddb : 0;
      pwdb = rdd * ((1 + Math.sin(pddb)) / 2);
    }
    
    function goPWMs() {
      iipr = setInterval(adpr,itpr * itpf);
      iipg = setInterval(adpg,itpg * itpf);
      iipb = setInterval(adpb,itpb * itpf);  
    }
    
    function goDeltas() {
      iidr = setInterval(addr,itdr * itdf);
      iidg = setInterval(addg,itdg * itdf);
      iidb = setInterval(addb,itdb * itdf);  
    }
    
    function onInit() {
       goPWMs();
       goDeltas();
    }
    
    setTimeout(onInit,1000);
    

    Code is 'flat' because it is 3 (6) times the same: modifying / modulating something with a sine wave... with everything done for each individual color R, G, and B. 'flat' is faster in execution... even though speed is of no essence right now... When cranking up the cycles though, it could come to matter.

    Next - unrelated - exercise will be the checking out of the remote and the IR receiver... ;-)

About

Avatar for allObjects @allObjects started