Hi Everybody!
Im trying to create a wireless device that can tell when a skateboard ollies.
Im using an arduino pro mini with and accelerometer and bluetooth. i have an arduino file that listens to my accelerometer and has a few if statements that create a serial print in when the board/accelerometer move vertically. this is all done wirelessly using blue tooth. works great.
I also have a processing file that creates a twitter post when the mouse is clicked.
What i would like to do is create a twitter post when the board move vertically instead of clicking the mouse.
so, what i think needs to happen is, have the processing file recognize the if statements...?
how do i go about linking or combining these files together?
Here is my arduino code.
/*
ADXL3xx
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from Sparkfun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
created 2 Jul 2008
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
This example code is in the public domain.
*/
// these constants describe the pins. They won't change:
const int groundpin = 2; // analog input pin 2 -- ground
const int powerpin = 4; // analog input pin 4 -- voltage
const int zpin = A2; // z-axis of the accelerometer
const int ypin = A1; // y-axis
const int xpin = A0; // x-axis (only on 3-axis models)
int sensorValue;
void setup()
{
// initialize the serial communications:
Serial.begin(115200);
// Provide ground and power by using the analog inputs as normal
// digital pins. This makes it possible to directly connect the
// breakout board to the Arduino. If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
}
void loop()
{
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
if(analogRead(xpin)<495)
Serial.println("Pop Shove-it");
if(analogRead(ypin)>495)
Serial.println("None");
Serial.print("\t");
Serial.print(analogRead(ypin));
if(analogRead(ypin)<475)
Serial.println("Kickflip");
if(analogRead(ypin)>475)
Serial.println("None");
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
if(analogRead(zpin)>600)
Serial.println("Ollie");
if(analogRead(zpin)<600)
Serial.println("None");
Serial.println();
// delay before next reading:
delay(100);
}
Here is the processing code.
/*
Posts a message to a Twitter account when you press the mouse button.
Uses Twitter4j, http://twitter4j.org.
For more info: http://tinkerlondon.com/now/2010/09/13/oauth-twitter-and-processing/
Daniel Soltis, September 2010
*/
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
String msg = "Ollie";
//copy and paste these from your application in dev.twitter.com
String consumer_key = "cv50u99znWOAOnOEUkhDA";
String consumer_secret = "dzVnD4nLzQd9FAUg47AyEVJKPQgY6ey6dsdOZDsj2FY";
String oauth_token = "276648172-s7m9Z4BPDlREyGJkllFKu84lguDeWkJU4ZKm6Y9E";
String oauth_token_secret = "zKN1i9SGNeh6PDjrEmv8BzeAYrErRac3Mjfs9XjU";
color bgcolor = color(255);
long timer;
void setup() {
size(640,480);
}
void draw() {
background(bgcolor);
if (millis()-timer > 2000) bgcolor = color(255);
}
void mousePressed() {
Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance (
consumer_key, consumer_secret,
new AccessToken( oauth_token, oauth_token_secret) );
try {
Status st = twitter.updateStatus(msg + " " + second());
println("Successfully updated the status to [" + st.getText() + "].");
bgcolor = color(0,0,255);
timer = millis();
}
catch (TwitterException e) {
println(e.getStatusCode());
}
}
Please help, Thanks.