Student • Programmer • Hacker • Geek • Coffee Addict

I suck at updating.

Wow, it’s been a while! The past 7 weeks have totally flown by since starting back for the first semester of my second year at Derby University. I found it a lot harder to get back into the swing of things after coming back from a (stupid) 17 week summer.

I am fully back in action now though. I’m currently taking a break from coding up a Software Development assignment which is due next friday. I hope to have the code finished soon so I can start working on some Unit tests and UML.

I’ve only taken 3 modules this semester, which means I’ll be taking 5 after christmas. I’m a little apprehensive about it seeing as I’ve got a ton of work to do just for these 3, but I’m sure I’ll work it out. I currently have a database report to finish, a database & application to develop, analyse and produce use case, class and sequence diagrams for a given scenario for my object oriented systems analysis class and work on these software assignments. Busy!

I will get around to uploading a video of the pong game in the post below, using both the iPad, iPhone and slider controls using the Arduino.

Back to work!

iOS Device Controlled Pong

Here is my simple game of pong programmed in Processing. Uses iOS devices to control the slider. Could easily be modified to use the mouse or another piece of hardware to control the slider.

I’ll be posting a video demo and altering the code to make it multiplayer using 2 x iOS devices or 1 iPad, using the larger screen. (Code below updated to include multiplayer via 2 iOS devices or 1 iPad.)

//import libraries
import oscP5.*;
import netP5.*;
OscP5 oscP5;
import processing.serial.*;

//score
int cScore = 0;
int pScore = 0;

//direction start
int x_counter = 0;
int y_counter = 2;

//paddle global

float pY = 0.0f;
float p2Y = 0.0f;
//start points
float bX = 300.0f;
float bY = 200.0f;

//serial port
Serial myPort;

//ball speed
int h_speed = 15;
int m_speed = 5;
int l_speed = 0;

//iOS device control
void oscEvent(OscMessage theOscMessage)
{
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();

if (addr.equals("/1/pY")) { pY = val * 250; }
if (addr.equals("/1/p2Y")) { p2Y = val * 250; }
//add more to use more devices

}
//setup
void setup()
{
  background(0);
  size(600,400);
  frameRate(55);
  myPort = new Serial(this, Serial.list()[0],9600);
  oscP5 = new OscP5(this, 8000);
  delay(2000);  
}

void draw()
{
  
  background(0);
 //centre line
  
  //basic setup
  background(0);
  smooth();
  fill(0);
  stroke(255);
  
  //ball
  fill(255);
  rect(bX,bY,10,10);
  
  //dotted lines
  for (int i = 0; i < 401; i = i++ + 10)
  {
   rect(300, i, 2, 2);
  }
  //main program
  
  //switching directon
  //right
  if (x_counter == 1)
  { bX = bX++ + h_speed; }
  //left
  else if (x_counter == 0)
  { bX = bX-- - h_speed; }
  
  //down
  if (y_counter == 1)
  { bY = bY-- - h_speed; }
  //up
  else if (y_counter == 0)
  { bY = bY++ + h_speed; }
  //central
  else if (y_counter == 2)
  { bY = 200; }
  
  //bounce from paddle
  if (bX == 15)
  { 
    if((bY >= pY - 5) && (bY <= pY + 150))
    { 
      x_counter = 1;
      if ((bY >= pY - 5) && (bY <= pY + 50))
      { y_counter = 1; }
      
      else if ((bY >= pY + 100) && (bY <= pY + 150))
      {y_counter = 0;}
    }
    else
    { x_counter = 0; }
  }
  else if (bX < 0) 
    { 
      bY = 200;
      bX = 300;
      cScore = cScore +1;
    }
  
   if (bY <= 15)
    {
      y_counter = 0;
    }
    else if (bY >= 385)
    {
      y_counter  = 1;
    }
  //bounce from sides and roof
  
  else if (bX == 585)
  { 
    //2 player 
     if((bY >= p2Y - 5) && (bY <= p2Y + 150))
    { 
      x_counter = 0;
      if ((bY >= p2Y - 5) && (bY <= p2Y + 50))
      { y_counter = 0; }
      
      else if ((bY >= p2Y + 100) && (bY <= p2Y + 150))
      {y_counter = 1;}
    
    /* 1 player
    x_counter = 0; 
    if ((bY >= p2Y) && (bY <= p2Y + 150) && (bX >= 585))
      { y_counter = 1; }
   
      
    else if ((bY >= pY + 100) && (bY <= pY + 150))
    {y_counter = 0;}*/
}

  }
  else if(bX >= 599)
  {
    y_counter = 0;
    bY = 200;
    bX = 300;
    pScore = pScore + 1;
  }
  
  //text
  fill(255);
  textSize(32);
  text(pScore, 265,50);
  text(cScore, 320, 50);
  
  //Player side
  rect(0, pY, 10, 150);
  
  //Player2 side
  rect(590, p2Y, 10, 150);
  }


