功能性:
当用户点击图像按钮时,当前页面(页面A)将导航到辅助页面(页面B)。因此,当显示辅助页面时,连接到Arduino的继电器的7 LED灯将亮起(从LOW切换 - > HIGH> HIGH)。因此,尽管NFC读卡器与arduino分开连接,7 LED将点亮7个NFC读卡器
当用户使用其中一个NFC时,程序将检查用户选择的NFC是否正确,如果正确,链接到特定NFC的LED将从HIGH切换到LOW,LED将是关掉。否则,如果用户选择的NFC错误,LED灯将不会关闭。
LED连接到arduino。当页面A切换到页面B时,javascript正在调用arduino。
因此,流程是这样的:
1。)用户点击“开始”按钮,页面A将导航到页面B. 2.)加载页面B时,7 LED将亮起。
我做了什么:
1。)我创建了arduino脚本,它将调用LED继电器点亮 2.)当用户点击按钮将页面A导航到页面B时,已使用ajax _call调用arduino脚本
代码:
Arduino代码: byte Relay_1 = 0; byte Relay_2 = 1; byte Relay_3 = 2; byte Relay_4 = 3; byte Relay_5 = 4; byte Relay_6 = 5; byte Relay_7 = 6;
int time; // Creates temp
void setup() {
// Initialized the Relay pin as an output
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);
pinMode(Relay_5, OUTPUT);
pinMode(Relay_6, OUTPUT);
pinMode(Relay_7, OUTPUT);
// Initialized the serial communication
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
// read the incoming byte:
int incomingByte = Serial.read();
digitalWrite(Relay_1, HIGH);
digitalWrite(Relay_2, HIGH);
digitalWrite(Relay_3, HIGH);
digitalWrite(Relay_4, HIGH);
digitalWrite(Relay_5, HIGH);
digitalWrite(Relay_6, HIGH);
digitalWrite(Relay_7, HIGH);
}
else{
int incomingByte = Serial.read();
digitalWrite(Relay_1, LOW);
digitalWrite(Relay_2, LOW);
digitalWrite(Relay_3, LOW);
digitalWrite(Relay_4, LOW);
digitalWrite(Relay_5, LOW);
digitalWrite(Relay_6, LOW);
digitalWrite(Relay_7, LOW);
}
/*
while(true)
{
// Check if data has been sent from the computer
if(Serial.available())
{
// Assign serial value to temp
time = Serial.parseInt();
// Output value to relay
digitalWrite(Relay, HIGH);
delay(time);
digitalWrite(Relay, LOW);
}
}
*/
}
当用户点击“开始”按钮以启用所有LED时,HTML调用arduino的部分:
$("#scentIntroductionPage > .Begin").click(function() {
//Ajax call to enable LED light to light up
document.getElementById("scentIntroBeginBtn").style.pointerEvents = 'none';
$("#gamePage").scentGame();
$("#scentIntroductionPage").fadeOut(function() {
$("#gamePage").fadeIn();
// $('#stillModal').modal('show');
})
用户选择NFC时HTML调用arduino的部分,如果正确:LED将切换为LOW,否则LED仍为HIGH:
var _chteUID = "042FC58A5949809000";
var _teeUID = "0435C58A5949809000";
var _okUID = "0429C48A5949809000";
var _spsUID = "04A5C88A5949809000";
var _dritsUID = "0430C58A5949809000";
var _vlaUID = "042FC48A5949809000";
var _cusUID = "0488C68A5949809000";
base.selectScent = function(selectedScent) {
scentIndex++;
$("#aromaHeader").html("You have picked up a vial.");
$("#aromaText").html("Please smell the still and guess which ingredient it is.");
$("." + selectedScent).addClass(scentIndex + "Scent");
$(".Flavours").removeClass("removeClick");
$(".Flavours").unbind().click(function() {
if ($(this).hasClass(scentIndex + "Scent")) {
$("#aromaHeader").html("GOOD JOB!<br><br> MATCH THE REMAINING SCENTS.");
$("#aromaText").html("");
$(".Flavours").addClass("grayScale")
$(this).removeClass("grayScale"); // Stay in coloured
$(this).removeClass("Flavours");
$(this).addClass("removeClick"); // Remove Clickability
$(".Flavours").addClass("removeClick");
previousScentArr.push(selectedScent);
if ($(".Flavours").length == 0) {
// All ingredient has been selected
$("#aromaHeader").html("CONGRATULATIONS<br><br> YOU HAVE MATCHED ALL AROMAS CORRECTLY.");
$("#aromaText").html("");
// Go back to home & Reset
$("#gamePage > .Back").fadeOut();
setTimeout(function() {
$(".navigationList > li").removeClass("navBorder_Bottom");
$("#gamePage").fadeOut(function() {
$("#Menu").css({
top: -121
});
$("#homePage").fadeIn();
})
$("#gamePage").empty();
base.reset();
}, 5500);
} else {
// Set buffer time
// There are still more ingredient to choose
// Ensure that all vials are back into positon
var ensureAllReadyInterval = setInterval(function() {
console.log("base:" + base.checkAllInPosition());
if (base.checkAllInPosition() == "false") {
$("#aromaHeader").html("Please place the vial back into position.");
} else if (base.checkAllInPosition() == "true") {
clearInterval(ensureAllReadyInterval);
setTimeout(function() {
$("#aromaHeader").html("All vials are in position. Please choose a new vial.");
base.detectFirstScent();
}, 1500);
}
}, 500);
}
} else {
$("#aromaHeader").html("THAT'S NOT THE RIGHT MATCH. <br><br> TRY AGAIN.");
$("#aromaText").html("");
}
})
}
base.init();
}
问题:
只有当用户点击按钮时,我才设法让arduino灯从LOW切换到HIGH状态。
但是,我完全坚持完成以下部分:
我需要在我的javascript中实现这一点。
我能帮忙吗?谢谢。
我完全不知道如何实现这些目标。