diff --git a/examples/thermometer-lm335/main.js b/examples/thermometer-lm335/main.js new file mode 100644 index 0000000..2c9d191 --- /dev/null +++ b/examples/thermometer-lm335/main.js @@ -0,0 +1,38 @@ +import LM335 from "j5e/lm335"; +import LED from "j5e/led"; +import { timer } from "j5e/fn"; + +let last = 0; +let myTimer; + +const thermometer = await new LM335({ + pin: 14, + threshold: 4 +}); + +const led = await new LED({ + pin: 12, + pwm: true +}); + +thermometer.on("change", function(data) { + + trace(`${data.F}° Fahrenheit\n`); + if (last > data.raw) { + led.blink(100); + last = data.raw; + } + + if (last < data.raw) { + led.stop().on(); + last = data.raw; + } + + if (typeof myTimer !== "undefined" && myTimer !== null) timer.clearTimeout(myTimer); + + myTimer = timer.setTimeout(function() { + myTimer = null; + led.stop().off(); + }, 1000); + +}); \ No newline at end of file diff --git a/examples/thermometer-lm335/manifest.json b/examples/thermometer-lm335/manifest.json new file mode 100644 index 0000000..09095d8 --- /dev/null +++ b/examples/thermometer-lm335/manifest.json @@ -0,0 +1,10 @@ +{ + "include": [ + "$(MODDABLE)/modules/io/manifest.json", + "$(j5e)/lib/thermometer/lm335/manifest.json", + "$(j5e)/lib/led/manifest.json" + ], + "modules": { + "*": "./main" + } +} \ No newline at end of file diff --git a/examples/thermometer-lm35/main.js b/examples/thermometer-lm35/main.js new file mode 100644 index 0000000..1c1a66a --- /dev/null +++ b/examples/thermometer-lm35/main.js @@ -0,0 +1,38 @@ +import LM35 from "j5e/lm35"; +import LED from "j5e/led"; +import { timer } from "j5e/fn"; + +let last = 0; +let myTimer; + +const thermometer = await new LM35({ + pin: 14, + threshold: 4 +}); + +const led = await new LED({ + pin: 12, + pwm: true +}); + +thermometer.on("change", function(data) { + + trace(`${data.F}° Fahrenheit\n`); + if (last > data.raw) { + led.blink(100); + last = data.raw; + } + + if (last < data.raw) { + led.stop().on(); + last = data.raw; + } + + if (typeof myTimer !== "undefined" && myTimer !== null) timer.clearTimeout(myTimer); + + myTimer = timer.setTimeout(function() { + myTimer = null; + led.stop().off(); + }, 1000); + +}); \ No newline at end of file diff --git a/examples/thermometer-lm35/manifest.json b/examples/thermometer-lm35/manifest.json new file mode 100644 index 0000000..30de8b1 --- /dev/null +++ b/examples/thermometer-lm35/manifest.json @@ -0,0 +1,10 @@ +{ + "include": [ + "$(MODDABLE)/modules/io/manifest.json", + "$(j5e)/lib/thermometer/lm35/manifest.json", + "$(j5e)/lib/led/manifest.json" + ], + "modules": { + "*": "./main" + } +} \ No newline at end of file diff --git a/examples/thermometer-mf52a103j3470/main.js b/examples/thermometer-mf52a103j3470/main.js new file mode 100644 index 0000000..1759c1a --- /dev/null +++ b/examples/thermometer-mf52a103j3470/main.js @@ -0,0 +1,38 @@ +import MF52A103J3470 from "j5e/mf52a103j3470"; +import LED from "j5e/led"; +import { timer } from "j5e/fn"; + +let last = 0; +let myTimer; + +const thermometer = await new MF52A103J3470({ + pin: 14, + threshold: 4 +}); + +const led = await new LED({ + pin: 12, + pwm: true +}); + +thermometer.on("change", function(data) { + + trace(`${data.F}° Fahrenheit\n`); + if (last > data.raw) { + led.blink(100); + last = data.raw; + } + + if (last < data.raw) { + led.stop().on(); + last = data.raw; + } + + if (typeof myTimer !== "undefined" && myTimer !== null) timer.clearTimeout(myTimer); + + myTimer = timer.setTimeout(function() { + myTimer = null; + led.stop().off(); + }, 1000); + +}); \ No newline at end of file diff --git a/examples/thermometer-mf52a103j3470/manifest.json b/examples/thermometer-mf52a103j3470/manifest.json new file mode 100644 index 0000000..85e82a2 --- /dev/null +++ b/examples/thermometer-mf52a103j3470/manifest.json @@ -0,0 +1,10 @@ +{ + "include": [ + "$(MODDABLE)/modules/io/manifest.json", + "$(j5e)/lib/thermometer/mf52a103j3470/manifest.json", + "$(j5e)/lib/led/manifest.json" + ], + "modules": { + "*": "./main" + } +} \ No newline at end of file