GPIO 输出反相
GPIO output is inverted
我只是在做一个基本测试,通过 8080 端口控制 LED 一切正常,但是当 LED 应该关闭时它会打开,而当它应该关闭时它会关闭
<body>
<h1 id="title">Control LED light</h1>
<p style="text-align: center; font-size: 25px;"></p>
<br>
<p id="date"><i></i><p>
<p id="log">ON/OFF</p>
<p id="log"><input type="checkbox" id="light"></p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script> <!-- include socket.io client side script -->
<script>
var socket = io(); //load socket.io-client and connect to the host that serves the page
window.addEventListener("load", function(){ //when page loads
var lightbox = document.getElementById("light");
lightbox.addEventListener("change", function() { //add event listener for when checkbox changes
socket.emit("light", Number(this.checked)); //send button status to server (as 1 or 0)
});
});
socket.on('light', function (data) { //get button status from client
document.getElementById("light").checked = ! data; //change checkbox according to push button on Raspberry Pi
socket.emit("light", data); //send push button status to back to server
});
</script>
<div class="footer">
<a id="back" href="http://jjh22.ddns.net/projects/webled.html"><-BACK-</a>
</div>
</body>
基本上可以做的是反转复选框的外观或反转复选框的输出。
我有什么想法可以做到这一点吗?
您可以简单地使用布尔逻辑来做到这一点,方法是 Number(!this.checked)
我只是在做一个基本测试,通过 8080 端口控制 LED 一切正常,但是当 LED 应该关闭时它会打开,而当它应该关闭时它会关闭
<body>
<h1 id="title">Control LED light</h1>
<p style="text-align: center; font-size: 25px;"></p>
<br>
<p id="date"><i></i><p>
<p id="log">ON/OFF</p>
<p id="log"><input type="checkbox" id="light"></p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script> <!-- include socket.io client side script -->
<script>
var socket = io(); //load socket.io-client and connect to the host that serves the page
window.addEventListener("load", function(){ //when page loads
var lightbox = document.getElementById("light");
lightbox.addEventListener("change", function() { //add event listener for when checkbox changes
socket.emit("light", Number(this.checked)); //send button status to server (as 1 or 0)
});
});
socket.on('light', function (data) { //get button status from client
document.getElementById("light").checked = ! data; //change checkbox according to push button on Raspberry Pi
socket.emit("light", data); //send push button status to back to server
});
</script>
<div class="footer">
<a id="back" href="http://jjh22.ddns.net/projects/webled.html"><-BACK-</a>
</div>
</body>
基本上可以做的是反转复选框的外观或反转复选框的输出。 我有什么想法可以做到这一点吗?
您可以简单地使用布尔逻辑来做到这一点,方法是 Number(!this.checked)