0 A.D. Real Time Strategy Game for Linux

If you liked Age of Empire series from old PC days, a group of open-source developers came up with brilliant game that has similar looks and gameplay. It is free to download and you can play single mode or go against other human / A.I. opponents in multiplayer setting.

Simply install the game on Ubuntu with the following command:

sudo apt-get install 0ad

Or go to http://play0ad.com/ for more information about the game.

Playing “Mission Impossible” Tune on a Arduino with 2 Voices

Dear Arduinoists,

Inspired by Dipto’s version of the Super Mario tune with two voice, I wanted to make my own tune. I had the notations of the MI-Theme for the easy piano lessons laying around, and I thought to myself, lets convert it. It was needed for a little game I was developing on Arduino.

Dipto’s approach was good, but it lacked the function to do other stuff while the melody was playing. It took me some time to figure it out, how to handle that. Maybe my approach is hacky, but it did the job.

I didn’t try to  copy and paste the notations into the other code, but it should work. Here I´ll provide  the whole code needed. I took out the functions needed, added a blinking LED for audio/visual experience, and compiled it on my Arduino mini.  Please make sure you use the piezo/buzzer/speaker on the PINS 7+8, and make sure you downloaded the right tone library (google: “rogue tone library”).  In order to make it compile, please change the #includes in the tone.cpp like stated in the code below and have the frequenzen.h // notes.h or whereever the frequencies are defined included in the project directory. The “frequenzen.h” is the very common file provided with the tone library demos.

If you´d like to download the code: http://www.xlr8.at/downloads/Mission_Impossible.zip

Inspired by these articles here:
http://www.linuxcircle.com/2013/03/31/playing-mario-bros-tune-with-arduino-and-piezo-buzzer/

and

http://www.linuxcircle.com/2013/04/03/play-mario-bros-harmonies-on-arduino-and-2-speakers/

Have fun, and happy compiling !

Cheers André

And here goes the code:

 

/*MISSION IMPOSSIBLE

Done by: André Thomas
24.01.2014

Taken out from a poker program I have written last year.
Idea for the 2-Tone same Speaker didn´t came from me.

“Mission Impossible” theme made for Arduino by me, note by note.
——————————————————————
For compiling you need Tone() from here

http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

Go into the Tone Directory and change tone.cpp header (includes) to this:

#include <avr/interrupt.h>
//#include <avr/pgmspace.h>
//#include <wiring.h>
#include <Arduino.h>

so it will compile.
——————————————————————

*/

#include <Tone.h>
#include “frequenzen.h”
#include <avr/pgmspace.h>

#define OUT1 7
#define OUT2 8

//Sound Vars
Tone notePlayer[2];
unsigned int Counts[] = { 0, 0};
unsigned long stopTimeNote1 = 0;
unsigned long stopTimeNote2 = 0;
int value;
int value2;
int dur;
int dur2;

//Mission Impossible // Game Finale Melodie
int mimp[]  PROGMEM = {
NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_F5,NOTE_FS5,NOTE_G5, // Upswing 5

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0

,-1
};

int mimpDur [] PROGMEM = {

50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,
50,50,50,50,50,50,

200,400,200,400,200,200,200,200,              //2000
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,              //2000
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

400,-1
};

int mimp2 [] PROGMEM  = {
NOTE_G3,

NOTE_G3,0,NOTE_G3,0,NOTE_AS3,0,NOTE_C4,0,
NOTE_G3,0,NOTE_G3,0,NOTE_F3,0,NOTE_FS3,0,

NOTE_G3,0,NOTE_G3,0,NOTE_AS3,0,NOTE_C4,0,
NOTE_G3,0,NOTE_G3,0,NOTE_F3,0,NOTE_FS3,0,

NOTE_AS5,0,NOTE_G5,0,NOTE_D5,0,
NOTE_AS5,0,NOTE_G5,0,NOTE_CS5,0,
NOTE_AS5,0,NOT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NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0    ,
NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0    ,
NOTE_GS4,NOTE_C5,NOTE_F5,NOTE_GS4,NOTE_C5,NOTE_F5,NOTE_GS4,NOTE_C5,0     ,
NOTE_A4,NOTE_CS5,NOTE_FS5,NOTE_A4,NOTE_CS5,NOTE_FS5,NOTE_A4,NOTE_CS5,0,

NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0,-1

};

int mimp2Dur [] PROGMEM  = {

2025,    //+25 for the delayed melody

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

150,50,150,50,800,800,
150,50,150,50,800,800,
150,50,150,50,800,800,
150,50,400,1400,

200,200,600,1000,
200,200,600,1000,
200,200,600,1000,
200,400,1400,

25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,

25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,

25,25,25,25,25,25,25,25,300, 0
};

int led = 13;   //Just a LED

