Sunday, 04 May 2014 11:02
Some useful javascript

Create an XML HTTP Request (XHR) object
function create_XMLHttpRequest() { //create new XHR object if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; }
Send request to Server and receive response from server
- Get replay from php web server: serverResponseInfo=httpGetRequest("http://domain/myReply.php")
- Read content from a text file: serverResponseInfo=httpGetRequest("myTextFile.txt")
- Read content from a text file: document.getElementById("myDiv").innerHTML=loadXMLDoc("myTextFile.txt");
function httpGetRequest(url)
{ xmlhttp= create_XMLHttpRequest(); xmlhttp.open("GET",url,false); xmlhttp.send(); return xmlhttp.responseText; } |
Check if file exist
- To check a file if exist in www root directory: fileExists("/settings.xml")
- To check a file if exist in the current directory: fileExists("settings.xml")
function fileExists(filename) { xmlhttp= create_XMLHttpRequest(); //create new XHR object if(!xmlhttp) return false; try { xmlhttp.open("HEAD", filename, false); xmlhttp.send(null); return (xmlhttp.status==200) ? true : false; } catch(er) { return false; } }
Load an XML file using XML HTTP Request
Eg. loadXML("settings.xml")
function loadXML(XML_filename) { xmlhttp= create_XMLHttpRequest(); xmlhttp.open("GET",XML_filename ,false); xmlhttp.send(); return xmlhttp.responseXML; }
Convert XML to string
function xmlToString(xmlDoc){ if(xmlDoc.xml){ // MSIE xmlString = xmlDoc.xml; }else{ xmlString = (new XMLSerializer).serializeToString(xmlDoc); } return xmlString; }
Create a string based on date
Example of output: 2014_0502
function createString_accordingDate() { var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1;//January is 0! var yyyy = today.getFullYear(); if(dd<10){dd='0'+dd} ; if(mm<10){mm='0'+mm}; return (yyyy + "_" + mm + dd); }
.
Published in
Tutorials
Friday, 17 January 2014 11:34
PicShow component: Image Transition Effects for RAD Studio XE5

TPicShow is an image slider VCL that enables you to create amazing splash screens and 176 transitional effects in pure Delphi code.
Features:
- Image transition can be controlled programmatically
- Image can be stretched or centered in the client area of the control
- Control can show a background image as centered, stretched, or tiled
- Transition process can use a separate thread
- New transitional effects can be easily implemented and added.
TPicShow's last update is on July 19, 2010 which does not support RAD Studio XE. By creating a package file, you can installing and running TPicShow on RAD Studio XE5 without any problem.
Download TPicShow for XE5
Published in
Blog
Friday, 27 September 2013 20:40
Arduino BIT manipulations
Code below set third pin to HIGH without changing the state of any of the other pins
bitSet syntax: bitSet(x, n)
- x: the numeric variable whose bit to set
- n: which bit to set, starting at 0 for the least-significant (rightmost) bit
//initialized all pins to LOW |
Code below set third pin to LOW without changing the state of any of the other pins
bitClear syntax: bitClear(x, n)
- x: the numeric variable whose bit to clear
- n: which bit to clear, starting at 0 for the least-significant (rightmost) bit
//initialized all pins to HIGH //set the third pin LOW |
Code below set each pin as LOW or HIGH without changing the state of any of the other pins
bitWrite Syntax: bitWrite(x, n, b)
- x: the numeric variable to which to write
- n: which bit of the number to write, starting at 0 for the least-significant (rightmost) bit
- b: the value to write to the bit (0 or 1)
byte pinState= 0; //initialized all pins to LOW (B00000000)
bitWrite(pinState, 0, HIGH); //set first pin to HIGH, pinState = B00000001 bitWrite(pinState, 3, HIGH); //set third pin to HIGH, pinState = B00001001 bitWrite(pinState, 0, LOW); //set first pin to LOW, pinState = B00001000
|
Reads a bit of a number.
bitRead Syntax: bitRead(x, n)
-
x: the number from which to read
-
n: which bit to read, starting at 0 for the least-significant (rightmost) bit
byte pinState = B10101010;
for (int i=0; i<8; i++) {
theBit = bitRead(pinState, i);
}
|
Published in
Tutorials
Saturday, 20 July 2013 22:31
DIYLC电子绘图软件

DIYLC (DIY Layout Creato)是电子爱好者用来设计电路图的绘图软件,它可以设计原理电路图(Schematic)、洞洞电板路板(Strip board)、面包电路板等(Breadboard)。
DIYLC是一个免费与开源软件,现在是3.27.0,应该是正式使用版本了。今天试用了这版本,感觉比之前的旧版本好用了许多,很适合初学者,所以决定在此与大家分享一下。
Published in
电子与电脑
Sunday, 14 July 2013 15:20
Arduino communicate with Vixen Lighting Control Software

Vixen is a free and popular light show creator software. With a PC and some hardware, anyone can have a professional-looking lighting display synchronized to music.
The latest version is Vixen3, the most attractive feature is supported for preview. Compare to Vixen2, Vixen3 is a bit difficult to use & lack of some features in Vixen2. Please correct me if I'm wrong.
This tutorial is based on Vixen2, please download Vixen2 and install it to your computer. Prior to Vixen2, you must have install Microsot.NET Framework 2.0 in your computer.
Published in
Blog
Sunday, 10 February 2013 19:03
Develop Android Application without Coding
App Inventor is an application use to develop Android application without programming. Its graphical interface is very similar to Scratch that allow users to drag and drop visual objects to develop application which runs on many mobile devices.
Google released App Inventor on December 15, 2010 and terminated as the Google product on August 2011. App Inventor is maintained by Massachusetts Institute of Technology and the code is become "Open Source".
Published in
Blog
Sunday, 03 February 2013 18:35
Backing Up Raspberry Pi SD card
- Insert SD card to computer
- Launch Win32 Disk Imager
- Select Device (source) which you want to backup from
- Under Image File, give it a file name as shown in figure below

- Click Read button to start backing up
- As shown in figure below, the image file size is equivalent to the size of SD card since I had resized the partition of my SD card

Published in
Tutorials
Monday, 28 January 2013 23:20
Gambas for Raspberry Pi
Gambas is a BASIC interpreter which is very similar to Visual Basic but running on Linux. Gambas from version 3.2 can run on Raspberry Pi and Gambas3 for Raspberry Pi image file is available here.
Installation
- After download the image file (it is zipped), extract it to any location of computer. Now your computer should have an image file named as 2012-07-15-wheezy-gambas3.img
- Write this img file to SD card using Win32DiskImager as describe in this article
- Remove the SD card from computer once writing completed
- Insert the SD card to Raspberry Pi & power on it.
- Remote access to Raspberry using TightVNC as describe in this article
- You should see Gambas icon appear on the desktop screen.
- To start Gambas3, click the first icon at the left bottom screen then select Programming>Gambas3
People find that they are facing 100% CPU usage when using Gambas3, you can use the patch to overcome this problem.
Published in
Blog
Sunday, 27 January 2013 22:19
TinyBASIC for Raspberry Pi
TinyBASIC is a simple BASIC interpreter which allow beginners to easily get into programming
Installing
You need to install libsdl-gfx1.2-4 package before install TinyBASIC.
You need to install libsdl-gfx1.2-4 package before install TinyBASIC.
- SSH to Raspberry Pi and execute command below:
sudo apt-get install libsdl-gfx1.2-4 |
- Download TinyBASIC deb file and save it to any location of computer
- Transfer the downloaded deb file from computer to /tmp folder of Raspberry Pi using WinSCP
- Execute command below to start install TinyBasic
sudo dpkg -i /tmp/tinybasic_2.1-1_armhf.deb |
Published in
Blog
Saturday, 19 January 2013 20:28
Virtualbox Raspberry Pi Emulator
Would like to have Raspberry Pi experience before you own one of the boards? This article show you how to use VirtualBox as a emulator of Raspberry Pi
Download
- Download the zip file and extract the included torrent file to any folder
- Open the torrent file with any torrent client. I'm using flashget to open the torrent file.
- The download should start.
- You will have a 658,763KB ova file upon completion of downloading
Published in
Blog