Skip to main content

get_accelerometer()

Description#

This function gets the accelerometer sensor data, which returns x, y, and z.
It outputs to the UI in Blockly and as a class in Python as a struct in Arduino.

Syntax#

Python: get_accelerometer()
Arduino: getAccelerometer()

Parameters#

None

Returns#

Outputs to visual UI. In code, it returns a class in Python and struct in Arduino.

Example Code#
Python#
#Python code
import CoDrone
drone = CoDrone.CoDrone()
drone.pair()
# print the acceleration of drone
acceleration = drone.get_accelerometer()
print(acceleration.X, acceleration.Y, acceleration.Z)
drone.close()
Arduino#
//Arduino code
//Code for print request data to serial monitor
#include<CoDrone.h> //header
void setup(){
//open serial and connect
CoDrone.begin(115200);
CoDrone.pair(Nearest);
}
void loop(){
// Struct for get accelerometer data
acceldata accel;
CoDrone.Send_LinkModeBroadcast(LinkBroadcast_Active); //link module mode change => Active
accel = CoDrone.getAccelerometer(); //save request data
delay(100);
CoDrone.Send_LinkModeBroadcast(LinkModeMute); //link module mode change => Mute
delay(100);
Serial.println("");
Serial.println("--------- Now -----------");
Serial.print("accel x : \t");
Serial.println(accel.x);
Serial.print("accel y : \t");
Serial.println(accel.y);
Serial.print("accel z : \t");
Serial.println(accel.z);
}