RGB LED Colour Processing

Today I decided to play with the iPad, Arduino and Processing a little bit more. Ever since I received my RGB LED’s in the post, I’ve been wanting to buy some sliders to wire up and mix the colours, I could honestly spend a very long time just mixing up the colours - I find it very soothing! Well since I’ve been playing about with the iPad controls on TouchOSC just lately I thought I’d use the slider interfaces to do the same thing, I posted a small video demo.

Video


Arduino, TouchOSC, Processing, RGB LED from Curt Walker on Vimeo.

This sort of thing is a great little project for first time Arduinoers that was to make something cool and interactive. (There is no reason you couldn’t use an iPhone or iPod Touch to do the same thing, you would just need TouchOSC installed on your iOS enabled device). I will get around to posting the code and circuit diagram.

Breadboard Diagram


Arduino Code

// Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11


long int inByte; 
int wait = 10; //10ms

void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  Serial.begin(9600); 
}

//This function uses 255 - because I am using Common Anode LEDs, if you are using Common Cathode, remove the 255-
void outputColour(int red, int green, int blue) 
{
  analogWrite(redPin, 255 - red);
  analogWrite(bluePin, 255 - blue);
  analogWrite(greenPin, 255 - green);    
}


int* getColour() 
  {
    int* colour;
    int i;
    i = 0;
    while (i  0) {
        colour[i] = Serial.read();
        i++;
      }
  }
  return colour;
}

// Main program
void loop()
{
  if (Serial.available() > 0) 
  {
    // get incoming byte:
    inByte = Serial.read();
    
    if (inByte == 'C')
      {
        int* one;
        one =  getColour();
        outputColour(one[1],one[2],one[3]);
      } 
  }
  
  delay(wait);
}

Processing Code

import oscP5.*;
import netP5.*;
OscP5 oscP5;
import processing.serial.*;
Serial myPort;
float R = 0.0f;
float G = 0.0f;
float B = 0.0f;
void setup()
{
  size(800,600);
  frameRate(55);
  myPort = new Serial(this, Serial.list()[0],9600);
  oscP5 = new OscP5(this, 8000);
}

void oscEvent(OscMessage theOscMessage)
{
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();

if (addr.equals("/1/r")) { R = val * 255; }
else if (addr.equals("/1/g")) { G = val * 255; }
else if (addr.equals("/1/b")) { B = val * 255; }
}

void draw()
{
  background(255);
  int int_R = (int)R;
  int int_G = (int)G;
  int int_B = (int)B;
  
  myPort.write("CL");
  myPort.write(int(int_R));
  myPort.write(int(int_G));
  myPort.write(int(int_B));
  background(int_R, int_G, int_B);
  
  //You can uncomment the code below, prints output to console
/*  
  print(" Red: " + int_R);
  print(" Green: " + int_G);
  print(" Blue: " + int_B);
  println(" ");
  
  */
}

Processing, TouchOSC, iPad

I’ve recently started to play with TouchOSC on the iPad and Processing. I’ve written a small processing program that will track the output from the XY Pad Module on the iPad and plot it on the desktop application over a WiFi network.

TouchOSC Setup

These are what the settings on your iOS device should look like. This will work with the iPad and iPhone but the example in this post is on the iPad.


Video Demo

Demo XY Pad - TouchOSC, iPad, Processing from Curt Walker on Vimeo.

Resources

TouchOSC Processing

Processing Code:

import processing.serial.*;
import oscP5.*;
import netP5.*;
OscP5 oscP5;

float x = 0.0f;
float y = 0.0f;
void setup()
{
  size(835, 610);
  frameRate(25);
  oscP5 = new OscP5(this, 8000);
}

void oscEvent(OscMessage theOscMessage)
{
String addr = theOscMessage.addrPattern();
float y_val = theOscMessage.get(0).floatValue();
float x_val = theOscMessage.get(1).floatValue();

if (addr.equals("/1/xy1")) { x = x_val; y = y_val; }

println("Co-ords: " + theOscMessage.get(1).floatValue() + theOscMessage.get(0).floatValue());
}

void draw()
{
  background(0);
  smooth();
  fill(0);
  strokeWeight(3);
  stroke(255,255,0);

  //inner rectangle
  rect(1, 1, 832,544);
  fill(255,255,0);
  stroke(255,255,0);
  strokeWeight(1);

  //verticle line
  line(0, y*545, 835, y*545);
  //horizontal line
  line(x*835,0,x*835,545);
  fill(255,255,0);
  stroke(255,255,0);
  
  //stats
  fill(50,50,50);
  stroke(200,200,200);
  rect(1,559,834,50);
  fill(255);
  text("y " + y*545, 445, 590);
  text(" , " , 535, 590);
  text("x " + x*835, 555, 590);

   //Direction
  text("Direction: ", 650 ,590);
  if(x*835 <= 417.5){ text("Left", 720, 590); }
  else { text("Right", 720, 590); }

}

