1.listing Program Ardino (Pitct Terbang Keatas)
1.listing Program Ardino (Pitct Terbang Keatas)
1.listing Program Ardino (Pitct Terbang Keatas)
#include <Wire.h>
#include <Servo.h>
Servo right_prop;
Servo left_prop;
Servo back_prop;
Servo front_prop;
float Acceleration_angle[2];
float Gyro_angle[2];
float Total_angle[2];
float elapsedTime, time, timePrev;
int i;
float pid_p = 0;
float pid_i = 0;
float pid_d = 0;
/////////////////PID CONSTANTS/////////////////
double kp = 0;
double ki = 0;
double kd = 0;
void setup() {
Wire.beginTransmission(0x68);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
right_prop.writeMicroseconds(1000);
left_prop.writeMicroseconds(1000);
back_prop.writeMicroseconds(1000);
front_prop.writeMicroseconds(1000);
delay(7000);
void loop() {
timePrev = time; // the previous time is stored before the actual time read
Wire.beginTransmission(0x68);
Wire.endTransmission(false);
Wire.requestFrom(0x68, 6, true);
Wire.beginTransmission(0x68);
Wire.endTransmission(false);
Serial.print("sudut = ");
Serial.println(Total_angle[1]);
//Serial.println(pwmRight);
//Serial.println(pwmLeft);
//Serial.println(pwmBack);
//Serial.println(pwmFront);
pid_p = kp * error;
PID = -1000;
PID = 1000;
///MOTOR 1
pwmRight = 1200;
pwmRight = 1200;
///MOTOE 2
pwmLeft = 1380;
pwmLeft = 1380;
///MOTO 3
pwmback = 1580;
pwmback = 1580;
}
///MOTOR 4
pwmfront = 1100;
pwmfront = 1100;
right_prop.writeMicroseconds(pwmRight);
left_prop.writeMicroseconds(pwmLeft);
back_prop.writeMicroseconds(pwmback);
front_prop.writeMicroseconds(pwmfront);