Gyro
This commit is contained in:
parent
7292715015
commit
3c0b12d1c4
|
|
@ -0,0 +1,23 @@
|
|||
#include"MeMCore.h"
|
||||
#include <Wire.h>
|
||||
MeGyro gyro;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
gyro.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
gyro.update();
|
||||
Serial.read();
|
||||
Serial.print("X:");
|
||||
Serial.print(gyro.getAngleX() );
|
||||
Serial.print(" Y:");
|
||||
Serial.print(gyro.getAngleY() );
|
||||
Serial.print(" Z:");
|
||||
Serial.println(gyro.getAngleZ() );
|
||||
Serial.println(gyro.getGyroY());
|
||||
delay(10);
|
||||
}
|
||||
|
|
@ -1,9 +1,27 @@
|
|||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
#include "MeMCore.h"
|
||||
|
||||
MeDCMotor motor1(9);
|
||||
|
||||
MeDCMotor motor2(10);
|
||||
|
||||
MeUltrasonicSensor ultraSensor(PORT_3);
|
||||
|
||||
int minDistance = 15;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
if (ultraSensor.distanceCm()<minDistance){
|
||||
motor1.run(100);
|
||||
motor2.run(100);
|
||||
delay(800);
|
||||
}
|
||||
else {
|
||||
motor1.run(-155);
|
||||
motor2.run(155);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue