Structuring with Indentation

Most programming languages use certain characters or keywords to group statements:Blocks in Python through indentation

  • begin … end
  • do … done
  • { … }
  • if … fi

Python uses a different principle. Programs get structured through indentation, this means that code blocks are defined by their indentation. Okay that’s what we expect from any program code, isn’t it? Yes, but in the case of Python it’s a language requirement not a matter of style. This principle makes it easier to read and understand other people’s Python code.

So, how does it work? All statements with the same distance to the right belong to the same block of code, i.e. the statements within a block line up vertically. The block ends at a line less indented or the end of the file. If a block has to be more deeply nested, it is simply indented further to the right.

A statement can be continued on the next line with the continuation character “\”.

Execute a Python script

In the following example we will write a variation of the mandatory “Hello World” script:

>>> print "It's easy to write a Python script!"
It's easy to write a Python script!
>>> 

The interactive interpreter is great for checking small bits of code, but if we have to write a serious program or script, we need to save our script in a file.

Let’s save our mini program in a source file. To save and edit programs in a file we need an editor. There are lots of editors, but you should choose one, which supports syntax highlighting and indentation. Under Linux you can use vi, vim, emacs, geany, gedit and umpteen others.
So, after you have chosen your editor, you can input your mini script and save it as easy_to_write.py.
The suffix .py is not really necessary under Linux but it’s good style to use it. But it is essential, if you want to write modules. Continue reading Execute a Python script

Using the Python Interpreter

With the Python interactive interpreter it is easy to check Python commands. The Python interpreter can be invoked by typing the command “python” without any parameter followed by the “return” key at the shell prompt:

python

Python comes back with the following information:

Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Once the Python interpreter is started, you can issue any command at the command prompt “>>>”.
The first thing we will do is write the mandatory “Hello World” statement: Continue reading Using the Python Interpreter

Python Overview

Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.

  • Python is Interpreted: Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP.
  • Python is Interactive: You can actually sit at a Python prompt and interact with the interpreter directly to write your programs.
  • Python is Object-Oriented: Python supports Object-Oriented style or technique of programming that encapsulates code within objects.
  • Python is a Beginner’s Language: Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games. Continue reading Python Overview

Arduino and 7 segment LED display decoder

In this instructable i will explain how to connect 7 segment display, decoder and arduino. It´s pretty easy. At first we have to learn something about decoder. I´m using BCD to 7 segment decoder. My is D147D, this is old chip, but the newer are similar. Documentation about one of them you can find here . Description of D147D you can see on picture two. There are four pins for sending BCD code to the decoder (ABCD). Table of BCD code you can see on third picture. But there is small problem. I thing, that pins are inside of chip connected to VCC source. If you want set logic zero on input, you must connect this input to the ground. Continue reading Arduino and 7 segment LED display decoder

Using the 74xx47 BCD to Seven-segment display

The 74xx47 chip is used to drive 7 segment display. You must use the 74xx47 with a common anode 7-segment display (e.g. Kingbright part number SA03). The input to the 74xx47 is a binary number DCBA where D is 8s, C is 4s, B is 2s and A is 1s. The inputs DCBA often come from a binary counter.

The display is only sensible if the binary number is between DCBA=0000 (0) and DCBA=1001 (9); this is called Binary Coded Decimal or BCD for short. If the number is larger than 9 you get a strange output on the display. Try this out by moving your mouse over the truth table. Continue reading Using the 74xx47 BCD to Seven-segment display

The AVR Microcontroller Digital I/O Ports

Introduction to AVR Digital Input/Output


Atmel AVR 8-bits microcontrollers provide pins to take in/output information form/to the outside world in the form of logic values. These pins are usually organised in groups of eight (8) and referred to as a port. The AVR use the alphabet to name these port, example PortA, PortB, etc. The figure below shows the pins of an AVR 8-bit microcontroller which has four (4) digital I/O ports: PortA, PortB, PortC and PortD. The pins of PortA are: PA0 – PA7

Continue reading The AVR Microcontroller Digital I/O Ports