Html script tag Query

How do you print value of analogRead(“A0”) in html inside the script tag?
It is supposed to return LDR sensor value
we use json.loads() in python
what is its equivalent in html?

Hi @deepanjalipandit660,

If you are using the boltCommands.js and if you look closely for this function

function analogRead(pin,element_id) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

            var obj = JSON.parse(xmlhttp.responseText);
                 document.getElementById(element_id).innerHTML = "Pin Val = "+obj.value;
                    document.getElementById(element_id).innerHTML = "Error = "+xmlhttp.responseText;

The below line is doing the parsing of data.

 var obj = JSON.parse(xmlhttp.responseText);

Do let me know i case you need any other information.

1 Like