Tuesday, March 19, 2013

SecureIt

Well,

After a day of boredom over long weekend, thought of making an Android app.....

Earlier in 2009, once I thought of a security system based on Camera that catches images, compares it and sends SMS to predefined number if difference is detected.

Applications could be as simple as home security system when you are away...

Well, I made that stuff using ARM 7 processor in late 2009 but it was sort of a costly model considering, ARM, Camera and GSM modem.

So thought of making it for J2ME phones. Managed to make itin late 2011 but it used to work with selected phones only. Thanks to different Camera API.

So last week, spent a day to convert it in Android App. and it worked.....

Only stuff I struggled was in creating infinite loop....

Forgot to use simple thread stuff.... LOL

So, the app is working and available at Google Play :-)


https://play.google.com/store/apps/details?id=ind.zaki.android.tools.secureit


So download it guys and enjoy. Any suggestions/comments/feedback are welcome.

Tuesday, February 26, 2013

Simplest Android App

Here is one of the simplest Android App:

Temperature Converter - It converts Temperature from Degree Celsius to Degree Fahrenheit and vice versa.



Tha App can be found in Market at :


https://play.google.com/store/apps/details?id=ind.zaki.android.temp.converter



Here is the code:


Androidmanifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ind.zaki.android.temp.converter"
    android:versionCode="2"
    android:versionName="2.0"
    android:installLocation="auto"
     >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".DtoFActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>





DToFActivity.java

package ind.zaki.android.temp.converter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class DtoFActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

((Button) findViewById(R.id.calculate))
.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {

final EditText degreesText = (EditText) DtoFActivity.this
.findViewById(R.id.degrees);

final EditText fahrenheitText = (EditText) DtoFActivity.this
.findViewById(R.id.fahrenheit);

if (!"".equals(degreesText.getText().toString())) {
fahrenheitText.setText(String.valueOf((Float
.valueOf(degreesText.getText().toString()) * 9 / 5) + 32));
}
}
});

((Button) findViewById(R.id.calculate2))
.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {

final EditText degreesText = (EditText) DtoFActivity.this
.findViewById(R.id.degrees);

final EditText fahrenheitText = (EditText) DtoFActivity.this
.findViewById(R.id.fahrenheit);

if (!"".equals(fahrenheitText.getText().toString())) {
degreesText.setText(String.valueOf((Float
.valueOf(fahrenheitText.getText()
.toString()) - 32) * 5 / 9));
}
}
});

}
}




main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/degrees" />

    <EditText
        android:id="@+id/degrees"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" >

        <requestFocus />
    </EditText>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/fahrenheit" />

    <EditText
        android:id="@+id/fahrenheit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" />

    <Button
        android:id="@+id/calculate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Degrees to FahrenHeit" />

    <Button
        android:id="@+id/calculate2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="FahrenHeit to Degrees" />

</LinearLayout>


Friday, April 8, 2011

Snake Game


Remember Playing Snake Game on Nokia 3310!!!!

Here is something for you:

Snake game that runs on LEDs. It was fun playing with it...


This is my circuit diagram. It uses 8051 family microcontroller, 16*8 LEDs, 4 switches for up down, left, right operations and a simple LED Driver.



And here is PCB Layout in Express PCB.


And yeah.... dear code. I used C this time considering complexity of the system.



#include<reg51.h>

