fix(examples): AND Gate Alarm uses latching slide switches (was momentary buttons)

The AND Gate Alarm needed BOTH inputs HIGH at once, but it used momentary
pushbuttons buffered through an Arduino — with one mouse you can only hold one
button at a time, so the AND never fired and the alarm could never be
demonstrated.

Rebuilt it as a board-less digital circuit: two SLIDE switches (they latch) feed
a real AND gate that drives the alarm LED. Slide both switches ON and they stay,
so the alarm arms. No MCU / compilation — it runs on the digital gate engine.
Verified live: the LED lights only on 11 (00/01/10 -> off, 11 -> on).

Snapshot updated: the new board-less and-gate-alarm netlist, plus the digital
bucket count label (38 -> 39) from the earlier ripple-counter example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Montero Crespo 2026-06-05 22:42:15 -03:00
parent b93b1b42c5
commit a5edeb74c7
2 changed files with 115 additions and 78 deletions

View File

@ -1026,18 +1026,16 @@ R_vm_vmR n0 0 10Meg
exports[`netlist snapshot — circuits (40 examples) > and-gate-alarm 1`] = `
"* Velxio circuit
R_btn1 n0 n4 1000000000
R_btn2 n1 n4 1000000000
B_u1 n6 0 V = 5 * u(V(n2)-2.5) * u(V(n3)-2.5)
R_u1_load n6 0 1Meg
R_rl n6 n5 220
V_led1_sense n5 led1_sense_mid DC 0
D_led1 led1_sense_mid n4 LED_RED
R_autopull_n0 n0 0 100Meg
R_autopull_n1 n1 0 100Meg
R_autopull_n2 n2 0 100Meg
R_autopull_n3 n3 0 100Meg
R_autopull_n4 n4 0 100Meg
V_src n1 0 DC 5
R_sw1 n1 n2 1000000000
R_sw2 n1 n3 1000000000
R_rpd1 n2 0 10000
R_rpd2 n3 0 10000
B_u1 n4 0 V = 5 * u(V(n2)-2.5) * u(V(n3)-2.5)
R_u1_load n4 0 1Meg
R_rl n4 n0 220
V_led1_sense n0 led1_sense_mid DC 0
D_led1 led1_sense_mid 0 LED_RED
.model LED_RED D(Is=1e-20 N=1.7)
.op
.end"
@ -1917,7 +1915,7 @@ R_autopull_n2 n2 0 100Meg
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-adder-subtractor-4bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-adder-subtractor-4bit 1`] = `
"* Velxio circuit
V_src n38 0 DC 5
R_asM n38 n16 1000000000
@ -2009,7 +2007,7 @@ D_asLCo asLCo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-alu-slice-1bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-alu-slice-1bit 1`] = `
"* Velxio circuit
V_src n22 0 DC 5
R_aluA n22 n0 1000000000
@ -2064,7 +2062,7 @@ D_aluLCo aluLCo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-and-two-switches 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-and-two-switches 1`] = `
"* Velxio circuit
V_src n3 0 DC 5
R_s1 n3 n1 1000000000
@ -2081,7 +2079,7 @@ D_led led_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-and3-all-on 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-and3-all-on 1`] = `
"* Velxio circuit
V_src n4 0 DC 5
R_s1 n4 n1 1000000000
@ -2100,7 +2098,7 @@ D_led led_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-and4-all-on 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-and4-all-on 1`] = `
"* Velxio circuit
V_src n5 0 DC 5
R_s1 n5 n1 1000000000
@ -2121,7 +2119,7 @@ D_led led_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-aoi-gate 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-aoi-gate 1`] = `
"* Velxio circuit
V_src n8 0 DC 5
R_sA n8 n4 1000000000
@ -2146,7 +2144,7 @@ D_led led_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-bcd-7seg-segment-a 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-bcd-7seg-segment-a 1`] = `
"* Velxio circuit
V_src n10 0 DC 5
R_saB0 n10 n1 1000000000
@ -2175,7 +2173,7 @@ D_saLed saLed_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-bcd-validity 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-bcd-validity 1`] = `
"* Velxio circuit
V_src n9 0 DC 5
R_bcdB0 n9 n2 1000000000
@ -2202,7 +2200,7 @@ D_bcdLed bcdLed_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-binary-to-gray-3bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-binary-to-gray-3bit 1`] = `
"* Velxio circuit
V_src n8 0 DC 5
R_grB0 n8 n0 1000000000
@ -2231,7 +2229,7 @@ D_grLG2 grLG2_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-buffer-three-inverters 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-buffer-three-inverters 1`] = `
"* Velxio circuit
V_src n5 0 DC 5
R_s1 n5 n4 1000000000
@ -2250,7 +2248,7 @@ D_led led_sense_mid 0 LED_YELLOW
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-carry-lookahead-adder-4bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-carry-lookahead-adder-4bit 1`] = `
"* Velxio circuit
V_src n42 0 DC 5
R_claA0 n42 n0 1000000000
@ -2350,7 +2348,7 @@ D_claLCo claLCo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-comparator-4bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-comparator-4bit 1`] = `
"* Velxio circuit
V_src n29 0 DC 5
R_cmpA0 n29 n0 1000000000
@ -2421,7 +2419,7 @@ D_cmpLedLt cmpLedLt_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-comparator-equal-2bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-comparator-equal-2bit 1`] = `
"* Velxio circuit
V_src n6 0 DC 5
R_sA0 n6 n2 1000000000
@ -2446,7 +2444,7 @@ D_led led_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-comparator-magnitude-1bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-comparator-magnitude-1bit 1`] = `
"* Velxio circuit
V_src n10 0 DC 5
R_sA n10 n8 1000000000
@ -2479,7 +2477,7 @@ D_ledLt ledLt_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-compressor-4to2 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-compressor-4to2 1`] = `
"* Velxio circuit
V_src n18 0 DC 5
R_cmpX1 n18 n14 1000000000
@ -2528,7 +2526,7 @@ D_cmLCo cmLCo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-decoder-2to4 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-decoder-2to4 1`] = `
"* Velxio circuit
V_src n12 0 DC 5
R_sA n12 n10 1000000000
@ -2567,7 +2565,7 @@ D_led3 led3_sense_mid 0 LED_BLUE
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-decoder-3to8 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-decoder-3to8 1`] = `
"* Velxio circuit
V_src n22 0 DC 5
R_dec3A0 n22 n0 1000000000
@ -2631,7 +2629,7 @@ D_dec3l7 dec3l7_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-full-adder 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-full-adder 1`] = `
"* Velxio circuit
V_src n8 0 DC 5
R_sA n8 n5 1000000000
@ -2662,7 +2660,7 @@ D_ledCo ledCo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-gray-to-binary-3bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-gray-to-binary-3bit 1`] = `
"* Velxio circuit
V_src n8 0 DC 5
R_gbG0 n8 n0 1000000000
@ -2691,7 +2689,7 @@ D_gbLB2 gbLB2_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-half-adder 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-half-adder 1`] = `
"* Velxio circuit
V_src n6 0 DC 5
R_sA n6 n4 1000000000
@ -2714,7 +2712,7 @@ D_ledC ledC_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-half-adder-nand-only 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-half-adder-nand-only 1`] = `
"* Velxio circuit
V_src n10 0 DC 5
R_hnA n10 n0 1000000000
@ -2745,7 +2743,7 @@ D_hnLC hnLC_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-half-subtractor 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-half-subtractor 1`] = `
"* Velxio circuit
V_src n7 0 DC 5
R_sA n7 n5 1000000000
@ -2770,7 +2768,7 @@ D_ledBo ledBo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-hamming-encoder-74 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-hamming-encoder-74 1`] = `
"* Velxio circuit
V_src n17 0 DC 5
R_hmD0 n17 n0 1000000000
@ -2822,7 +2820,7 @@ D_hmL7 hmL7_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-majority-voter 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-majority-voter 1`] = `
"* Velxio circuit
V_src n8 0 DC 5
R_sA n8 n5 1000000000
@ -2847,7 +2845,7 @@ D_led led_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-multiplier-2x2 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-multiplier-2x2 1`] = `
"* Velxio circuit
V_src n16 0 DC 5
R_sA0 n16 n12 1000000000
@ -2894,7 +2892,7 @@ D_ledP3 ledP3_sense_mid 0 LED_BLUE
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-mux-2to1 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-mux-2to1 1`] = `
"* Velxio circuit
V_src n8 0 DC 5
R_sSel n8 n7 1000000000
@ -2919,7 +2917,7 @@ D_led led_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-mux-4to1 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-mux-4to1 1`] = `
"* Velxio circuit
V_src n18 0 DC 5
R_d0 n18 n4 1000000000
@ -2964,7 +2962,7 @@ D_led led_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-nand-two-switches 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-nand-two-switches 1`] = `
"* Velxio circuit
V_src n3 0 DC 5
R_s1 n3 n1 1000000000
@ -2981,7 +2979,7 @@ D_led led_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-nor-idle-light 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-nor-idle-light 1`] = `
"* Velxio circuit
V_src n3 0 DC 5
R_s1 n3 n1 1000000000
@ -2998,7 +2996,7 @@ D_led led_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-not-inverter 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-not-inverter 1`] = `
"* Velxio circuit
V_src n2 0 DC 5
R_s1 n2 n1 1000000000
@ -3013,7 +3011,7 @@ D_led led_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-or-any-switch 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-or-any-switch 1`] = `
"* Velxio circuit
V_src n3 0 DC 5
R_s1 n3 n1 1000000000
@ -3030,7 +3028,7 @@ D_led led_sense_mid 0 LED_BLUE
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-parity-4bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-parity-4bit 1`] = `
"* Velxio circuit
V_src n5 0 DC 5
R_s0 n5 n1 1000000000
@ -3055,7 +3053,7 @@ D_led led_sense_mid 0 LED_YELLOW
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-popcount-4bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-popcount-4bit 1`] = `
"* Velxio circuit
V_src n18 0 DC 5
R_pcX0 n18 n14 1000000000
@ -3104,7 +3102,7 @@ D_pcLed2 pcLed2_sense_mid 0 LED_GREEN
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-priority-encoder-8to3 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-priority-encoder-8to3 1`] = `
"* Velxio circuit
V_src n22 0 DC 5
R_pe0 n22 n0 1000000000
@ -3163,7 +3161,7 @@ D_lV lV_sense_mid 0 LED_BLUE
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-ripple-adder-4bit 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-ripple-adder-4bit 1`] = `
"* Velxio circuit
V_src n26 0 DC 5
R_sA0 n26 n17 1000000000
@ -3247,7 +3245,43 @@ D_ledCo ledCo_sense_mid 0 LED_RED
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-xnor-equality 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-ripple-counter-4bit 1`] = `
"* Velxio circuit
V_src n12 0 DC 5
R_cnt_clk n12 n0 1000000000
R_cnt_clk_r n0 0 10000
R_cnt_lr0 n1 n8 220
V_cnt_led0_sense n8 cnt_led0_sense_mid DC 0
D_cnt_led0 cnt_led0_sense_mid 0 LED_RED
R_cnt_lr1 n3 n9 220
V_cnt_led1_sense n9 cnt_led1_sense_mid DC 0
D_cnt_led1 cnt_led1_sense_mid 0 LED_GREEN
R_cnt_lr2 n5 n10 220
V_cnt_led2_sense n10 cnt_led2_sense_mid DC 0
D_cnt_led2 cnt_led2_sense_mid 0 LED_BLUE
R_cnt_lr3 n7 n11 220
V_cnt_led3_sense n11 cnt_led3_sense_mid DC 0
D_cnt_led3 cnt_led3_sense_mid 0 LED_YELLOW
R_autopull_n1 n1 0 100Meg
R_autopull_n2 n2 0 100Meg
R_autopull_n3 n3 0 100Meg
R_autopull_n4 n4 0 100Meg
R_autopull_n5 n5 0 100Meg
R_autopull_n6 n6 0 100Meg
R_autopull_n7 n7 0 100Meg
R_autopull_n8 n8 0 100Meg
R_autopull_n9 n9 0 100Meg
R_autopull_n10 n10 0 100Meg
R_autopull_n11 n11 0 100Meg
.model LED_RED D(Is=1e-20 N=1.7)
.model LED_GREEN D(Is=1e-22 N=1.9)
.model LED_BLUE D(Is=1e-28 N=2.0)
.model LED_YELLOW D(Is=1e-21 N=1.8)
.op
.end"
`;
exports[`netlist snapshot — digital (39 examples) > digital-xnor-equality 1`] = `
"* Velxio circuit
V_src n3 0 DC 5
R_s1 n3 n1 0.01
@ -3264,7 +3298,7 @@ D_led led_sense_mid 0 LED_YELLOW
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-xor-difference 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-xor-difference 1`] = `
"* Velxio circuit
V_src n3 0 DC 5
R_s1 n3 n1 1000000000
@ -3281,7 +3315,7 @@ D_led led_sense_mid 0 LED_YELLOW
.end"
`;
exports[`netlist snapshot — digital (38 examples) > digital-xor-from-nands 1`] = `
exports[`netlist snapshot — digital (39 examples) > digital-xor-from-nands 1`] = `
"* Velxio circuit
V_src n7 0 DC 5
R_sA n7 n5 1000000000

