Mikkzle

Mikkzle's brain log

Category Archives: Uncategorized

Arduino torture

I’ve always had this fascination about 80’s and 90’s demo scenes. I’ve had and still have, a hard time finding and understanding some of the code from that time

BUT,

last night I bumped into this cool processing sketch.

Checked some of the other sketches from the creator of the before mentioned sketch, Luis Gonzalez, and found my new favorite demo effect.

So I quickly copy-pasted the code, saw if I could figure out the code.

I couldn’t and proceeded to think.

Out of my brain came this ‘brilliant’ idea of porting it to my Arduino Duemilanove.

And so I did.

Since the Arduino doesn’t have a screen, I had to write a Processing sketch which read the serial port and print it to the screen.

WARNING: This code is slow and badly formatted. Read at own risk.

Arduino part:

int w=255,p,z;
float u,v,x,y,d,r,t;
void setup() {
Serial.begin(9600);
}

void loop() {
for (int j=-1;j<w;j++) {
y=-1+2.0*j/w;
for (int i=-1;i<w;i++) {
x=-1+2.0*i/w;
u=x/y;
v=1/abs(y);
z=int(w*u+p)^int(w*v+p);
t=(z&w)+20*-v;
Serial.println(t);
}
}
p++;
}

Processing part:

import processing.serial.*;
int x,y;

Serial myPort;

void setup() {
size(255,255);
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
}

 

void draw() {
while (myPort.available() > 0) {
String inString = myPort.readStringUntil(int(10));//read buffer until line break
if (inString!=null) {
stroke(float(inString));//convert and set color
point(x,y);
x++;
if (x>width) {
x=0;
y++;
}
if (y>height) y=0;
}
}

It would take the Arduino approximately 11 seconds if it didn’t have to send it over the serial port.

Now, it takes a very long time.

I wonder if it would go faster on the new Arduino Uno?

Advertisements