-
Notifications
You must be signed in to change notification settings - Fork 0
/
semaforo.html
121 lines (98 loc) · 3.49 KB
/
semaforo.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
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous" >
</head>
<body>
<div id="div1">
<p style="font-size:160%; color: white" id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script type="text/javascript">
var iFrequency = 1000; // expressed in miliseconds
var myInterval = 0;
var greenInterval = 0;
var yellowInterval = 0;
var redInterval = 0;
var neutralInterval = 0;
var child = document.getElementById("p1");
// STARTS and Resets the loop if any
function startLoop() {
if(myInterval > 0) clearInterval(myInterval); // stop
myInterval = setInterval( "doSomething()", iFrequency ); // run
}
function doSomething()
{
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDay() + "/"+currentdate.getMonth()
+ "/" + currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":" + currentdate.getSeconds() + ":" + currentdate.getMilliseconds();
//var para = document.createElement("p");
//var node = document.createTextNode("This is new."+ datetime);
//para.appendChild(node);
var element = document.getElementById("div1");
var child = document.getElementById("p1").innerHTML = "" + datetime;
var child
//var element = document.getElementById("div1");
//var child = document.getElementById("p1");
//element.insertBefore(para, child);
}
function runSemaforo()
{
if(myInterval > 0) clearInterval(myInterval); // stop
myInterval = setInterval( "avviaSemaforo()", 4000 );
}
function avviaSemaforo()
{
//neutralInterval = setInterval("neutral()", 0);
greenInterval = setInterval( "verde()", 500 ); // run
//yellowInterval = setInterval( "giallo()", 250 );
//redInterval = setInterval( "rosso()", 1250 );
}
/*
function neutral()
{
*/
function verde()
{
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDay() + "/"+currentdate.getMonth()
+ "/" + currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":" + currentdate.getSeconds() + ":" + currentdate.getMilliseconds();
child.innerHTML = "verde " + datetime;
child.style.background = "green";
setTimeout("giallo()", 7000);
}
function giallo()
{
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDay() + "/"+currentdate.getMonth()
+ "/" + currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":" + currentdate.getSeconds() + ":" + currentdate.getMilliseconds();
child.innerHTML = "giallo " + datetime;
child.style.background = "yellow";
setTimeout("rosso()", 2000);
}
function rosso()
{
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDay() + "/"+currentdate.getMonth()
+ "/" + currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":" + currentdate.getSeconds() + ":" + currentdate.getMilliseconds();
//child.innerHTML = "rosso " + datetime;
child.style.background = "red";
setTimeout("verde()", 3500);
}
</script>
<input type="button" onclick="verde(); return false;"
value="Avvia semaforo" />
<p>...After the script.</p>
</body>
</html>