Sunday, February 17, 2013

C# Programming: Basic Paint Program

I've created this program last semester, it's just a proof of concept for now. I plan to refine this code and add new features to it. As of  now, it has only two features, paint and erase. Left click to paint and right click to erase. Here's a video demonstration



Feel free to copy the code here.

Python Programming: Sending SMS using AT Commands

Introduction
 
In these project,  will be using Python 2.7 as our programming language. In my opinion, Python is the most elegant programming language (C is my second pick). Its syntax is so concise and readable that it's like writing a pseudo-code that actually runs on a machine. The first programming language that I've learned from school (during my freshmen year) is Java but I was lost because I felt like it's so verbose and complex. I was new to programming back then and OOP was way  out of my league. During the summer, I followed my older sister's advice to study C first before jumping into Java and I was not disappointed. It helps to first understand a procedural language before diving into OOP languages such as Java or C#. C is a good language but I felt like I would need to write dozen lines of code just to accomplish a simple task (like sending SMS). Then I researched about scripting languages that are easy to learn and scalable and Python was always popping out on the list. I was surprised on how easy it is to learn the language and perform so many tasks in only a few lines of code. It doesn't have a steep learning curve unlike Java or C++. Its syntax is so clear that it's like writing an imperative statement rather than programming a code.

AT Commands 
To communicate with the USB Modem, we'll be using AT Commands. Don't worry, it's easy to use these commands and only a few will be needed here. Here's a tutorial to help you.

Materials

USB Modem
For this project, I used my SmartBro broadband, but any USB broadband should work. I've also tested this on a Globe broadband and the results are just the same.



PC or Laptop
The PC/ laptop should have Python 2.7 installed and the PySerial library to enable serial communication.

Cellphone
To test the program, we'll send it to a recipient phone

Determining the COM Port number of the USB Modem

Go to device managers, find modems and you should see your usb modem there. Right click on properties



On the USB Modem Properties, click on the Modem tab, the Port here should be the same as the one written in the program


Here's a sample run



As always, the code is available in my Github page, feel free to build upon it and add new features to it.
I hope this article helped you. In the next post, I'll be combining this capability to my previous project, the Arduino-based Temperature Monitor, so that we'll be able to get the readings through SMS.

Arduino-Based Temperature Monitor


Here's a simple hardware project that I've done last semester based on my Arduino Uno board. It uses an LM35 temperature sensor as an input device and a 2x16 LCD as its output device.

LM35 Configuration

If you're new to Arduino or programming in general, I suggest that you first read their tutorials to be familiar with the syntax and semantics. To interface the LCD to the Arduino, here's an LCD Tutorial. The LM35 temperature sensor produces an analog voltage directly proportional to temperature with an output of 1 mV per 0.1°C (10 mV per degree). The sensor accuracy is around 0.5°C, and in many cases you can use integer math instead of floating point.


Schematic and breadboard prototype using fritzing.


The code is in my Github page.


Saturday, February 16, 2013

Java Programming: Palindrome

Description:
A string is a palindrome if it reads the same forward and backward.The words “mom,” “dad,”
and “noon,” for instance, are all palindromes.

Problem:
Write a program that prompts the user to enter a string and reports whether the string is a palindrome.

Solution:
One solution is to check whether the first character in the string is the same as the last character. If so, check whether the second character is the same as the second-to-last character. This process continues until a mismatch is found or all the characters in the string are checked, except for the middle character if the string has an odd number of characters.

To implement this idea, use two variables, say low and high, to denote the position of two characters at the beginning and the end in a string inputString. Initially, low is 0 and high is inputString.length() – 1. If the two characters at these positions match, increment low by 1and decrement high by 1. This process continues until (low >= high) or a mismatch is found.

The solution is in my Github page.

Here's a test run



 

C++ Programming

Here's a simple C++ problem that deals with basic input and output processing. The solution is straight forward, using while loops, if statements and decrements. 

Problem:
Write a program that reads in the size of the side of a square and then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all side sizes between 1 and 20. For example, if your program reads a size of 5, it should print

*****
*    *
*    *
*    *    
*****

The  solution is in my Github page.

Here's a sample test run




Hello World!

For my first post, I would like to introduce myself. I'm a Computer Engineering student from the Polytechnic University of the Philippines.  My interests are programming (C/C++, Java, Python, C#), open source hardware (Arduino), and Console/PC gaming (NBA 2K13, Assassins Creed). I also love mathematics (Calculus, Digital Signal Processing) but I haven't practiced my problem solving skills for quite some time because I'm always busy either programming or playing games. I created this blog to cater all of my programming/ electronics projects and to serve also as a reference for others' projects. It's my own little way of contributing to the open source community. :)