let lastPushId = "C" const arduionoURL = "http://192.168.1.160" function buttonPushAnimation(id) { if (id !== lastPushId) { document.getElementById(id).style.backgroundColor = "#2c2c36" document.getElementById(lastPushId).style.backgroundColor = "#252531" lastPushId = id httpGetAsync(arduionoURL + "/" + id) } } function httpGetAsync(theUrl, callback) { var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState === 4 && xmlHttp.status === 200) callback(xmlHttp.responseText); } xmlHttp.open("GET", theUrl, true); // true for asynchronous xmlHttp.send(null); }