View File

@ -859,39 +859,42 @@ void loop() {
{
id: 'and-gate-alarm',
title: 'AND Gate Alarm',
description: 'Buzzer sounds only when BOTH buttons are pressed (AND logic).',
description:
'Two arming switches feed an AND gate — the alarm LED lights ONLY when BOTH ' +
'are ON (e.g. both doors closed). They are slide switches, so they latch: ' +
'slide each one ON and it stays, so you can hold both at once. Pure logic, ' +
'no MCU — runs on the digital gate engine.',
category: 'circuits',
difficulty: 'beginner',
code: `// AND gate alarm — MCU buffers buttons, physical AND gate drives LED
void setup() {
pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP);
pinMode(5, OUTPUT); pinMode(6, OUTPUT);
}
void loop() {
digitalWrite(5, !digitalRead(2)); // HIGH when btn1 pressed
digitalWrite(6, !digitalRead(3)); // HIGH when btn2 pressed
}`,
boardFilter: 'digital',
code: `// Pure digital circuit — no MCU. Slide BOTH switches ON to arm the alarm.
void setup() {}
void loop() {}`,
components: [
UNO,
{ type: 'wokwi-pushbutton', id: 'btn1', x: 260, y: 80, properties: {} },
{ type: 'wokwi-pushbutton', id: 'btn2', x: 260, y: 180, properties: {} },
{ type: 'velxio-logic-gate-and', id: 'u1', x: 400, y: 130, properties: {} },
{ type: 'wokwi-resistor', id: 'rl', x: 520, y: 60, properties: { value: '220' } },
{ type: 'wokwi-led', id: 'led1', x: 520, y: 160, properties: { color: 'red' } },
{ type: 'wokwi-signal-generator', id: 'src', x: 40, y: 200, properties: { waveform: 'dc', offset: 5, amplitude: 0, frequency: 1 } },
{ type: 'wokwi-slide-switch', id: 'sw1', x: 220, y: 90, properties: { value: 0 } },
{ type: 'wokwi-slide-switch', id: 'sw2', x: 220, y: 250, properties: { value: 0 } },
{ type: 'wokwi-resistor', id: 'rpd1', x: 340, y: 140, properties: { value: '10000' } },
{ type: 'wokwi-resistor', id: 'rpd2', x: 340, y: 300, properties: { value: '10000' } },
{ type: 'velxio-logic-gate-and', id: 'u1', x: 470, y: 170, properties: {} },
{ type: 'wokwi-resistor', id: 'rl', x: 620, y: 130, properties: { value: '220' } },
{ type: 'wokwi-led', id: 'led1', x: 620, y: 220, properties: { color: 'red' } },
],
wires: [
// Buttons → MCU inputs (pin 2 / 3)
w('w1', ['arduino-uno', '2'], ['btn1', '1.l']),
w('w2', ['btn1', '2.l'], ['arduino-uno', 'GND'], '#000000'),
w('w3', ['arduino-uno', '3'], ['btn2', '1.l']),
w('w4', ['btn2', '2.l'], ['arduino-uno', 'GND'], '#000000'),
// MCU output pins drive gate inputs
w('w5', ['arduino-uno', '5'], ['u1', 'A']),
w('w6', ['arduino-uno', '6'], ['u1', 'B']),
// Gate Y → Rl → LED → GND
w('w7', ['u1', 'Y'], ['rl', '1']),
w('w8', ['rl', '2'], ['led1', 'A']),
w('w9', ['led1', 'C'], ['arduino-uno', 'GND'], '#000000'),
// Switch 1 → AND input A (slide ON = rail HIGH; pull-down holds it LOW when OFF)
w('w1', ['src', 'SIG'], ['sw1', '1'], '#ff3030'),
w('w2', ['sw1', '2'], ['u1', 'A']),
w('w3', ['sw1', '2'], ['rpd1', '1']),
w('w4', ['rpd1', '2'], ['src', 'GND'], '#000000'),
// Switch 2 → AND input B
w('w5', ['src', 'SIG'], ['sw2', '1'], '#ff3030'),
w('w6', ['sw2', '2'], ['u1', 'B']),
w('w7', ['sw2', '2'], ['rpd2', '1']),
w('w8', ['rpd2', '2'], ['src', 'GND'], '#000000'),
// AND output → series resistor → alarm LED → GND
w('w9', ['u1', 'Y'], ['rl', '1']),
w('w10', ['rl', '2'], ['led1', 'A']),
w('w11', ['led1', 'C'], ['src', 'GND'], '#000000'),
],
},