void loop() {
  // Read the 'raw' data in 14-bit counts
  mma.read();
  Serial.print("X:\t"); Serial.print(mma.x); 
  Serial.print("\tY:\t"); Serial.print(mma.y); 
  Serial.print("\tZ:\t"); Serial.print(mma.z); 
  Serial.println();

  /* Get a new sensor event */ 
  sensors_event_t event; 
  mma.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
  Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
  Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
  Serial.println("m/s^2 ");
  
  /* Get the orientation of the sensor */
  uint8_t o = mma.getOrientation();
  
  switch (o) {
    case MMA8451_PL_PUF: 
      Serial.println("Portrait Up Front");
      break;
    case MMA8451_PL_PUB: 
      Serial.println("Portrait Up Back");
      break;    
    case MMA8451_PL_PDF: 
      Serial.println("Portrait Down Front");
      break;
    case MMA8451_PL_PDB: 
      Serial.println("Portrait Down Back");
      break;
    case MMA8451_PL_LRF: 
      Serial.println("Landscape Right Front");
      break;
    case MMA8451_PL_LRB: 
      Serial.println("Landscape Right Back");
      break;
    case MMA8451_PL_LLF: 
      Serial.println("Landscape Left Front");
      break;
    case MMA8451_PL_LLB: 
      Serial.println("Landscape Left Back");
      break;
    }
  Serial.println();
  delay(500);
  
}
예제 #2
0
void loop() {

  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  /*
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  */
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  if (timer > millis())  timer = millis();

  if (millis() - timer > 1000) { 
    timer = millis();
    
    if (1) {//(GPS.fix) {

      Serial.print("(123,");
      Serial.print(GPS.latitudeDegrees, 6);
      Serial.print(", "); 
      Serial.print(GPS.longitudeDegrees, 6);
      Serial.print(",");
      Serial.print(GPS.speed);
      Serial.print(",");
      Serial.print((int)GPS.fixquality); 
      Serial.println(")");
    }
  }

  sensors_event_t event; 
  mma.getEvent(&event);
  Serial.print("(456,");
  Serial.print(event.acceleration.x); Serial.print(",");
  Serial.print(event.acceleration.y); Serial.print(",");
  Serial.print(event.acceleration.z); Serial.print(")");
  Serial.println();
  delay(1000/100);

  /*
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("('ping', ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println(")");
  */

}
예제 #3
0
파일: main.cpp 프로젝트: yjlintw/SerialIMU
void setup()
{
    Serial.begin(9600);
    pinMode(led, OUTPUT);
    if (!mma.begin()) {
        Serial.println("Couldn't start");
        while(1);
    }

    mma.setRange(MMA8451_RANGE_2_G);

    // for (int i = 0; i < 20; i++) {
    //     char numstr[6];
    //     sprintf(numstr, "cmd%d", i);
    //     cmdList.push_back(numstr);
    // }
}
void setup(void) {
  Serial.begin(9600);
  while (!Serial.available()) SPARK_WLAN_Loop(); //wait to connect
  Serial.println("Adafruit MMA8451 test!");
  

  if (! mma.begin()) {
    Serial.println("Couldnt start");
    while (1);
  }
  Serial.println("MMA8451 found!");
  
  mma.setRange(MMA8451_RANGE_2_G);
  
  Serial.print("Range = "); Serial.print(2 << mma.getRange());  
  Serial.println("G");
  
}
예제 #5
0
void setup()  
{
  Serial.begin(9600);
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  useInterrupt(true);

  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);

  //Serial.println("Adafruit MMA8451 test!");
  if (! mma.begin()) {
    //Serial.println("Couldnt start");
    while (1);
  }
  //Serial.println("MMA8451 found!");
  mma.setRange(MMA8451_RANGE_2_G);
  Serial.print("Range = "); Serial.print(2 << mma.getRange());  
  Serial.println("G");
}
예제 #6
0
파일: main.cpp 프로젝트: yjlintw/SerialIMU
void loop()
{
    mma.read();
    serialMQ.Update();
    serialMQ.Send("%s %d", "ax", mma.x);
    serialMQ.Send("%s %d", "ay", mma.y);
    serialMQ.Send("%s %d", "az", mma.z);
    // static int count = 0;
    // for (int i = 0; i < cmdList.size(); i++) {
    //     // to work with the parser, please format string as
    //     // cmd argument
    //     serialMQ.Send("%s %d", cmdList[i].c_str(), count);
    // }
    // // SerialMQ::Submit();
    //
    // if (serialMQ.getValue("led") == "LOW") {
    //     digitalWrite(led, LOW);
    // } else if (serialMQ.getValue("led") == "HIGH") {
    //     digitalWrite(led, HIGH);
    // }
    //
    // count++;
    delay(300);
}