void setup()
{
pinMode(led, OUTPUT);                         // Set pinmode
notePlayer[0].begin(OUT1);                    // Voice 1
notePlayer[1].begin(OUT2);                    // Voice 2
digitalWrite(led, LOW);                       // Turn off LED
}

void loop() {

playTune(mimp, mimpDur, mimp2 , mimp2Dur ,0);  //Play the tune

}

void playTune(int melody[],  int melDurations[], int harmony[],  int harmDurations[], boolean repeat )
{
value    = pgm_read_word(&melody[Counts[0]]);
value2   = pgm_read_word(&harmony[Counts[1]]);
dur      = pgm_read_word(&melDurations[Counts[0]]);
dur2     = pgm_read_word(&harmDurations[Counts[1]]);

if(value == -1 || value2 == -1) {
notePlayer[0].stop();
notePlayer[1].stop();
digitalWrite(led, LOW); // Just a visual check if it´s doin something
if(repeat == 1) {
value=0;value2=0;dur=0;dur2=0;Counts[0]=0;Counts[1]=0;
}
return;
}

if ( millis()>stopTimeNote1 ) {
if(value==0) {
if(notePlayer[0].isPlaying()) notePlayer[0].stop();
digitalWrite(led, LOW); // Just a visual check if it´s doin something
}
else{
notePlayer[0].play(value);
digitalWrite(led, HIGH); // Just a visual check if it´s doin something
}
stopTimeNote1 = millis() + dur;
if(value != -1 ) {Counts[0]++;}

}

if ( millis()>stopTimeNote2 ) {
if(value2==0) { if(notePlayer[1].isPlaying()) notePlayer[1].stop();    }
else{
notePlayer[1].play(value2);
}
stopTimeNote2 = millis() + dur2;
if(value2 != -1 ) {Counts[1]++;}

}
return;
}

void resetTone() {
Counts[0] = 0;
Counts[1] = 0;
stopTimeNote1 = 0;
stopTimeNote2 = 0;
notePlayer[0].stop();
notePlayer[1].stop();
value=0;
value2=0;
dur=0;
dur2=0;
}

 

 

 

First Encounter: i3 super fast and light-weight Window Manager

There are many Desktop Environments (DE) for the various Linux distros, namely GNOME, KDE, XFCE, and LXDE and each of them branch-off into different variances, most notably Unity, Cinnamon and Pantheon. A lot of them offer bloated screen gimmicks, unecessary widgets, and high resource consumptions.

Today Linux Circle Team tested a few lighter-weight solution for faster application access, higher productivity and optimum use of screen area without the ridiculous shells or icons. Ligth-weight means low disk-space utilisation, memory and processor comsumptions that is low enough for use on older PCs. A desirable solution could only be achieved when the PC is not using any DE at all. How can Linux be still usable without going straight into bare-bone terminal? The answer is to use one of the minimalist Window Managers, like Xmonad, OpenBox, or Awesome. These are great tools out of the box. However, most of these solutions require programming knowledge for something as simple as changing desktop background.

Linux Circle Team was very impressed with the performance and simplicity of i3. With only one main configuration file ~/.i3/config, any Linux novice can start editing the script that look similar enough to bash and terminal commands, whereas experts can extend more advance functionalities to their likings without having to learn to program the source codes.

Out of the box experience with i3 is very minimalist. After you logged in you will be presented with plain screen with 2 bars on its top and bottom. You have to be familiar with terminal commands to be able to fire up applications. There are also a few short cut keys to help you arrange your windows, which can be customised and added in the configuration file.

Installation of i3 only takes one line in your typical Arch Linux command prompt: sudo pacman -S i3. Once installed and fired up for the first time through a login manager like LXDM, i3 comes with a setup wizard to help your getting started with the WM. With options to move from work space from another by mouse click or a simple Modifier key + Number. By default your mod key is your left Windows Menu key. If you want to view workspace #2 all you do is Win Menu Key + 2. And If you want to move a window to workspace 3 then you can go Win Menu Key + Shift + 3. Simple!

i3 is also very extensible. By default it comes with i3status bar that shows some resource usage and date-time at the bottom screen. Right click is disabled. But it is simple enough to open your default terminal by pressing Win Menu Key + Return. If you want extra menu you can use dmenu or install j4-dmenu-desktop provided by j4tools to show those applications with .desktop extension.

At start mostly used applications can be assigned to a dedicated workspace. A typical setup could look like this:
Ws1:Terminal
Ws2:Web
Ws3:Files
Workspaces can be assigned and renamed in the config file.

Overall i3 is the fastest and the most convenient, lightweight Linux experience that gives you flexibilities with mouse control, keyboard, or a combination of both. Even with our 10 year-old Pentium 3 + 500MB RAM + 2GB disk laptop, i3 on ArchLinux runs very smoothly.

