Monday, 05 May 2014 17:37
Changing the Screen Resolution for Raspberry Pi

View the current display configuration
tvservice -s |
View the /boot/config.txt settings
vcgencmd get_config int |
Get the list of what is supported by your monitor:
tvservice -d dataFile #dump information to dataFile edidparser dataFile #load dataFile & display on screen |
Published in
Tutorials
Tagged under
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); }
.
Sunday, 22 December 2013 11:00
Count number of digits in a number and extract each digit
Count number of digits in a number(integer). Eg. countDigits(5678) return 4
byte countDigits(int num){ byte count=0; while(num){ num=num/10; count++; } return count; }
Extract a digit from an number(integer). Eg. getDigit(5678,2) return 6
int getDigit(unsigned int number, int digit) { for (int i=0; i<digit-1; i++) { number /= 10; } return number % 10; }
Extract all digits from a number and store them to an array
#define MAX_NUMBER_OF_DIGITS 5 byte array_to_hold_digit[MAX_NUMBER_OF_DIGITS]; void setup(void) { Serial.begin(9600); extractDigit_Save2Arrary(5678); Serial.println(array_to_hold_digit[0]); Serial.println(array_to_hold_digit[1]); Serial.println(array_to_hold_digit[2]); Serial.println(array_to_hold_digit[3]); } void loop(void) { } /*---------------------------------------------------------------------------- count number of digits in a number(integer) ----------------------------------------------------------------------------*/ void extractDigit_Save2Arrary(int number){ byte number_of_digit = countDigits(number); for (byte i=0; i<number_of_digit; i++) { array_to_hold_digit[i] = getDigit(number,number_of_digit-i); //store each digit to array } /* for (byte i=0; i<number_of_digit; i++) { Serial.print(array_to_hold_digit[i]); } Serial.println(); */ } /*---------------------------------------------------------------------------- count number of digits in a number(integer) ----------------------------------------------------------------------------*/ byte countDigits(int number){ byte count=0; while(number){ number=number/10; count++; } return count; } /*---------------------------------------------------------------------------- extract a digit from an number(integer) ----------------------------------------------------------------------------*/ byte getDigit(unsigned int number, int digit) { for (int i=0; i<digit-1; i++) { number /= 10; } return number % 10; }
Saturday, 21 December 2013 22:21
Debouncing Multiple Switches

If you want to input a manual switch signal into a digital circuit you'll need to debounce the signal so a single press doesn't appear like multiple presses.
There is a Bounce library for Arduino which is very easy to use. However there is limitations with this Bounce library.
- You are unlikely to enable the internal pull-up resistor on switch pins, therefore each switch require an external pull-up resistor
- It is not possible to detect the switch state before main loop (setup). When you press a switch during power on, you will never get the state of the switch.
Tuesday, 17 December 2013 21:51
Arduino function with optional argument(s)
Function Declaration and Function Prototypes: function prototype allowing the function to be used before it is defined.
functionReturnType myFunctionName(optionalArgumentType optionalArgument = defaultValue); |
Function Implementation
functionReturnType myFunctionName(optionalArgumentType optionalArgument); |
Function calls
myFunctionName(); // Use the default value |
Example
int myFunction(int optionalArgument = 1); void setup() { Serial.begin(9600); } void loop() { Serial.println(myFunction()); // Use the default value Serial.println(myFunction(2)); // Use specific value } int myFunction(int optionalArgument) { return optionalArgument; }