Analog-SPST-Switch
By JElenielAn analog Single Pole Single Throw switch with characteristics based on the 405x series ICs
const float ROFF = 100000000000.0;
const float RON_L = 60.0;
const float RON_M = 50.0;
const float RON_H = 15.0;
const float LEAKAGE = 0.000000000001;
const int A=1;
const int VEE=2;
const int GND=3;
const int EN=4;
const int B=5;
const int VCC=6;
bool enabled = false;
void setup() {
chipName("Analog SPST Switch");
logicFamily(CMOS);
pin(A, "A", INPUT);
pin(VEE, "Vee", INPUT);
maxVoltage(VEE,0.5);
pin(GND, "GND", GROUND);
pin(EN, "En", INPUT | LINE_OVER);
maxVoltage(EN,30);
pin(B, "B", INPUT);
pin(VCC, "Vcc", POWER);
maxVoltage(VCC,7);
//capacitance(A, B, LEAKAGE);
resistance(A, B, ROFF, NON_LINEAR);
}
void loop() {
float vcc=analogRead(VCC);
float vee=analogRead(VEE);
float vdelta=vcc-vee;
maxVoltage(1,vcc);
maxVoltage(5,vcc);
bool en = !digitalRead(4);
if (en != enabled) {
if(vdelta<4.5) {
resistance(1, 5, en ? RON_L : ROFF);
} else if(vdelta>=4.5 && vdelta<6) {
resistance(1, 5, en ? RON_M : ROFF);
} else {
resistance(1, 5, en ? RON_H : ROFF);
}
enabled = en;
}
}

