forked from jorydotcom/matrix-emoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
164 lines (137 loc) · 5.03 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!--Just type your own thingspeak api key in the script below and you should be good to go-->
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset=utf-8>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.22.2/es6-shim.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<script type="text/javascript" src="/js/iotmatrix.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/css/iotmatrix.css" media="screen"/>
<title>Panneau de contrôle des LEDs</title>
</head>
<body>
<h1 class="titre"><span class="wrapper"><span class="letters">Panneau de
contrôle des LEDs</span></span></h1>
<script src="/js/iotmatrix.js"></script>
<div class="instructionblock">
<span class="instructions">Maintenez
la touche </span> <img alt="Touche Shift" src="images/shift.svg"/> <span class="instructions">pour colorer plusieurs cases à la suite.</span>
</div>
<div class="master">
<div id="container" class="matrice" style="text-align: center;"></div>
<div class="actions"><button class="command" id="save"> Envoyer
la matrice au panneau led dans ma chambre </button><button class="reset"
id="new"> Effacer </button></div>
<ul id="sent" style="text-align: center;">
</ul>
<div style="text-align: center;">
<footer><a href="https://github.com/jorydotcom/matrix-emoji/">Fork de </a><a
href="https://github.com/jorydotcom/matrix-emoji/">ce repo</a><a href="https://github.com/jorydotcom/matrix-emoji/"><img
src="/images/GitHub-Mark-32px.png" alt="githublogo" title="git"></a></footer>
</div>
</div>
<div style="text-align: center;">
<script>
var memory = new Array(64);
var buttons = [];
var dims = [8, 8];
var button = document.createElement("button");
var container = document.getElementById("container");
var character = document.getElementById("character");
var output = document.getElementById("output");
var sent = document.getElementById("sent");
button.classList.add("led");
for (var i = 0; i < dims[0]; i++) {
for (var j = 0; j < dims[0]; j++) {
buttons.push(container.appendChild(button.cloneNode()));
}
}
function newMatrix() {
rows = [
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000"
];
Array.from(rows.reduce(function(accum, row) {
return accum.concat(row);
}, ""), Number).forEach(function(led, index) {
buttons[index].classList.remove("active");
if (led) {
buttons[index].classList.add("active");
}
});
;
output.value=null;
}
function asBinaryArray() {
var result = [];
var all = buttons.map(function(button) {
return +button.classList.contains("active");
});
for (var i = 0; i < 8; i++) {
result.push(all.slice(i * 8, i * 8 + 8).join(""));
}
return result;
}
function padLeft(nr, n, str){
return Array(n - String(nr).length + 1).join(str || "0") + nr;
}
function bin2hex(bin) {
return parseInt(bin, 2).toString(16);
}
function formatTS() {
JSON.stringify(asBinaryArray());
console.log( asBinaryArray().map(function(v) { return parseInt(v, 2); }) );
asBinaryArray().map(function(v) {
return "0x" + padLeft(bin2hex(v), 2);
}).join(", ");
}
container.addEventListener("click", function(event) {
if (event.target.nodeName === "DIV") {
return;
}
event.target.classList.toggle("active");
formatTS();
}, false);
var dragging = false;
container.addEventListener("mouseover", function(event) {
if (event.target.nodeName === "DIV" || event.shiftKey == false) {
return;
}
if(dragging) {
event.target.classList.add("active");
}
});
container.addEventListener("mousedown", function(event) {
if (event.target.nodeName === "DIV" || event.shiftKey == false) {
return;
}
dragging = true;
event.target.classList.add("active");
});
container.addEventListener("mouseup", function(event) {
if(dragging) {
dragging = false;
formatTS();
}
});
$("button.command").click(function(){
$.post('https://api.thingspeak.com/update.json', {api_key: "YOUR_WRITE_API_KEY",field1: asBinaryArray().map(function(v) {
return "0x" + padLeft(bin2hex(v), 2);
}).join(",")})
.done(function(){
alert("Matrice envoyée !");})
.fail(function() {
alert( "error" );})});
$("button.reset").click(function(){ newMatrix();});
</script></div>
</body>
</html>