diff options
Diffstat (limited to 'test.rb')
| -rwxr-xr-x | test.rb | 47 |
1 files changed, 38 insertions, 9 deletions
| @@ -2,24 +2,53 @@ | |||
| 2 | 2 | ||
| 3 | require "./lace" | 3 | require "./lace" |
| 4 | 4 | ||
| 5 | def r(size, suffix="ohm") | 5 | def r(size) |
| 6 | comp("R", "0805", "resistor", "#{Lace::e12(size)}#{suffix}") | 6 | comp("R", "0805", "resistor", size) |
| 7 | end | 7 | end |
| 8 | 8 | ||
| 9 | def c(size, suffix="nF") | 9 | def c(size) |
| 10 | comp("C", "0805", "capacitor", "#{Lace::e12(size)}#{suffix}") | 10 | comp("C", "0805", "capacitor", size) |
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | def led(color="red") | 13 | def led(color="red") |
| 14 | comp("D", "0805", "LED", "1.5V 10mA #{color}") | 14 | comp("D", "0805", "LED", "1.5V 10mA #{color}") - r("220ohm") |
| 15 | end | ||
| 16 | |||
| 17 | def inverter() | ||
| 18 | $inverters ||= [] | ||
| 19 | if $inverters.empty? | ||
| 20 | u = comp("U", "TSOP-14", "74HCT04", "hex inverter") | ||
| 21 | $vcc - u[14] - c("100nF") - u[7] - $gnd | ||
| 22 | $inverters += [ | ||
| 23 | pair(u[1], u[2]), | ||
| 24 | pair(u[3], u[4]), | ||
| 25 | pair(u[5], u[6]), | ||
| 26 | pair(u[9], u[8]), | ||
| 27 | pair(u[11], u[10]), | ||
| 28 | pair(u[13], u[12]), | ||
| 29 | ] | ||
| 30 | end | ||
| 31 | $inverters.shift | ||
| 32 | end | ||
| 33 | |||
| 34 | def btn(color="black") | ||
| 35 | sw = comp("SW", "BTN", "SPST button", color) | ||
| 36 | sw[1] - sw[4] | ||
| 37 | sw[2] - sw[3] | ||
| 38 | pair(sw[1], sw[4]) | ||
| 15 | end | 39 | end |
| 16 | 40 | ||
| 17 | nl = Lace::Netlist.new do | 41 | nl = Lace::Netlist.new do |
| 18 | vcc = net("vcc") | 42 | $vcc = net("vcc") |
| 19 | gnd = net("gnd") | 43 | $gnd = net("gnd") |
| 44 | |||
| 45 | $vcc - led - $gnd | ||
| 46 | |||
| 47 | $vcc - btn - led("green") - $gnd | ||
| 20 | 48 | ||
| 21 | vcc - r((5 - 1.5)/0.010) - led - gnd | 49 | x = $vcc - btn("white") |
| 22 | vcc - c(100) - gnd | 50 | x - led("amber") - $gnd |
| 51 | x - inverter() - led("blue") - $gnd | ||
| 23 | end | 52 | end |
| 24 | 53 | ||
| 25 | nl.kicad | 54 | nl.kicad |
