### Basic Resistor Example Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html A simple circuit demonstrating a basic resistor. ```CircuitJS $+1+0.000005+10.20027730826997+58+5+50%0A213+464+288+528+288+0+2+-\(a-b\)/1000%0Aw+464+288+464+240+0%0Aw+464+240+560+240+0%0Aw+560+240+560+288+0%0Aw+464+320+464+368+0%0Aw+464+368+560+368+0%0Aw+560+368+560+320+1%0Ag+464+368+464+400+0%0AR+464+240+464+176+0+0+40+5+0+0+0.5%0A ``` -------------------------------- ### Current Adder Example Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html A circuit demonstrating the addition of multiple current sources. ```CircuitJS $+1+0.000005+10.20027730826997+50+5+50%0A214+304+192+336+192+0+2+i%0A214+304+288+352+288+0+2+i%0A213+464+240+480+240+0+2+a%5Cpb%0Aw+400+192+464+192+0%0Aw+464+192+464+240+0%0Aw+400+288+464+288+0%0Aw+464+288+464+272+0%0Ag+400+224+400+256+0%0Ag+400+320+400+352+0%0Aw+560+240+560+208+0%0Aw+560+208+624+208+1%0Ar+624+208+624+304+0+1000%0Aw+560+272+560+304+0%0Aw+560+304+624+304+0%0Ag+624+304+624+320+0%0Ai+224+192+304+192+0+0.015%0Aw+224+192+224+224+0%0Aw+224+224+304+224+0%0Aw+224+288+224+320+0%0Aw+224+320+304+320+0%0Ai+224+288+304+288+0+0.005%0A ``` -------------------------------- ### Voltage Ramp Example Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html A circuit demonstrating a voltage ramp using the pwl function. ```CircuitJS $+1+0.000005+10.20027730826997+50+5+50%0A212+448+224+480+224+0+0+pwl\(t,0,0,.1,5\)%0Ag+544+256+544+288+0%0Ar+544+224+624+224+0+1000%0Ag+624+224+624+256+0%0Ao+2+64+0+4098+5+0.003125+0+2+2+3%0A ``` -------------------------------- ### Varying Resistor Example Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html Demonstrates a resistor whose value can vary based on input parameters. ```CircuitJS $+1+0.000005+10.20027730826997+58+5+50%0A213+464+288+528+288+0+3+-\(a-c\)/\(1000*\(1%5Cpb\)\)%0Aw+464+288+464+240+0%0Aw+464+240+560+240+0%0Aw+560+240+560+288+0%0Aw+464+384+560+384+0%0Aw+560+384+560+320+1%0Ag+464+384+464+416+0%0AR+464+240+464+176+0+0+40+5+0+0+0.5%0Aw+464+352+464+384+0%0AR+464+320+400+320+0+2+40+2+3+0+0.5%0A ``` -------------------------------- ### JavaScript for Circuit File Loading and Display Source: https://github.com/sharpie7/circuitjs1/blob/master/war/blink-test.html This script handles loading a list of circuit files from a text file, setting up XMLHttpRequest for synchronous requests, and dynamically updating iframe sources to display different circuit simulations. It also includes functions for navigating between loaded circuits. ```javascript var lines; var request = new XMLHttpRequest(); var files = []; var ptr = 0; function setScr(msg, fname) { document.getElementsByName("local")[0].src = "http://127.0.0.1:8888/circuitjs.html?startCircuit="+fname; document.getElementsByName("remote")[0].src = "https://lushprojects.com/circuitjs/circuitjs.html?startCircuit="+fname; document.getElementsByName("fname")[0].innerHTML= msg+" "+fname; } function next() { if (ptr // Load the circuit from the URL (like the # in the Java version) .../circuitjs.html?ctz= // Load the circuit from compressed data in the URL .../circuitjs.html?startCircuit= // Loads the circuit named "filename" from the "Circuits" directory .../circuitjs.html?startCircuitLink= // Loads the circuit from the specified URL. CURRENTLY THE URL MUST BE A DROPBOX SHARED FILE OR ANOTHER URL THAT SUPPORTS CORS ACCESS FROM THE CLIENT .../circuitjs.html?euroResistors=true // Set to true to force "Euro" style resistors. If not specified the resistor style will be based on the user's browser's language preferences .../circuitjs.html?usResistors=true // Set to true to force "US" style resistors. If not specified the resistor style will be based on the user's browser's language preferences .../circuitjs.html?whiteBackground= .../circuitjs.html?conventionalCurrent= .../circuitjs.html?running= // Start the app without the simulation running, default true .../circuitjs.html?hideSidebar= // Hide the sidebar, default false .../circuitjs.html?hideMenu= // Hide the menu, default false .../circuitjs.html?editable= // Allow circuit editing, default true .../circuitjs.html?positiveColor=%2300ff00 // change positive voltage color (rrggbb) .../circuitjs.html?negativeColor=%23ff0000 // change negative voltage color .../circuitjs.html?hideInfoBox= ``` -------------------------------- ### Display Node.js, Chromium, and Electron Versions Source: https://github.com/sharpie7/circuitjs1/blob/master/app/index.html Outputs the versions of Node.js, Chromium, and Electron. This is useful for debugging and understanding the runtime environment. ```javascript document.write(process.versions.node), Chromium document.write(process.versions.chrome), and Electron document.write(process.versions.electron). // You can also require other files to run in this process const electron = require('electron') require('./renderer.js') ``` -------------------------------- ### Display Circuit Simulator Version Source: https://github.com/sharpie7/circuitjs1/blob/master/war/about.html This snippet retrieves the simulator version from session storage and displays it on the page. It handles cases where the version might not be available. ```javascript // Add version from versionString variable let versionString = document.querySelector('.ver'); let verStr = sessionStorage.getItem('versionString'); if (verStr == null) { versionString.textContent = "... "; } else { versionString.textContent = verStr; } ``` -------------------------------- ### Diode/LED Model Calculation Source: https://github.com/sharpie7/circuitjs1/blob/master/war/diodecalc.html Calculates diode/LED parameters (emission coefficient) and generates a CircuitJS simulation link. Requires input values for forward voltage, current, and reverse saturation current. ```javascript function calc() { var fwd = document.getElementById("forward").value.trim(); var cur = document.getElementById("current").value.trim(); var rev = document.getElementById("reverse").value.trim(); var modelname = document.getElementById("modelname").value.trim(); modelname = modelname.replace(" ", ""); var vt = 0.025865; fwd = convertValue(fwd); cur = convertValue(cur); rev = convertValue(rev); var ecoef = (fwd/Math.log(cur/rev+1)) / vt; document.getElementById("values").innerHTML = "Emission coefficient: " + ecoef; document.getElementById("link").innerHTML = "link to example circuit"; } ``` -------------------------------- ### JavaScript Units Conversion and Beta Calculation Source: https://github.com/sharpie7/circuitjs1/blob/master/war/mosfet-beta.html This function handles unit conversions for input values (like 'm' for milli) and calculates the beta value for a MOSFET. It uses the provided Rds(on), VGS, and VT values. Ensure input values are correctly formatted. ```javascript function units(x) { x = x.trim(); if (x.match(/m$/)) { x = x.replace(/m$/, ""); return .001 * x; } // don't think we need this but you never know if (x.match(/u$/)) { x = x.replace(/u$/, ""); return 1e-6 * x; } return x; } function calc() { var rds = units(document.getElementById('rds').value); var vgs = units(document.getElementById('vgs').value); var vt = units(document.getElementById('vt').value); var beta = Math.abs(1/(rds*(vgs-vt))); document.getElementById('result').innerHTML = "beta = " + beta; } ``` -------------------------------- ### 3-Input NAND with Enable Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html A 3-input NAND gate with an enable input. The output is high-impedance when the enable is low. ```CircuitJS Logic Definition Inputs: A,B,C,En Outputs: X Definition: 1111=0 ???1=1 ???0=_ ``` -------------------------------- ### Crystal Parameter Calculation Source: https://github.com/sharpie7/circuitjs1/blob/master/war/crystal.html Calculates series and parallel resonant frequencies and Q factor for a crystal based on user-defined component values (Cp, Cs, L, R). It also generates a link to a CircuitJS simulation with these parameters. ```javascript function units(x) { x = x.trim(); if (x.match(/m$/)) { x = x.replace(/m$/, ""); return .001 * x; } if (x.match(/u$/)) { x = x.replace(/u$/, ""); return 1e-6 * x; } if (x.match(/n$/)) { x = x.replace(/n$/, ""); return 1e-9 * x; } if (x.match(/p$/)) { x = x.replace(/p$/, ""); return 1e-12 * x; } return x; } function calc() { var cp = units(document.getElementById('cp').value); var cs = units(document.getElementById('cs').value); var L = units(document.getElementById('L').value); var r = units(document.getElementById('r').value); var fs = 1/(2*Math.PI*Math.sqrt(L*cs)); //if (cl > 0) // fs = Math.sqrt((cs+cp+cl)/(L*(cs*cp+cs*cl)))/(Math.PI*2); var fp = 1/(2*Math.PI*Math.sqrt(L*(cp*cs)/(cp+cs))); document.getElementById('result').innerHTML = "Series resonant frequency = " + Math.round(fs) + " Hz
Parallel resonant frequency = " + Math.round(fp) + " Hz
Q = " + Math.round(2*Math.PI*fp*L/r) + "
crystal with these parameters"; } calc(); ``` -------------------------------- ### Multiplier Circuit Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html A circuit demonstrating a multiplier function. ```CircuitJS $+1+0.000005+10.20027730826997+50+5+50%0A212+496+272+544+272+0+2+a*b%0AR+496+272+448+272+0+1+40+5+0+0+0.5%0Aw+496+304+496+336+0%0AR+496+336+448+336+0+1+88+5+0+0+0.5%0Ag+592+304+592+320+0%0AO+592+272+672+272+0%0Ao+1+64+0+12291+24.99332860963738+0.0001+0+5+1+3+3+0+3+3+5+0%0A ``` -------------------------------- ### Op-Amp With Rails Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html An operational amplifier circuit including power rails for limiting output. ```CircuitJS $+1+0.000005+10.20027730826997+57+5+50%0Av+96+336+96+176+0+1+40+5+0+0+0.5%0Ag+96+336+96+384+0%0Aw+160+208+160+336+0%0Aw+352+176+352+336+0%0Ar+160+336+352+336+0+2000%0Ar+96+336+160+336+0+1000%0AO+352+176+464+176+0%0A212+224+176+320+176+0+4+clamp\(\(a-b\)*1000,d,c\)%0Aw+320+176+352+176+0%0Aw+160+208+224+208+0%0Aw+96+176+224+176+0%0Ag+320+208+320+224+0%0AR+224+240+192+240+0+0+40+10+0+0+0.5%0AR+224+272+192+272+0+0+40+-10+0+0+0.5%0Ao+0+64+0+4098+10+0.00009765625+0+2+0+3%0Ao+6+64+0+4098+20+0.00009765625+1+1%0A ``` -------------------------------- ### 3-Input NAND Gate Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Defines a 3-input NAND gate. The output is 0 only when all inputs are 1; otherwise, it's 1. ```CircuitJS Logic Definition Inputs: A,B,C Outputs: X Definition: 111=0 ???=1 ``` -------------------------------- ### Full Adder Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Implements a full adder circuit with inputs A, B, and carry-in C, producing sum S and carry-out C. ```CircuitJS Logic Definition Inputs: A,B,C Outputs: S,C Definition: 111=11 110=10 011=10 101=10 100=01 010=01 001=01 000=00 ``` -------------------------------- ### Op-Amp Circuit Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html An operational amplifier circuit configuration. ```CircuitJS $+1+0.000005+10.20027730826997+57+5+50%0Av+96+256+96+112+0+1+40+5+0+0+0.5%0Ag+96+256+96+304+0%0Aw+192+208+192+256+0%0Aw+336+176+336+256+0%0Ar+192+256+336+256+0+2000%0Ar+96+256+192+256+0+1000%0Aw+96+112+192+112+0%0Aw+192+112+192+176+0%0AO+336+176+400+176+0%0A212+192+176+288+176+0+2+\(a-b\)*1000%0Ag+288+208+288+224+0%0Aw+288+176+336+176+0%0Ao+0+64+0+4098+10+0.00009765625+0+2+0+3%0Ao+8+64+0+4098+20+0.00009765625+1+1%0A ``` -------------------------------- ### Tri-state Buffer Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Implements a tri-state buffer. The output follows the input when enabled, otherwise it is high-impedance. ```CircuitJS Logic Definition Inputs: A,En Outputs: X Definition: A1=A ?0=_ ``` -------------------------------- ### Digital Comparator Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Implements a digital comparator for two 3-bit numbers (A and B), outputting Eq (equal), A> (A greater than B), and A< (A less than B). ```CircuitJS Logic Definition Inputs: A2,A1,A0,B2,B1,B0 Outputs: Eq,A>,A< Definition: ABC ABC=100 1?? 0??=010 A1? A0?=010 AB1 AB0=010 ??? ???=001 ``` -------------------------------- ### Full Rectifier Circuit Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customfunction.html A circuit implementing a full rectifier using the abs() function. ```CircuitJS $+1+0.000005+16.817414165184545+50+5+50%0A212+496+272+544+272+0+1+abs\(a\)%0AR+496+272+448+272+0+1+40+5+0+0+0.5%0Ag+592+304+592+320+0%0AO+592+272+672+272+0%0Ao+1+64+0+12291+5.000000000000001+0.0001+0+3+1+3+3+0%0A ``` -------------------------------- ### Convert Value with Suffix Source: https://github.com/sharpie7/circuitjs1/blob/master/war/diodecalc.html Converts a string value with a unit suffix (p, n, u, m, k, M, G) to its numerical equivalent. Handles various unit prefixes for scientific notation. ```javascript function convertValue(s) { s = s.trim(); var len = s.length; var uc = s.charAt(len-1); var mult = 1; switch (uc) { case 'p': case 'P': mult = 1e-12; break; case 'n': case 'N': mult = 1e-9; break; case 'u': case 'U': mult = 1e-6; break; case 'm': mult = 1e-3; break; case 'k': case 'K': mult = 1e3; break; case 'M': mult = 1e6; break; case 'G': case 'g': mult = 1e9; break; } if (mult != 1) s = s.substring(0, len-1).trim(); return s * mult; } ``` -------------------------------- ### D Flip Flop Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Implements a D flip-flop with input D and clock Clk, producing outputs Q and /Q. Captures D on rising clock edge. ```CircuitJS Logic Definition Inputs: D,Clk Outputs: Q,/Q Definition: ?? 00=10 0+ ??=01 1+ ??=10 ?? AB=AB ``` -------------------------------- ### 3-Bit Counter Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Defines a 3-bit counter that increments on a positive clock transition. Handles various count sequences. ```CircuitJS Logic Definition Inputs: Clk Outputs: A,B,C Definition: + AB0=AB1 + A01=A10 + 011=100 + 111=000 ? ABC=ABC ``` -------------------------------- ### SR Latch Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Defines an SR latch with inputs S and R, and outputs Q and /Q. Handles reset and set conditions, and maintains state. ```CircuitJS Logic Definition Inputs: S,R Outputs: Q,/Q Definition: ?? 00=10 10 ??=10 01 ??=01 ?? AB=AB ``` -------------------------------- ### JK Flip Flop Logic Source: https://github.com/sharpie7/circuitjs1/blob/master/war/customlogic.html Defines a JK flip-flop with inputs J, K, and clock Clk, producing outputs Q and /Q. Implements JK logic on negative clock transitions. ```CircuitJS Logic Definition Inputs: J,K,Clk Outputs: Q,/Q Definition: ??? 00=10 00- AB=AB 10- ??=10 01- ??=01 11- AB=BA ??? AB=AB ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.