Ref: https://wiki.archlinux.org/index.php/I3
There are also instructions for other distros.

(331)

Easy way to install Arch Linux

Arch is very stable, and highly customizable linux distro. You will like it if you want to build your OS up from scratch.

Prepare partition

You can use gparted from Ubuntu Live CD or another GUI tool to create root, home, and swap partitions. Or you can follow the following instruction.

Login as root.

# cgdisk /dev/sda

Create root partition

  • Hit New -> Enter
  • First Sector -> Enter
  • Size in Sector -> 15GB -> Enter
  • Hex Code of GUID (L to show codes, Enter = 8300) -> Enter
  • Enter partition name – > Enter
  • Now you will see a 15GB partition has been created.

Create swap partition

Use keyboard and select Free Space. If your RAM is 2GB, then you need 4GB or swap space. Swap space is extra memory for when you suspend your computer.

  1. Hit New -> Enter
  2. First Sector ->
  3. Size in Sector -> 4GB -> Enter
  4. Hex Code of GUID (L to show codes, Enter = 8300) -> Enter
  5. Enter partition name – > swap

Swap has been created.

Creating home partition

Use keyboard and select Free Space

  1. Hit New -> Enter
  2. First Sector -> Enter
  3. Size in Sector -> 40GB -> Enter
  4. Hex Code of GUID (L to show codes, Enter = 8300) -> Enter
  5. Enter partition name – > home -> Enter

Once ok select ‘Write‘. Type ‘yes‘ if you are sure, and then select ‘Quit‘.

Check the structure of partition by running this command:

# lsblk

You will see your hard-disk structure as follows:

sda1 – root

sda2 – swap

sda3 – home

Create file system

Format root and home

# mkfs.ext4 /dev/sda1
# mkfs.ext4 /dev/sda3 

Format swap space

# mkswap /dev/sda2  
# swapon /dev/sda2

Double-check your format

# lsblk /dev/sda

Install & Configure Base System

Mount drives

# mount /dev/sda1 /mnt
# mkdir /mnt/home
# mount /dev/sda3 /mnt/home

Install base packages

# pacstrap -i /mnt base base-devel

Configure Mounting

# genfstab -U -p /mnt >> /mnt/etc/fstab

Check if all looks good:

# nano /mnt/etc/fstab

Configure System

Log as root in the partition. This is a very important step that you install stuff on your newly created parition and not in the Live CD OS which will be removed when you log out.

# arch-chroot /mnt

Setup Locale

# nano /etc/locale.gen

Uncomment this:  en_AU.UTF-8 UTF-8

# locale-gen
# echo LANG=en_AU.UTF-8 > /etc/locale.conf
# export LANG=en_AU.UTF-8

Set up timezone

# ls /usr/share/zoneinfo/
# ln -s /usr/share/zoneinfo/Australia/Melbourne> /etc/localtime

You must adjust the country and city according to yours.

Set up Clock

# hwclock --systohc --utc

Prepare Users

Set your root password:

# passwd

Add a sudoer user. Change the last word with your username:

# useradd -m -g users -G wheel,storage,power -s /bin/bash linuxcircle
# passwd linuxcircle

Install Sudo

# pacman -S sudo
# pacman -Ss sudo
# EDITOR=nano visudo

Ucomment this line:

%wheel ALL=(ALL) ALL

Install Bootloader

# pacman -S grub
# grub-install --target=i386-pc --recheck /dev/sda
# pacman -S os-prober
# grub-mkconfig -o /boot/grub/grub.cfg
# pacman -S os-prober

Setup Network

If you are running eth cable.

# systemctl enable dhcpcd.service
# systemctl start dhcpcd.service

If you are running wifi

# pacman -S wireless_tools wpa_supplicant wpa_actiond dialog
# wifi-menu

Chose your wifi access point, then enable it on boot.

# systemctl enable network-wireless@wlan0.service
# systemctl start network-wireless@wlan0.service

 

Final Steps

# exit

Unmount the root, home and reboot the system:

# umount -R /mnt 
# reboot

Robot Project Day 6 – Arduino Sketches for Robot Control

Previous: Day 5 – Power Supplies

If you are familiar with Arduino IDE sketch, you could program simple commands to control the motors first.

The most important thing to remember is that each motor controller is different, and each one would have a dedicated ports for you to connect up the motor. Arduino compatible boards like Gertboard or Romeo V2 allow you to controll the direction through its digital pins which you can program in Sketch.

In Arduino Sketch, you could use the Servo library to control the direction and speed of motors. Or you could also create your own PWM function to control the motors. This function is then called remotely via Serial calls depending on the communication protocol and architecture that you chose.

Example of a working sketch can be found here.

(798)

Creative computing with Linux and Open Source Software, focusing on Raspberry Pi & Arduino technology