-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f23f996
commit 696b15e
Showing
1 changed file
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
// See https://youtu.be/saIGmyrM_Wc for details, starting around 6:00. | ||
// We create an R-2R ladder using data bits A7, A6, A4, B3, B2, C3 and GND. | ||
|
||
let eventLoop = require("event_loop"); | ||
let gpio = require("gpio"); | ||
let pins = ["PA7", "PA6", "PA4", "PB3", "PB2", "PC3"]; | ||
for (let i=0; i<pins.length;i++) { | ||
gpio.init(pins[i], "outputPushPull", "none"); | ||
|
||
let pins = [gpio.get("PA7"), gpio.get("PA6"), gpio.get("PA4"), gpio.get("PB3"), gpio.get("PB2"), gpio.get("PC3")]; | ||
for (let i = 0; i < pins.length; i++) { | ||
pins[i].init({ direction: "out", outMode: "push_pull" }); | ||
} | ||
|
||
function reset() { | ||
for (let i=0; i<pins.length;i++) { | ||
gpio.write(pins[i], false); | ||
for (let i = 0; i < pins.length; i++) { | ||
pins[i].write(false); | ||
} | ||
} | ||
|
||
let delay_ms = 2000; | ||
while (true) { | ||
// 0b100000 / 0b111111 * 3.3 = 1.65 volts | ||
print("1.65 volts"); | ||
reset(); | ||
gpio.write(pins[5], true); | ||
delay(delay_ms); | ||
// 0b100000 / 0b111111 * 3.3 = 1.65 volts | ||
print("1.65 volts"); | ||
reset(); | ||
pins[5].write(true); | ||
delay(delay_ms); | ||
|
||
// 0b101010 / 0b111111 * 3.3 = 2.2 volts | ||
print("2.2 volts"); | ||
reset(); | ||
gpio.write(pins[5], true); | ||
gpio.write(pins[3], true); | ||
gpio.write(pins[1], true); | ||
delay(delay_ms); | ||
// 0b101010 / 0b111111 * 3.3 = 2.2 volts | ||
print("2.2 volts"); | ||
reset(); | ||
pins[5].write(true); | ||
pins[3].write(true); | ||
pins[1].write(true); | ||
delay(delay_ms); | ||
|
||
// 0b010011 / 0b111111 * 3.3 = 1.0 volts | ||
print("1.0 volts"); | ||
reset(); | ||
gpio.write(pins[4], true); | ||
gpio.write(pins[1], true); | ||
gpio.write(pins[0], true); | ||
delay(delay_ms); | ||
// 0b010011 / 0b111111 * 3.3 = 1.0 volts | ||
print("1.0 volts"); | ||
reset(); | ||
pins[4].write(true); | ||
pins[1].write(true); | ||
pins[0].write(true); | ||
delay(delay_ms); | ||
} |