#include <Wire.h>
#include <MPU6050.h>
#include <LiquidCrystal_I2C.h>
MPU6050 mpu;
LiquidCrystal_I2C(0x27, 16, 2); // Адрес I2C для LCD
volatile int stepCount = 0;
volatile float caloriesBurned = 0.0;
int button1Pin = 2; // Кнопка для обнуления
int button2Pin = 3; // Кнопка для переключения данных
bool displayCalories = false;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
lcd.begin();
lcd.backlight();
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button1Pin), resetValues, FALLING);
attachInterrupt(digitalPinToInterrupt(button2Pin), toggleDisplay, FALLING);
}
void loop() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
// Определяем шаги по изменению ускорения (это упрощенная логика)
if (ay > 10000) { // Пороговое значение для определения шага
stepCount++;
caloriesBurned += 0.05; // Примерное количество калорий за шаг
delay(300); // Задержка для предотвращения многократного счёта одного шага
}
// Обновляем дисплей
lcd.clear();
if (displayCalories) {
lcd.print("Calories: ");
lcd.print(caloriesBurned);
} else {
lcd.print("Steps: ");
lcd.print(stepCount);
}
delay(100); // Задержка для обновления дисплея
}
void resetValues() {
stepCount = 0;
caloriesBurned = 0.0;
}
void toggleDisplay() {
displayCalories = !displayCalories;
}