-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (45 loc) · 1.31 KB
/
index.js
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
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawGauge);
var gaugeOptions = {min: 0, max: 220, yellowFrom: 180, yellowTo: 200, redFrom: 200, redTo:220, minorTicks: 10};
// var gauge;
function drawGauge() {
gaugeData = new google.visualization.DataTable();
gaugeData.addColumn('number', 'Speed');
gaugeData.addRows(1);
gaugeData.setCell(0, 0, 0);
gauge = new google.visualization.Gauge(document.getElementById('gauge_div'));
gauge.draw(gaugeData, gaugeOptions);
}
function changeSpeed(dir) {
gaugeData.setValue(0, 0, gaugeData.getValue(0, 0) + dir);
gauge.draw(gaugeData, gaugeOptions);
}
function update(){
var x = document.querySelector("#inp").value;
console.log(x);
if(x>=0 && x<=220){
if(x>180 && x<200){
createSound();
}
if(x>=200 && x<220){
createSound();
createSound();
}
var res = x - gaugeData.getValue(0,0);
changeSpeed(res);
return ;
}
else{
alert("Speed cannot be achieved!");
changeSpeed(0-gaugeData.getValue(0,0));
return ;
}
}
function pressed(e){
if(e.keyCode==13)
update();
}
function createSound(){
var snd = new Audio("beep.mp3"); // buffers automatically when created
snd.play();
}