Arduino LED Matrix Control Part II

IMG_0105
IMG_0106
IMG_0108
IMG_0107

With the Arduino app you can control a led matrix over wifi on your iphone.

Later you can save your “icon” and load older ones.

Sourcecode is still a bit clunky. But it Works :)

- (void)drawRect:(CGRect)rect {
 
	CGContextRef context = UIGraphicsGetCurrentContext();
	if(isOn) {
		[color setFill];
	} else {
		[[UIColor grayColor] setFill];
	}
 
	CGContextSetLineWidth(context, 1.0);
 
	CGContextAddEllipseInRect(context, rect);
	CGContextDrawPath(context, kCGPathFillStroke);
}

Download Sourcecode

Arduino LED Matrix Controlling by iPhone

IMG_0099IMG_0100Today i ported the mac ArduinoControll app to my iPhone.

+ now you can controll the LED via the UIAccelerometer

#pragma mark UIAccelerometer delegate
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
 
	double xAcceleration = 100.0 - (acceleration.x + 1.0) * 100.0;
	double yAcceleration = 100.0 - (acceleration.y + 1.0) * 100.0;
	double zAcceleration = 100.0 - (acceleration.z + 1.0) * 100.0;
 
	accelerationX.text = [[NSString alloc] initWithFormat:@"%4.1f%", xAcceleration];
	accelerationY.text = [[NSString alloc] initWithFormat:@"%4.1f%", yAcceleration];
	accelerationZ.text = [[NSString alloc] initWithFormat:@"%4.1f%", zAcceleration];
 
 
	long xValue = map(xAcceleration, -100, 100, 0, 7);
	long yValue = map(yAcceleration, -100, 100, 0, 7);
 
	[positionX setValue:xValue];
	[positionY setValue:yValue];
 
	NSString *command = [NSString stringWithFormat:@"SET LED %d:%d:%d", (int)xValue, (int)yValue, (int)[color value]];
	[socket sendData:command];
 
}

Sourcecode of Arduino Controlling with iPhone

Arduino + Wishield + LED Matrix = a lot of fun!

socketapp.c

extern char buffer[20];
static int handle_connection(struct socket_app_state *s)
{
 
  PSOCK_BEGIN(&s->p);
  PSOCK_READTO(&s->p, '\n');
  memcpy(buffer,s->inputbuffer,20);
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_END(&s->p);
}

main

void loop() {
  WiFi.run();
  if(strncmp(buffer, "SET LED", 7) == 0) {
 
    substr(positionX, buffer, 8,1);
    substr(positionY, buffer, 10,1);
    substr(color, buffer, 12,3);
    matrix.set(atoi(positionX),atoi(positionY), atoi(color));
    matrix.send();
}

Sending to the socket server (Cocoa, NSStream)

-(void)sendData:(NSString *)string {
 
	NSString *stringWithEnding = [NSString stringWithFormat:@"%@\n", string];
	const uint8_t * rawstring = (const uint8_t *)[stringWithEnding UTF8String];
	[oStream write:rawstring maxLength:strlen(rawstring)];
 
}

Bildschirmfoto 2009-10-21 um 21.58.01

Sourcecode of the Arduino Socket Server

Sourcecode of the Cocoa Socket Client

Sourcecode of ’simple’ pong

led matrix protocol:

SET LED x:y:color

everpixx Kennenlern-Gutschein: 10 % auf Fotokalender

Kennenlern-Gutschein

10% Gutschein für alle Fotokalender

  1. Laden Sie die kostenlose Gestaltungssoftware hier herunter.
  2. Gestalten Sie Ihren individuellen Fotokalender
  3. Bei der Bestellung tragen Sie folgenden Gutschein-Code* ein:

    TIKILINECO

  4. Ihr Fotokalender wird Ihnen bequem nach Hause geliefert.

*Dieser Gutschein ist gültig für Neukunden, bis zum 30.11.2009 auf alle Fotokalender-Bestellungen.

Wasser auf dem Mars!