Non Sequitur comics, by Wiley Miller.

[audio:http://cejug.podomatic.com/enclosure/2009-03-17T08_20_43-07_00.mp3]
O Igo Coelho recebe neste episódio eu e o Amaury Brasil, falamos sobre o que é o CCT, PUJ e os temas do próximo encontro dia 23 de março de 2009 na UNIFOR. Apresentando o LWUIT com Daniel Valente e Introdução a programação em Java para a TV Digital com Amaury Brasil.
Fotos da gravação lá na Fortes.
Parabéns ao Igo Coelho mais uma vez pela iniciativa e a todos que contribuÃram para fazer mais esse episódio do CEJUG Podcast acontecer. ;D
I got a simple motor from a broken domestic printer. It’s a Mitsumi m355P-9T stepping motor. Any other common stepping motor should fits. You can find one in printers, multifunction machines, copy machines, FAX, and such.
With a flexible cap of water bottle with a hole we make a connection between the motor axis and other objects.
With super glue I attached to the cap a little handcraft clay ox statue.
It’s a representation from a Brazilian folkloric character Boi Bumbá. In some traditional parties in Brazil, someone dress a structure-costume and dances in circular patterns interacting with the public.

Photos by Marcus Guimarães.
Controlling a stepper motor is not difficult. There’s a good documentation on how to that on the Arduino Stepper Motor Tutorial. Basically it’s about sending a logical signal for each coil in a circular order (that is also called full step).

Animation from rogercom.com.

You’ll probably also use a driver chip ULN2003A or similar to give to the motor more current than your Arduino can provide and also for protecting it from a power comming back from the motor. It’s a very easy find this tiny chip on electronics or automotive stores or also from broken printers where you probably found your stepped motor.

With a simple program you can already controlling your motor.
// Simple stepped motor spin
// by Silveira Neto, 2009, under GPLv3 license
// http://silveiraneto.net/2009/03/16/bumbabot-1/
int coil1 = 8;
int coil2 = 9;
int coil3 = 10;
int coil4 = 11;
int step = 0;
int interval = 100;
void setup() {
pinMode(coil1, OUTPUT);
pinMode(coil2, OUTPUT);
pinMode(coil3, OUTPUT);
pinMode(coil4, OUTPUT);
}
void loop() {
digitalWrite(coil1, step==0?HIGH:LOW);
digitalWrite(coil2, step==1?HIGH:LOW);
digitalWrite(coil3, step==2?HIGH:LOW);
digitalWrite(coil4, step==3?HIGH:LOW);
delay(interval);
step = (step+1)%4;
}
Writing a little bit more generally code we can create function to step forward and step backward.
My motor needs 48 steps to run a complete turn. So 360º/48 steps give us 7,5º per step. Arduino has a simple Stepper Motor Library but it doesn’t worked with me and it’s also oriented to steps and I’d need something oriented to angles instead. So I wrote some routines to do that.
For this first version of BumbaBot I mapped angles with letters to easy the communication between the programs.

Notice that it’s not the final version and there’s still some bugs!
// Stepped motor control by letters
// by Silveira Neto, 2009, under GPLv3 license
// http://silveiraneto.net/2009/03/16/bumbabot-1/
int coil1 = 8;
int coil2 = 9;
int coil3 = 10;
int coil4 = 11;
int delayTime = 50;
int steps = 48;
int step_counter = 0;
void setup(){
pinMode(coil1, OUTPUT);
pinMode(coil2, OUTPUT);
pinMode(coil3, OUTPUT);
pinMode(coil4, OUTPUT);
Serial.begin(9600);
}
// tells motor to move a certain angle
void moveAngle(float angle){
int i;
int howmanysteps = angle/stepAngle();
if(howmanysteps<0){
howmanysteps = - howmanysteps;
}
if(angle>0){
for(i = 0;i
In another post I wrote how create a Java program to talk with Arduino. We'll use this to send messages to Arduino to it moves.Â

[put final video here]
To be continued... :)
Para o controle de qualidade quando encondando vÃdeos com o FFmpeg use o parâmetro -qscale seguido de um número. Os número podem ir de 1 (melhor qualidade) até 31 (pior qualidade), sendo que 13 já é uma qualidade bem ruim.
Convertendo pro exemplo um vÃdeo chamado exemplo.flv para um arquivo ogg com a melhor qualidade seria:
ffmpeg -i exemplo.flv -qscale 1 saida.ogg
Sem usar esse parâmetro os arquivos encodados em OGG ficam com uma qualidade mediana. Uma opção bem útil é usar a mesma qualidade do arquivo de entrada, já que não é possÃvel melhorar a qualidade do vÃdeo mesmo. Para isso existe o parâmetro -sameq. No exemplo anterior bastaria:
ffmpeg -i exemplo.flv -sameq saida.ogg
Com isso eu tenho reduzido os vÃdeos da minha câmera para arquivos que só ocupam cerca de 1/5 do tamanho original e ainda assim mantém a mesma qualidade.
Esse é uma amostras dos bastidores do que rolou nas filmagens nessa terça-feira na Casa Brasil unidade Vila União. As filmagens são por mim e pela pequena Vitória de apenas 5 anos. =)
A reportagem vai ao ar no canal da Globo, esse sábado ao meio dia. Não percam!
Atualizado em 7 de Março:
Algumas fotos dos bastidores da gravação.
Pra quem não assistiu na TV, eu gravei com a câmera, aqui está.
Download: cbvilauniaonatv.ogg
Parabéns Alyne, Alexandra, Leonardo e todos, vocês foram ótimos!
Arduino is a free popular platform for embedded programming based on a simple I/O board easily programmable. Interfacing it with Java allow us to create sophisticated interfaces and take advantages from the several API available in the Java ecosystem.
I’m following the original Arduino and Java interfacing tutorial by Dave Brink but in a more practical approach and with more details.
Step 1) Install the Arduino IDE
This is not a completely mandatory step but it will easy a lot our work. Our program will borrow some Arduino IDE libraries and configurations like which serial port it is using and at which boud rate. At the moment I wrote this tutorial the version of Arduino IDE was 0013.
Step 2) Prepare your Arduino
Connect your Arduino to the serial port in your computer. Here I’m connecting my Arduino with my laptop throught a USB.

