/*
  Accelerometer reader
  Language: Wiring/Arduino
  Reads 2 axes of an accelerometer and sends the values 
  out the serial port
*/

int accelerometer[2];     // variable to hold the accelerometer values

void setup() {
  // open serial port:
  Serial.begin(9600);
  // send out some initial data:
  Serial.println("0,0,");
}

void loop() {
  // read 2 channels of the accelerometer:
  for (int i = 0; i < 2; i++) {
    accelerometer[i] = analogRead(i);
    // delay to allow analog-to-digital converter to settle:
    delay(10);
  }

  // if there's serial data in , print sensor values out:
  if (Serial.available() > 0) {
    // read incoming data to clear serial input buffer:
    int inByte = Serial.read();
    for (int i = 0; i <  2; i++) {
      // values as ASCII strings:
      Serial.print(accelerometer[i], DEC);
      // print commas in between values:
      Serial.print(",");
    }
    // print \r and \n after values are sent:
    Serial.println();
  }
}

Sorry, the comment form is closed at this time.

   
© 2012 Making Things Talk Suffusion theme by Sayontan Sinha