iPad / TouchOSC / Processing / Arduino / Other Stuff

So, I’ve not got around to posting since forever. I’ve not really been up to much to be honest.

Yesterday a friend and I (Tim) went to Nottinghack / HS NOTTS for the first time. It was a really good night, and everyone was super friendly. There are a lot of cool projects that other members brought with them, my favourite being the iPhone / Nunchuck controlled tank.

When I saw the application that was controlling the tank from the phone, I was really interested in using the same sort of thing to control my own projects via the iPhone and iPad. I found out that it was made possible by using TouchOSC and the Processing language. Today I started to play around with simple concepts such as moving objects on screen using the and moving a small servo with the iPad.

Here are some videos:

Moving a small Servo:

iPad & Small Servo from Curt Walker on Vimeo.

Servo & AR:

iPad + TouchOSC + Processing + AR from Curt Walker on Vimeo.

I’ll soon have a video of moving objects with the iPad that exist within Processing applets.

My mate and I!

My mate and I!

Urgh.

So I don’t really get around to posting as frequently as I’d like. Most of the time I don’t really feel i have much to write about.

Quite a bit is happening in the tech world just lately, and a lot of the attention is looming on the iPhone 4 and it antenna ‘flaw’. It always seems that if there is anything at all available to pick at Apple, people will. Even at the smallest of things. Now I’m not saying that these sorts of things should happen, because if you’re paying £500 for a handset you expect it to be perfect. Personally I’ve not had any problems with the reception on my iPhone 4.

I’ve seen a lot of people lately slating Apple as a company, slating their products and slating their operating system. The people I’m talking about are people who don’t own apple products and don’t use their operating systems. So i ask myself 2 things:

Without using one of their products on a day to day basis, how can these people even begin to fault these devices?

Why should the care?

The second question i find to be most important. Why on earth should they care, i can understand if you’re one of the unlucky customers who bought an iPhone 4 and you’re experiencing dropped calls, because i know i would be a little miffed after shelling out the money on a handset if you’re not going to get a reliable service out of it but for the others who own different phones, to keep on calling the device a failure and ripping into Apple, I can’t see a reason.

iPhone 4 / iOS4

This morning was the earliest I’d been up in a long while. Last night I couldn’t sleep so I ended up only getting around 4 hours worth.

I waited in line for around 4 hours to pick up my brand new iPhone 4. I am so pleased with it. It was worth the early start and huge queue, I was only 11th in the queue!

The FaceTime function is pretty sweet, I was kind of expecting slow and pixelated video quality, but I’ve just had a play and it’s very nice indeed.

Pic to follow!

Project & Ideas

Well, yesterday I started to code a small idea I’ve been kicking around for a while. On a recent project for a client I was trying to find a simple solution: An easy to use, content managed gallery that I could install for said client and have them upload / delete and rename files. That’s all I needed. I searched and searched the web for a solution but everything was over-complicated so I decided to code my own.

Now, my PHP skills are no where near perfect but last night I got all the basic functions working in a couple of hours. It’s a really simple but effective way for users to manage their images gallery on their web pages. Once I have a better version and I’ve cleaned up my code I’ll post it as a download for people to test.

I’m glad to have a project to work on over the summer now that I’m done with uni until September.

Boredom is setting in.

It’s 1.48am and I’m still up. I have nothing to be up for but it seems I’m up just for the sake of being awake.

Since finishing uni and having nothing to do, I seem to be getting very crap at going to be at sensible times. 2am seems to be the normal sort of time I’m getting to bed at the moment and i hate it because i feel so crap in the mornings.

Today however i have been less bored because I’ve just finished the bare bones of a gallery script I’m working on. I’ve also got to put the first ‘draft’ if you like to test on a clients site. I’m thinking about developing this more and creating a free app for people to use on their own projects. Early days yet though.

Tomorrow i have nothing planned, which sucks. I might possibly see if i can meet a friend on his lunch break, then head to town and grab a coffee whilst doing some rough wireframes for the UI of the project I mentioned earlier. Who knows. Then I’ll head over to pick Em up from the station at 6pm.

I also need to go register at the new doctors surgery and get my arm looked at again. It’s been over 5 weeks now since I gave blood and the needle messed up my vein and it still feels hardly better.

That is all.

Ps. The auto full-stop thing is really annoying.