Make sure your Arduino IDE is configured and communicating well if your Arduino. Let put on it a little program that sends to us a mensage:
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println("Is there anybody out there?");
delay(1000);
}
Step 3) Install RXTX Library
We will use some libraries to acess the serial port, some of them relies on binary implementations on our system. Our first step is to install the RXTX library (Java CommAPI) in your system. In a Debian like Linux you can do that by:
sudo apt-get install librxtx-java
Or using a graphical package tool like Synaptic:
For others systems like Windows see the RXTX installation docs.
Step 4) Start a new NetBeans project
Again, this is not a mandatory step but will easy a lot our work. NetBeans is a free and open source Java IDE that will help us to develop our little application. Create a new project at File → New Project and choose at Java at Categories and Java Application at Projects.
Chose a name for your project. I called mine SerialTalker.
At the moment I wrote this tutorial I was using Netbeans version 6.5 and Java 6 update 10 but should work as well on newer and some older versions
Step 5) Adding Libraries and a Working Directory
On NetBeans the Projects tab, right-click your project and choose Properties.
On the Project Properties window select the Libraries on the Categories panel.
Click the Add JAR/Folder button.
Find where you placed your Arduino IDE installation. Inside this directory there’s a lib directory will some JAR files. Select all them and click Ok.
As we want to borrow the Arduino IDE configuration the program needs to know where is they configuration files. There’s a simple way to do that.
Still in the Project Properties window select Run at Categories panel. At Working Directory click in the Browse button and select the directory of your Arduino IDE. Mine is at /home/silveira/arduino-0013.
You can close now the Project Properties window. At this moment in autocomplete for these libraries are enable in your code.
Step 6) Codding and running
Here is the code you can replace at Main.java in your project:
package serialtalk;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;
public class Main {
static InputStream input;
static OutputStream output;
public static void main(String[] args) throws Exception{
Preferences.init();
System.out.println("Using port: " + Preferences.get("serial.port"));
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
Preferences.get("serial.port"));
SerialPort port = (SerialPort)portId.open("serial talk", 4000);
input = port.getInputStream();
output = port.getOutputStream();
port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
while(true){
while(input.available()>0) {
System.out.print((char)(input.read()));
}
}
}
}
Now just compile and run (with your Arduino attached in your serial port and running the program of step 2).
There is. Now you can make your Java programs to talk with your Arduino using a IDE like NetBeans to create rich interfaces.

