diff --git a/script.js b/script.js index 2691ce0..0a925a8 100644 --- a/script.js +++ b/script.js @@ -7,6 +7,7 @@ const DEBUG = false; let socketMoteur = undefined; let socketInfos = undefined; let moteur = undefined; +let led = undefined; let position = undefined; @@ -104,6 +105,31 @@ class Moteur { } +class Led { + + http = undefined; + + send(color){ + this.http = new XMLHttpRequest(); + this.http.open('POST', 'http://' + URL + '/led/set_color', true); + this.http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + this.http.send('ledcolor=' + color); + } + + red(){ + this.send("#ff0000") + } + + green(){ + this.send("#00ff00") + } + + blue(){ + this.send("#0000ff") + } + +} + class Position { posX = 0; @@ -144,6 +170,7 @@ class Position { function run() { connectSockets(); moteur = new Moteur(); + led = new Led(); position = new Position(socketInfos); }