DANDUINO

An Arduino resource by evangelist Dan Plows

Android controlled papercraft head [Code+Video]

(0 comments)

Controlling my papercraft head over bluetooth with a custom Android app connected to an Arduino and a servo.

Code:
#include <SoftwareSerial.h>
#include <MeetAndroid.h>
#include <Servo.h>

Servo spin; // horizontal
//Servo tilt; // vertical
int spinPos = 0;
//int tiltPos = 0;

// TX = digital pin 2, RX = digital pin 3
SoftwareSerial portOne(2, 3);
MeetAndroid meetAndroid;

void setup()
{
Serial.begin(57600);
spin.attach(9);
//tilt.attach(10);
// Start the software serial port
portOne.begin(57600);
portOne.listen();
// sync with android app
/*meetAndroid.registerFunction(stringValue, '^'); // keyboard
meetAndroid.registerFunction(stringValue, '`'); // backspace*/
meetAndroid.registerFunction(stringValue, '~'); // mouse
}

void loop()
{
// while there is data coming in...
while (portOne.available() > 0) {
// read value of character
char c = portOne.read();
Serial.print(c);
Serial.println();
if(c == 'L' && spinPos > 0){
spinPos -= 10;
spin.write(spinPos);
}
else if(c == 'R' && spinPos < 180){
spinPos += 10;
spin.write(spinPos);
}
/*else if(c == 'U' && tiltPos > 0){
tiltPos -= 10;
tilt.write(tiltPos);
}
else if(c == 'D' && tiltPos < 180){
tiltPos += 10;
tilt.write(tiltPos);
}*/
}
}

void stringValue(byte flag, byte numOfValues){}

Written by Dan Plows

April 30th, 2012 at 9:55 pm

Posted in Android

Leave a Reply

You must be logged in to post a comment.