unsigned char display_data[] = {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
unsigned char const rows[] = {0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};
unsigned char const add[] = {128,64,32,16,8,4,2,1,128};
unsigned int positions[] = {0,16,32,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char length = 3;
unsigned int food,nextFood;

unsigned char direction = 0 ;
unsigned char lastSpeed=10,speed = 10;

void delay(void);
void initialise(void);
void timer1 (void);
void timer0 (void);

bit levelStarted = 0;
bit gameOver = 0;

void main(void){
unsigned char i = 0;
initialise();

while(1){

if(P3 == 0xfd && (direction != 2)){
direction = 0;
levelStarted = 1;
}
if(P3 == 0xfb&& (direction != 3)){
direction = 1;
levelStarted = 1;
}
if(P3 == 0xf7&& (direction != 0)){
direction = 2;
levelStarted = 1;
}
if(P3 == 0xfe&& (direction != 1)){
direction = 3;
levelStarted = 1;
}

for(i=0;i<8;i++){
P0 = rows[i];
P1 = 255 - display_data[i];
P2 = 255 - display_data[i+8];
delay();
}
}
}

void delay(void){
unsigned char i = 0;
unsigned char j = 0;
unsigned char K = 0;
for(i=0;i<2;i++){
for(j=0;j<5;j++){
for(K=0;K<5;K++){
}
}
}
}


void initialise(void){
IE = 0x8a;
TMOD = 0x11;
TH1 = 128;
TH0 = 0;
TR1 = 1;
TR0 = 1;
}


void timer0 (void) interrupt 1{
nextFood ++;
TH0 = nextFood/13;
nextFood = nextFood % 128;
}


void timer1 (void) interrupt 3{
unsigned char row;// = start_position / 16;
unsigned char col;// = start_position % 16;
unsigned char i;// = start_position % 16;
if(--speed == 0){
speed = lastSpeed;

if (levelStarted == 1 ){

if (positions[length-1] == food){
length++;
positions[length-1] = food;
food = nextFood;
}  else {
for(i=1;i<length;i++){
positions[i-1] = positions[i];
}
}


row = positions[length-1]/16;
col = positions[length-1]%16;

if (direction == 0){
if(row == 7){
positions[length-1] = positions[length-2] % 16;
} else {
positions[length-1] = positions[length-2] + 16;
}
}

if (direction == 1){
if(col == 15){
positions[length-1] = positions[length-2] - 15;
} else {
positions[length-1] = positions[length-2] + 1;
}
}

if (direction == 2){
if(row == 0){
positions[length-1] = positions[length-2] + (16*7);
} else {
positions[length-1] = positions[length-2] - 16;
}
}

if (direction == 3){
if(col == 0){
positions[length-1] = positions[length-2] + 15;
} else {
positions[length-1] = positions[length-2] - 1;
}
}
}


if(length == 16){   // level change triggerred
length = 3;
levelStarted = 0;
positions[0] = 0;
positions[1] = 16;
positions[2] = 32;
lastSpeed--;
speed = lastSpeed;
direction = 0;
}

//detect gameover
for(row=0;row<length;row++){
for(col=0;col<length;col++){
if(col!=row){
if(positions[row] == positions[col]){
gameOver = 1;
}
}
}
}



for (i=0;i<16;i++){
display_data[i] = 255;
}

for (i=0;i<length;i++){
row = positions[i]/16;
col = positions[i]%16;
display_data[col] = display_data[col] & (255-add[row]);
}

if(levelStarted == 1){
row = food/16;
col = food%16;
display_data[col] = display_data[col] & (255-add[row]);
} else {
food = nextFood;
}

if(gameOver == 1){
for (i=0;i<16;i++){
display_data[i] = 0;
}
}
  }
}

Wednesday, January 14, 2009

A Tryst with Destiny

It was Dec 2003, when I, along with my friend, decided to participate in TechFest, an event organized by IIT Bombay every year. We selected the Micromouse competition as it was sort of most challenging.

And then fun began...
How we managed to create a non-functional model is altogether different story. But the competition opened the doors of adventures of technology....

Lately, in 2005, ended up a with functional model based on ATMEGA16.
Also created a simulator in C to explore the shortest path algorithm.

A few pics for record!!!


This is my Bot which happened to be the smallest ever when we participated in 2005.




A simple Maze simulator for shortest path. Written in C. Perhaps my longest PL code.

Monday, March 6, 2006

Java for Electronics Engineers

So, I am a Java professional now.... Wow, that sounds Awesome.

After spending lots of time trying to understand what it is, joining formal training program, it comes to be a quiet simple stuff. Only thing is that, we, electronics engineers should be taught it in a different way.

Generally trainers start with JVM and OOPS concept and all.... And we poor souls get confused with lots of stuff coming simultaneously.

So, if you are an Electronics Engineer, know C and learning Java, here is something for you. Just follow me for one hour and you will know Java. Remember these six points:
  1. Java is like C.
  2. It is platform independent.
  3. It is like C, but it is not C.
  4. It is Object Oriented Programming Language.
  5. It supports Web Application Development (J2EE)
  6. It is better than C
Lets consider each point in detail:

1. Java is like C

Well, you already know C Language.
You know how to declare variables, how to write if else, switch case, methods, calling methods and all.
Its all valid for Java as well...

Let's have a code examples:

void main(){

   int i=100;
   int j =10;
   int m,n,o;
   int k = i+j;

   m = i*j;
   n = i /j;
   o = m*m/100;

   if(i==0){
      j= i*j;
   } else {
      j= k*j;
   }

   o = sum(m,n);
}


int sum(int i, int j){
   return i+j;
}


This code is valid for both C and Java... So its simple. Isn't it?



2. It is platform independent

So what does this mean? This means something but nothing to worry as a developer.

Think of C..... I use Turbo C, rum my code and get .exe file that can be executed independently even if I don't have code. right? 

Now can I execute same .exe file over Unix/Linux? Answer is NO.
So, code written for one platform is not usable for other platforms.

So if I want to reuse the code across platforms, what do I do?
Well, Java provides solution for this problem.


This is how: