Skip to content

Instantly share code, notes, and snippets.

@Krimsit
Last active November 16, 2017 12:40
Show Gist options
  • Save Krimsit/3bb51a6300ff84f4d03b07e6dbd7bcf9 to your computer and use it in GitHub Desktop.
Save Krimsit/3bb51a6300ff84f4d03b07e6dbd7bcf9 to your computer and use it in GitHub Desktop.
var ir = require("@amperka/ir-receiver").connect(P0);
var led = require("@amperka/led").connect(P2);
var light = require("@amperka/light-sensor").connect(A3);
var temp = require("@amperka/thermometer").connect(A5);
var nrm_t = 24;
var now_t = temp.read("C").toFixed(3);
var nrm_l = 350;
var now_l = light.read("lx");
function update(a, f){
return a = f;
}
var ToggleBlinkLED = function(t, n){
var i = 0;
var inter = setInterval(function(){
led.blink(t - 200);
setTimeout(function(){}, 100);
i++;
if(i == n*2){
clearInterval(inter);
led.turnOff();
}
}, t);
};
console.log(temp.read("C"));
console.log(light.read("lx"));
function getProcentsTemp(a, b){
return Math.round(a / b * 100);
}
function getProcentsLight(a, b){
return Math.round(a / b * 100);
}
ir.on("receive", function(code, repeat){
console.log(code.toString(16));
if(code.toString(16) == "3fcc33f"){
var proc = getProcentsTemp(temp.read("C"), nrm_t);
console.log(getProcentsTemp(temp.read("C"), nrm_t));
if(proc >= 80){
ToggleBlinkLED(400, 3);
}else if(proc >= 55){
ToggleBlinkLED(400, 2);
}else{
ToggleBlinkLED(400, 1);
}
}
if(code.toString(16) == "3fc639f"){
console.log(getProcentsLight(light.read("lx"),nrm_l));
var proc = getProcentsLight(light.read("lx"), nrm_l);
if(proc >= 80){
ToggleBlinkLED(400, 3);
}else if(proc >= 55){
ToggleBlinkLED(400, 2);
}else{
ToggleBlinkLED(400, 1);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment