Posts Tagged ‘Processing’

Hello to the UK’s Robot Brighton

September 24, 2009

Thanks for the mention from the UK’s @robotbrighton robotics group. Recently I read @fluffyemily‘s RoboChick Rampant Robotic Rumpus blog post about the book “Making Things Talk“. This is a great book and it influenced my decision to explore the combination of Processing and Arduino through this web site.  The urge to purchase books is great and it’s easy to spend a small fortune on computer books. Another book worth adding to your bookshelf  is “Programming Interactivity“, I’m still forming my opinion on this book but in general I think it is useful.

I checked to see what was showing up on my site’s home page at the time of RobotBrighton’s mention and realized that a little explanation would be helpful. Most of the articles may be considered a Stream of Consciousness and when reading top-down consecutively the articles appear out of proper order and somewhat disconnected. I’m basing this site’s articles on a series of workshops I’m developing titled “Topics in Robotics, Electronics, and Communications”.

I started DIY Robotics Lab as a way to encourage people interested in this technology to begin exploring what they can do at home. So many of the robot kits used by high school students are too expensive for home use.

Presently much of this site is about programming using Arduino and Processing. I believe there are enough similarities when learning to program in one it will help you learn the other. Processing can provide an enjoyable way of interacting with our robotic creations. One series of articles begins with this Processing – Arduino Comparison article.

Another series is an example of low cost robotics projects spanning multiple web sites. Here is an article about our Robotic Labyrinth using a Wii Fit balance board. I saw this as a great way to get kids interested in robotics. An article on this site illustrates using Processing to interact with a simulated joystick. Since publishing that article I’ve added xBox 360 controller support through Processing to control the labyrinth. Another member of our labyrinth project has posted an article showing our labyrinth in action at the Missouri state fair. He also publish this article “Using a PC Joystick with the Arduino“. Since older game port joysticks can be bought at thrift stores for around $3 its another cheap way to encourage home based robotics labs. You can find more information about our labyrinth project at my personal blog SomeoneKnows.

Another series of articles on this site starts with Learning the C Language with Arduino. It explores using C while building circuits to blink LEDs.

I hope you enjoy the site and find the information useful. I would like to learn about your thoughts and comments. Thanks for stopping by.

(c) 2009 – Vince Thompson

Incrementing Variables Using ++

September 13, 2009

I received an email from Brendan, one of our 16 year old members attending the Make:KC meetings. He is looking into using the Processing language. One of his questions was about how variables are incremented using the ++ syntax.

  • The ++ syntax is for incrementing values – counting up by one each time.
  • The — syntax is for decrementing values – counting down by one each time.

References:

A thought about debugging

One thing I miss in the Processing and Arduino development environment is a way to step through a program line by line to debug a program as it’s running. Since we don’t have that feature the next best thing is by using print statements. The following programs are written to hopefully show you what is happening in the program as it is running.

Here is a short Processing program to illustrate incrementing:

Incrementing Variables in Processing


void setup()
{
 int a;
 int b;

 a=0;
 print("Initialize value: a = ");
 println(a);

 print("example 1: ++a is equal ");
 println(++a);
 println("  this example increments 'a' by 1 before evaluating (using) the variable");
 println("  in the print statement\n");

 a=0;
 print("Reinitialize: a = ");
 println(a);

 print("example 2: a++ is equal ");
 println(a++);
 println("  this example increments 'a' after printing its value");
 println("  The ++ incrementor only increases the value by 1 each time\n");

 a=0;
 print("Reinitialize: a = ");
 println(a);
 println("example 3: a += 1");
 print("  a equals ");
 println(a += 1);
 println("  This is another example of incrementing the variable by 1");
 println("  a += 1 is a simplified way of writing  a = a + 1\n");

 a=0;
 b=5;
 print("Reinitialize: a = ");
 print(a);
 print(" and b = ");
 println(b);
 println("example 4: a += b");
 print("  a equals ");
 println(a += b);
 println("  The += operator lets you change the incrementing value");
 println("  a += b is a simplified way of writing  a = a + b\n");

}

void draw()
{
}

When you look at Processing’s output view as you run the program you’ll see:

Initialize value: a = 0
example 1: ++a is equal 1
this example increments ‘a’ by 1 before evaluating (using) the variable in the print statement

Reinitialize: a = 0
example 2: a++ is equal 0
this example increments ‘a’ after printing its value
The ++ incrementor only increases the value by 1 each time

Reinitialize: a = 0
example 3: a += 1
a equals 1
This is another example of incrementing the variable by 1
a += 1 is a simplified way of writing  a = a + 1

Reinitialize: a = 0 and b = 5
example 4: a += b
a equals 5
The += operator lets you change the incrementing value
a += b is a simplified way of writing  a = a + b

To illustrate the similarities of programming in Processing and programming for an Arduino, consider this program.

Incrementing Variables in Arduino

void setup()
{
int a;
int b;

Serial.begin(9600);

a=0;
Serial.print("Initialize value: a = ");
Serial.println(a);

Serial.print("example 1: ++a == ");
Serial.println(++a);
Serial.println("  this example increments 'a' by 1 before evaluating (using) the variable");
Serial.println("  in the print statement\n");

a=0;
Serial.print("Reinitialize: a = ");
Serial.println(a);

Serial.print("example 2: a++ == ");
Serial.println(a++);
Serial.println("  this example increments 'a' after printing its value");
Serial.println("  The ++ incrementor only increases the value by 1 each time\n");

a=0;
Serial.print("Reinitialize: a = ");
Serial.println(a);
Serial.println("example 3: a += 1");
Serial.print("  a equals ");
Serial.println(a += 1);
Serial.println("  This is another example of incrementing the variable by 1\n");

a=0;
b=5;
Serial.print("Reinitialize: a = ");
Serial.print(a);
Serial.print(" and b = ");
Serial.println(b);
Serial.println("example 4: a += b");
Serial.print("  a equals ");
Serial.println(a += b);
Serial.println("  The += operator lets you change the incrementing value\n");
}

void loop()
{}

The only difference with an Arduino program is in order to display messages on your computer screen you need to send them through a serial connection using the “Serial.” prefix on the “print” statement. The variables get incremented the same way whether using Processing or Arduino.

(c) 2009 – Vince Thompson