tockn / MPU6050_tockn

Arduino library for easy communication with MPU6050
226 stars 89 forks source link

Suggestion to sleep function of MPU6050 #17

Open cedricwritescode opened 5 years ago

cedricwritescode commented 5 years ago

I've written a function for the library that reduces current need. It sets the MPU6050 in low power/sleep mode and disables the sensors. You have still access to the registers.

void MPU6050::sleep(bool sleep) { byte b = readMPU6050(0x6B); bitWrite(b, 6, sleep); writeMPU6050(0x6B, b);

b = readMPU6050(0x6C);
for(uint8_t i = 0; i < 6; i ++)
{
    bitWrite(b, i, sleep);
}
writeMPU6050(0x6C, b);

}