Explain the code in BOLT.js file in sd card!

function analogWrite(pin,val) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && debug == 1) { alert(xmlhttp.responseText); } }; xmlhttp.open("GET","/analogWrite?pin="+pin+"&value="+val,true); xmlhttp.send();

Someone please explain the code, what is really happening?

More importantly where is the basic code which describes the pins of microcntroller and all the functions like we used to do in EMBEDDED C for arduino
Please Please Help

Hey , let me clear your doubt, you are wondering where is the embedded C right .Actually it is hidden . though bolt can be programed by C via arduino IDE it is not advisable to do so if you are a basic user .The firmware on bolt is just like a webserver it is basically serving the html and javascript file from the sdcard.
The javascript file bolt.js defines the functions for controlling bolt’s hardware using http protocol. The main thing of the above code is this
" xmlhttp.open(“GET”,"/analogWrite?pin="+pin+"&value="+val,true);"
Bolt uses this to send receive data from the html or javascript file inorder to control the hardware.

Try this url in your web browser.


You will find that pin 0 turns high . Similar kind of thing happens in the above code

1 Like