Accelerometer data (arduino) processing
in
Contributed Library Questions
•
2 years ago
Hi Everybody!
im trying to create a post on twitter when i receive data from my accelerometer.
everything works great;
my arduino code runs and recognizes my accelerometer.
my processing sketch recognizes my accelerometer, and posts to twitter.
the problem is that because the accelerometer always has output of around 550 i am constantly posting to twitter.
how do i set a limit in processing. can you write if statements in processing the same way you do in arduino? (im newish to arduino and this is my first attempt at using processing) in my arduino sketch i have if xvalue is greater than 600 serial print in "ollie"
this works in arduino but i don't know how to translate it in processing.
Arduino Code
- // 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 communication:
- Serial.begin(9600);
- }
- void loop() {
- if(analogRead(zpin)>600)
- Serial.println("Ollie");
- Serial.println();
- // delay before next reading:
- delay(100);
- }
Processing code (Twitter4j + graph)
- /*
- 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.*;
- import processing.serial.*; //new
- String msg = "Ollie"; //my tweet
- //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;
- Serial myPort; // The serial port
- void setup() {
- size(640,480);
- //new below
- // List all the available serial ports
- println(Serial.list());
- // I know that the first port in the serial list on my mac
- // is always my Arduino, so I open Serial.list()[0].
- // Open whatever port is the one you're using.
- myPort = new Serial(this, Serial.list()[0], 9600);
- // don't generate a serialEvent() unless you get a newline character:
- myPort.bufferUntil('\n');
- //new above
- }
- void draw() {
- background(bgcolor);
- bgcolor = color(255);
- }
- void
- serialEvent (Serial myPort) {
- 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.
1