My Arduinos arrived yesterday. It’s a programmable open source and hardware device.
To install its software on my Ubuntu 8.10 I need Java installed and some tools that I could get by:
sudo apt-get install avrdude avrdude-doc avrp avrprog binutils-avr gcc-avr
Some fellows asked for some Sun SPOT posters.
Here it is one that you can use to let people know about Project Sun SPOT.

Download the PNG with 200 dpi resolution or the SVG vetorial drawing. You can use a tool like Inkscape to open and edit the SVG file. You can change colors, images, texts and anything else.
If you need a poster to a presentation about Sun SPOT you can just print or edit this one:

Again, download a 200 pdi PNG file or the SVG vetorial drawing.
Good times with Sun SPOT. 😉
Obrigado a todos que compareceram a meu webinar de JavaFX mesmo durante o carnaval. =)
Conforme prometido aqui estão os slides que nós utilizamos:
Download: javafx_carnaval2009.odp
Para assistir o replay da apresentação, clique aqui.
Nos exemplos de código eu procurei seguir a abordagem do Robert Eckstein no videocast Learn JavaFX Script in 15 minutes. O resultado foi muito bom para apresentar a sintáxe da linguagem.
Exemplo 1
def raio = 4;
def Pi = 3.1415;
var area = Pi * (raio * raio);
println("Ãrea do cÃrculo: {area}");
SaÃda do Exemplo 1:
Ãrea do cÃrculo: 50.264
Exemplo 2
var isActive = true;
var isVisible:Boolean = false;
println("Active: {isActive}");
println("Visible: {isVisible}");
isVisible = true;
println("Visible: {isVisible}");
SaÃda do Exemplo 2:
Active: true
Visible: false
Visible: true
Exemplo 3
var integer1 = 3;
var number1 = 3.0;
var integer2:Integer = 3;
var number2:Number = 3.0;
var number3:Number = integer1;
println("Integer 1: {integer1}");
println("Integer 2: {integer2}");
println("Number 1: {number1}");
println("Number 2: {number2}");
println("Number 3 (copiado do integer 3): {number3}");
println("Number 1 como Integer: {number1 as Integer}");
SaÃda do Exemplo 3:
Integer 1: 3
Integer 2: 3
Number 1: 3.0
Number 2: 3.0
Number 3 (copiado do integer 3): 3.0
Number 1 como Integer: 3
Exemplo 4
var s1 = "Olá";
var s2:String = "Olá";
var s3 = "Olá 'mundo'";
var s4 = 'Olá "mundo" ';
println("Primeira String é {s1}");
println("Segunda String é {s2}");
println("Terceira String é {s3}");
println("Quarta String é {s4}");
SaÃda do Exemplo 4:
Primeira String é Olá
Segunda String é Olá
Terceira String é Olá ‘mundo’
Quarta String é Olá “mundo”
Exemplo 5
var hora = 16;
println("Olá! {if(hora < 12) "Bom dia" else "Boa tarde"}");
def string1 = "Java";
def string2 = "FX";
def javafxstring = "{string1}{string2}";
println(javafxstring);
SaÃda do Exemplo 5:
Olá! Boa tarde
JavaFX
Exemplo 6
var duration1 = 1s;
var duration2 = 10m;
var duration3:Duration = 5h;
var duration4:Duration = 1ms;
println("Duração 1 é (5 seg): {duration1}");
println("Duração 2 é (10 min): {duration2}");
println("Duração 3 é (5 h): {duration3}");
println("Duração 4 é (1 milisegundo): {duration4}");
println("Duração 1 + Duração 2 (10min e 5 seg): {duration1+duration2}");
SaÃda do Exemplo 6:
Duração 1 é (5 seg): 1000ms
Duração 2 é (10 min): 600000ms
Duração 3 é (5 h): 18000000ms
Duração 4 é (1 milisegundo): 1ms
Duração 1 + Duração 2 (10min e 5 seg): 601000ms
Exemplo 7
def Pi = 3.1415;
def raio = 5;
println("A área do cÃrculo é {getArea(raio)}");
function getArea(raio: Number): Number {
var area = Pi * (raio*raio);
return area;
}
SaÃda do Exemplo 7:
A área do cÃrculo é 78.53750000000001
Exemplo 8
function checaBalanço(cta:Conta):Void{
if(cta==null){
println("Conta nula");
}else{
println("Balanço é de {cta.balanço}");
}
}
class Conta {
var balanço: Number;
}
var minhaconta = Conta {
balanço: 9.99
}
checaBalanço(minhaconta);
SaÃda do Exemplo 8:
Balanço é de 9.99
Exemplo 9
class Monstro {
var nome: String;
var nÃvel: Integer;
var vida: Number;
}
var ogr = Monstro {
nome: "Ogro"
nÃvel: 16;
vida: 100.0;
}
println("nome: {ogr.nome}");
println("nÃvel: {ogr.nÃvel}");
println("vida: {ogr.vida}");
SaÃda do Exemplo 9:
nome: Ogro
nÃvel: 16
vida: 100.0
Exemplo 10
class Monstro {
var nome: String;
var nÃvel: Integer;
var vida: Number;
var força: Number;
function porrada(outro:Monstro){
outro.vida = outro.vida - força;
}
}
Exemplo 11
abstract class MonstroVoador {
var nome: String = "monstro voador";
abstract function voa():Void;
}
class Griffon extends MonstroVoador{
override function voa(){
println("estou voando =D");
}
}
Exemplo 12
var software: String[] = ["NetBeans", "Java", "JavaFX"];
var hardware: String[] = ["UltraSparc", "Niagra", "SunSpot"];
var oferta = [software,hardware];
println(software);
println(hardware);
println(oferta);
SaÃda do Exemplo 12:
[ NetBeans, Java, JavaFX ]
[ UltraSparc, Niagra, SunSpot ]
[ NetBeans, Java, JavaFX, UltraSparc, Niagra, SunSpot ]
Exemplo 13
var A = [1..10];
var B = [1,2,3,4,5,6,7,8,9,10];
println("A é igual a B? {A==B}");
var C: Integer[] = [1..11];
println("A é igual a C? {A==C}");
SaÃda do Exemplo 13:
A é igual a B? true
A é igual a C? false
Exemplo 14
var umadez = [1..10];
var copia = umadez;
println(umadez);
println(copia);
var outracopia = umadez[valor|true];
println(outracopia);
var sopares = umadez[valor|(valor mod 2)==0];
println(sopares);
SaÃda do Exemplo 14:
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
[ 2, 4, 6, 8, 10 ]
Exemplo 15
var sequencia = [1..10];
println("tamanho de sequencia é {sizeof sequencia}");
insert 11 into sequencia;
delete 3 from sequencia;
insert 3 before sequencia[2];
delete sequencia[1];
insert 2 after sequencia[0];
println(sequencia);
delete sequencia;
println(sequencia);
SaÃda do Exemplo 15:
tamanho de sequencia é 10
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
[ ]
Exemplo 16
var meses = ["jan", "fev", "mar", "abr", "mai", "jun", "jul",
"ago", "set", "out", "nov", "dez"];
println(sizeof meses);
println(meses[2..5]);
println(meses[2..<5]);
println(meses[2..]);
println(meses[2..<]);
SaÃda do Exemplo 16:
12
[ mar, abr, mai, jun ]
[ mar, abr, mai ]
[ mar, abr, mai, jun, jul, ago, set, out, nov, dez ]
[ mar, abr, mai, jun, jul, ago, set, out, nov ]
Exemplo 17
var meses = ["jan", "fev", "mar", "abr", "mai", "jun", "jul",
"ago", "set", "out", "nov", "dez"];
for(mes in meses){
println(mes);
}
SaÃda do Exemplo 17:
jan
fev
mar
abr
mai
jun
jul
ago
set
out
nov
dez