• Hi there !

    I hadn't really considered that, but yes, that would work great.

    Actually, I thought about it when reading your suggestion ;p

    For the SD card you have a chip select pin so that might give you something you can use as well?

    Indeed: it also gives me a ( silly ? ) idea: using the SDCARD SPI CS pin as the pin on which to set the APA102 SPI CLK () so that the APA102 CLK 'll be tied low while the SD card is in use ? ( so by writing to the SD, it shall auto-disable the APA102 comm ? I guess it'd be even better than tying the SD CS pin to Gnd & then doing the above 'different pin for the clock signal' hack ? )
    -> I gotta try those tomorrow ;)

    Onto the "2pins analog setWatch" hack, I had some success with a quite simple circuit in which the A0 pin ( on which a digital setWatch() is set ) is connected directly to the A1 pin, used as analog input.
    An external 10k pulldown & setting it as "analog" did the trick on giving me slightly more meaningfull results :)
    In order to get reliable results ( and this, without an added transitor as I first planned ), the least voltage I get is 2.09V ( so some safety from 1.70 ;p )
    I didn't try ( yet ? ) adding a "small" ( 1 uF ? ) cap - how would it "smooth" the result ?

    put the battery charge status and/or toggle switch on exactly the same A0 pin as well. If your 5 voltages are 2v,2.25v,2.5v,2.75v and 3v then if the toggle switch varied the voltage by 0.05v you could detect that.

    I'm not sure yet if my setup is precise enought & on how to implement that ( for either the batt. status pin, the toggle, or both ? .. - I plan to use the MCP73831 's stat pin as battery status pin, for info .. )

    Now, the voltages I currently get ( from the resistor values I could find around easily ) are the ones in the following code, I'm currently happy with those ( seems to work flawlessly ), but if anyone has hints on better resistor values, I'm a taker ;)

    nb: I'm not quite sure of the followings ( gotten using successive tries on tinkercad .. ), but these may be the resistor values you had in mind to produe your proposed voltages ?
    ( all the followings uses a 10k pulldown as R1 )
    3.3Vin-> 3Vout => R2: 1315 Ohms
    3.3Vin-> 2.75Vout => R2: 2350 Ohms
    3.3Vin-> 2.5Vout => R2: 3600 Ohms
    3.3Vin-> 2.25Vout => R2: 5100 Ohms
    3.3Vin-> 2.00Vout => R2: 7000 Ohms

    So, here's some wip working code :)

    // trying to get this 5-way switch from 5 pins down to 1 digital
    // ( for setWatch() ) & one analog ( to read the five different values through different resistors )
    
    // pin 0 has the digital watch on it
    pinMode(A0, "input_pulldown");
    //pinMode(A1, "input"); // has external 10k pulldown resistor
    pinMode(A1, "analog"); // has external 10k pulldown resistor -> yup, I am DUMB !
    /*
    setWatch(function(e) {
      console.log('A0 pressed');
      console.log('A1 biggest is: ' + analogReadBiggest(A1, 1000));
      console.log('A1 lowest is: ' + analogReadLowest(A1, 1000));
    }, A0, { repeat:true, edge:'rising', debounce:100 });
    */
    
    // wip 'analog2pinWatch'
    function setWatchA(digitalPin, analogPin, callbackFcn){
      setWatch(function(e) {
        callbackFcn(analogRead(analogPin)*3.3);
      }, digitalPin, { repeat:true, edge:'rising', debounce:100 });
    }
    // usage:
    setWatchA(A0, A1, function(buttonAnalogVal){
      console.log('button on A0 pressed: analog read =' + buttonAnalogVal);
      if(buttonAnalogVal > 3.15) console.log('btn1');
      else if(buttonAnalogVal > 2.85) console.log('btn2');
      else if(buttonAnalogVal > 2.50) console.log('btn3');
      else if(buttonAnalogVal > 2.30) console.log('btn4');
      else if(buttonAnalogVal > 2.00) console.log('btn5');
      //else if(buttonAnalogVal > 1.70) console.log('btn6'); // N/A for 5-way switch ..
    });
    
    // for a 10k pulldown & pinMode(A1, "analog"), we get the below outputs
    // 1:
    // 10k & nothing  ( 500 readings using analogReadBiggest) -> 0.99708552681 | *3.3 = 3.29038223847
    // 10k & nothing  ( 500 readings using analogReadLowest) ->  0.99781795986 | *3.3 = 3.29924467841
    // 2:
    // 10k & 1k ( 500 readings using analogReadBiggest)     ->   0.90626382848 | *3.3 = 2.99067063398
    // 10k & 1k ( 500 readings using analogReadLowest)     ->    0.90553139543 | *3.3 = 2.98825360491
    // 3:
    // 10k & 2.2k ( 500 readings using analogReadBiggest)     -> 0.82032501716 | *3.3 = 2.70707255662
    // 10k & 2.2k ( 500 readings using analogReadLowest)     ->  0.82008087281 | *3.3 = 2.70626688027
    // 4:
    // 10k & 3.2k ( 500 readings using analogReadBiggest)     -> 0.75660334172 | *3.3 = 2.49679102767
    // 10k & 3.2k ( 500 readings using analogReadLowest)     ->  0.75611505302 | *3.3 = 2.49517967496
    // 5:
    // 10k & 4.7k ( 500 readings using analogReadBiggest)     -> 0.67969787136 | *3.3 = 2.24300297548
    // 10k & 4.7k ( 500 readings using analogReadLowest)     ->  0.67896543831 | *3.3 = 2.24058594642
    // 6:
    // 10k & 5.7k ( 500 readings using analogReadBiggest)     -> 0.63526359960 | *3.3 = 2.09636987868
    // 10k & 5.7k ( 500 readings using analogReadLowest)     ->  0.63648432135 | *3.3 = 2.10039826045
    // 7:
    // 10k & 10k  ( 500 readings using analogReadBiggest)     -> 0.50074006256 | *3.3 = 1.65244220644
    // 10k & 10k  ( 500 readings using analogReadLowest)     ->  0.50074006256 | *3.3 = 1.65244220644
    
    // R: currently testing with A0 wire going directly to A1 'line' ( that is, without any transistor )
    // when helding a button pressed:
    // 1:
    // A1 biggest is: 0.99977111467
    // A1 lowest is: 0.99977111467
    // 2:
    // A1 biggest is: 0.88697642481
    // A1 lowest is: 0.88966201266
    // 3:
    // A1 biggest is: 0.78223849851
    // A1 lowest is: 0.78590066376
    // 4:
    // A1 biggest is: 0.71729610131
    // A1 lowest is: 0.71705195696
    // 5:
    // A1 biggest is: 0.63062485694
    // A1 lowest is: 0.62940413519
    

    This being said, I'm onto drawing a little "delayed power off" circuit that may be useful to get on one ( not shared ) pin as well ;)

    Thanks for the precious hints :)
    +

About

Avatar for stephaneAG @stephaneAG started