• ...did dig up the code:

    `
    // resonance.js
    // resonance experiment
    // PWM signal generator with variable frequency
    // agitates LC with variable L and C
    // observed to find resoncances
    
    // *** Exciter, resonance, detector circuit
    //
    // <--sigPin ----------------------------------------­-. 
    //   resonance                 TP3  TP4           TP5 | 
    //   signal s      multi-tap  /    /     D       /    | 
    //   detected  MW(AM) HF Air .----.-----|>|-----.-----: 
    //   0..290mV  Coil 100 wind |    |  Ge E110LF  |     | 
    //               0.5mm Cu on (    |  Si 1N4148  |     | 
    //               41mm/1-5/8" (    |             |     | 
    //         _                 (    |             |+    | 
    //    TP1 | |_| 3.3VPP   TP2 (   ===           ===    / 
    //   /                  /    (    | Cx      C1 ---    \ 
    // >.-outPin--/\/\/\-->.     (    | 1nF    3.3u |-    / 
    //   PWM      R1 330R  )     (    | 2.2n*       |  R2 \ 
    //   variable          )  8x (    | 3.2n        | 56K / 
    //   frequency f    20 )  10 (    | 4.7n        |     | 
    //   32K..262KHz...  w |   w |    | 5.7n        |     | 
    //   for receiver      |     |    | 9.4n        |     | 
    //   antenna          ___   ___  ___           ___   ___
    //   simulation        -     -    -             -     - 
    //                     .     .    .             .     . 
    
    // *** UI / Control / Feedback circuitry to vary frequency f
    //
    // <-slidePin------------------------------­-------------------. 
    //   0..3.3V                                                  | 
    //            3.3V      3.3V      3.3V      3.3V  3.3V        | 
    //              ^         ^         ^         ^     ^         | 
    //              |         |         |   extra |     |         | 
    //              |         |         | read of |     |         | 
    //              \  f down |    f up |  signal |     /         | 
    //           R3 /  button |  button |  button |     \         | 
    //    100..300R \     red |   green |  yellow |  R4 /    R5   | 
    //              /   SW1 |      SW2 |     SW3 |  10K \<-/\/\/\-: 
    //              |         |         |         | Sli /    1K   | 
    //             .-./|      |         |         | der \         | 
    //     speaker | | |      |         |         |     /         | 
    //             '-'\|      |         |         |     \         | 
    //    _        +|         |         |         |     |         | 
    //   | |_|     ===        |         |         |     |         | 
    //   3.3VPP    --- C2     |         |         |     |         |+
    //   PWM       -| 33u     |         |         |     |        ===
    // >-audioPin-->'         |         |         |     |     C3 ---
    //   wave 7 octaves lower |         |         |     |    3.3u |-
    //                        |         |         |     |         | 
    // <-btnPins[1]-----------'         |         |     |         | 
    // <-btnPins[0]---------------------'         |    ___       ___
    // <-sRBtnPin------------------------------­---'     -         - 
    // internal input_pulldown (30k..40K)               .         . 
    
    var go        = true   // keep going on self invocation / 'interval'
      , f         = -1     // frequency put out
      , fMin      = 32768  // lowest used freequency
      , fMax      = 262144 // highst, 65536 * 4 = 18 bits unsigned ()
      , fUp       = true   // frequency hopping up (wobble)
      , outPin    = B7     // wave exciting antenna coil
      , duty      = 0.5    // 0..1
      , audioPin  = B10    // speaker
      , audioDiv  = 128    // 7 octavae lower into audible space
      , s         = 0.0       // signal (resonance, rectified) - discrete
      , smV       = 0.0       // signal in [mV], continuously
      , sigPin    = A0        // signal pin (analog read 0..1=0..3.3V)
      , sChngSens = 0.7       // signal change sensitivity relative
      , sCalib    = 303.334   // signal calibration to show mV
      , sRBtnPin  = B13       // singal extra read button pin
      , ctrlMode  = 0         // 0=buttons, 1=slider
      , ctrlModeI = 1000 // [ms] delay after ctrlMode chnage
      , btnPins   = [B15,B14] // down|up button, both = ctrlMode change
      , debounced = false     // on button press do custom debounce
      , debounceI = 10   // [ms] debounce interval
      , btnHopInt = 10   // [ms] button hop interval min, slider modified
      , btnHopMul = 49        // button hop interval extension multiplier
      , slidePin  = B1        // analog to read voltage divider from slider
      , slideVal  = 0.0       // last read different slider value
      , slideSens = 0.003     // slider sensitivity to detect different val
      , slideAdjM = -0.005    // adjust slider min to cover [0..1]
      , slideAdjR = 1.05      // adjust slider range to cover [0..1]
      , slideHopI = 50   // [ms] slider check/hop interval
      ;
    var hTFact = 1.059463094359; // half tone factor (2**1/12)**12 = 2 oktav
    var qTFact = 1.029302236643495; // quarter tone  (2**1/24)**24 = 2 oktav
    var eTFact = 1.014545334937521; // eight tone f  (2**1/48)**48 = 2 oktav
    
    var lon = true; // log on
    function log() { console.log.apply(console,arguments); }
    
    pinMode(outPin,"output");
    pinMode(sigPin,"analog");
    pinMode(sRBtnPin,"input_pulldown");
    btnPins.forEach(function(b){ pinMode(b,"input_pulldown"); });
    pinMode(slidePin,"analog");
    
    var cnt = 0;
    function upAndDown(fInp,fCdPre) {
      var fChgd = (fInp != f); // f changed
      if (fChgd) { // ----- put freq out if changed
        f = fInp; fChngedT = getTime();
        analogWrite(outPin,duty,{freq:f});
        analogWrite(audioPin,duty,{freq:f/audioD­iv});
      }
      var btnVals = digitalRead(btnPins), nextF = f, hopI, val;
      // if (lon) log(++cnt, btnVals, ctrlMode);
      if (btnVals && ( ! debounced)) { debounced = true;
        setTimeout(upAndDown,debounceI,fInp,fChg­d); // ...w/ same f
      } else {
        debounced = false;
        if (btnVals === 3) { // --- ctrlMode change
          ctrlMode = (ctrlMode === 0) ? 1 : 0;
          if (lon) log("New ctrlMode =",ctrlMode);
          setTimeout(upAndDown,ctrlModeI,fInp,fals­e); // ...w/ same f
        } else {
          if (ctrlMode === 0) { // --- calc next freq on button presses
            slideVal = -1.0; // forces slide value on ctrlMode change
            if        (btnVals === 1) { // --- up
              nextF = (f<fMax) ? f*tFact : fMax;
            } else if (btnVals === 2) { // --- down
              nextF = (f>fMin) ? f/tFact : fMin;
            } hopI = Math.floor((1+analogRead(slidePin)*btnHo­pMul)*btnHopInt);
          } else { // --- calc next freq from slider pos / voltage divider
            val = (slideAdjM + analogRead(slidePin)) * slideAdjR;
            if (Math.abs(val - slideVal) > slideSens) {
              slideVal = val;
              nextF = Math.floor(fMin + (fMax - fMin) * slideVal);
              nextF = (nextF<fMin) ? fMin : (nextF>fMax) ? fMax : nextF;
            } hopI = slideHopI;
          }
          val = analogRead(sigPin);
          if (lon) {
            if (    digitalRead(sRBtnPin)
                 || (fChgd || fCdPre)
                 || (    (Math.abs(s - val) > s*sChngSens)
                      && (f !== fMin) && (f !== fMax) ) ) {
              s = val;
              smV = val * sCalib;
              log(++cnt,"f =",Math.round(f),Math.floor(smV));
          } }
          if (go) setTimeout(upAndDown,hopI,nextF,false);
        }
      }
    }
    
    function h() { go = false; } // halt
    
    function onInit() {
      go = true;
      tFact = eTFact;
      ctrlMode = 0;
      fUp=true;
      upAndDown(fMin);
    }
    
    setTimeout(onInit,500); // while dev'ing
    `
    
About

Avatar for allObjects @allObjects started