#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
//#include "ThingSpeak.h"
int led=1;
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy , gz;
struct MyData{
byte X;
byte Y;
};
MyData data;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
mpu.initialize();
pinMode(6, OUTPUT);
Serial.println("Hello, ESP32-C3!");
}
void loop() {
mpu.getMotion6(&ax,&ay,&az,&gx,&gy,&gz);
data.X=map(ax,-17000,17000,0,255);
data.Y=map(ay,-17000,17000,0,255);
delay(1000);
Serial.print("axis x= ");
Serial.print(data.X);
Serial.println();
Serial.print("Axis y = ");
Serial.print(data.Y);
if(led!=0){
digitalWrite(6, HIGH);
}
else{
digitalWrite(6, LOW);
}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}