Součástky:
- Arduino Mega 2560
- motor shield l293d
- Gyro+akcelerometr MPU 6050
Kód: Vybrat vše
#include <AFMotor.h>
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
AF_DCMotor motorL(3);
AF_DCMotor motorP(4);
long timer = 0;
float UhelNatoceni;
void setup() {
Wire.begin();
Serial.begin(9600);
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
void loop(){
if(millis() - timer > 50)
{
UhelNatoceni = mpu6050.getAngleZ();
Serial.println(UhelNatoceni);
timer = millis();
mpu6050.update();
}
motorL.setSpeed(80);
motorP.setSpeed(80);
motorL.run(FORWARD);
motorP.run(FORWARD);
}