Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
- // Title: Accelrometer readings though 90 degrees
- // Author: Third_meow - 三喵
- // Discription: Redbot takes (and displayes on serial monitor) the accelerometer readings, then turns a small amount and takes(and diplays) accel readings.
- // Redbot repeats this 14 times, ending up at 90 degrees right of the starting point. This program was written to help understand how the accelerometor readings correlate to
- // redbot movment.
- // Date: 16 Febuary 2017
- //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
- #include <RedBot.h>
- RedBotMotors motors;
- RedBotAccel accelerometer;
- const int buzzerPin = 9;
- int loop_amount = 0;
- //sets up the redbot libary, the motors, the accelerometer and the buzzer.
- void setup(void)
- {
- pinMode(buzzerPin, OUTPUT); // configures the buzzerPin as an OUTPUT
- Serial.begin(9600);
- Serial.println("Accelerometer Readings:");
- Serial.println();
- Serial.println("(X, Y, Z) -- [X-Z, Y-Z, X-Y]");
- Serial.println("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-");
- //prints the tilte info about accelerometer to screen
- //**************************************************************************
- accelerometer.read(); // updates the x, y, and z axis readings on the acceleromter
- Serial.print("(");
- Serial.print(accelerometer.x);
- Serial.print(", ");
- Serial.print(accelerometer.y);
- Serial.print(", ");
- Serial.print(accelerometer.z);
- Serial.print(") -- ");
- Serial.print("[");
- Serial.print(accelerometer.angleXZ);
- Serial.print(", ");
- Serial.print(accelerometer.angleYZ);
- Serial.print(", ");
- Serial.print(accelerometer.angleXY);
- Serial.println("]");
- // prints the accerlerometer readings to screen
- Serial.print("INITIAL READING COMPLETE"); //prints INITIAL READING COMPLETE to your screen
- delay(1000); // waits 1000 milliseconds
- Serial.print("TURN STARTING"); //prints TURN STARTING to your screen
- //tone(buzzerPin, 1000); // Creats a buzzing sound
- delay(2000); // waits 2000 milliseconds
- noTone(buzzerPin); //turns off buzzing sound
- // warns you program setup is finished and loop is about to start
- while (loop_amount < 14) { //repeats code below 14 times
- motors.rightMotor(-150);
- motors.leftMotor(-150);
- delay(100);
- motors.brake();
- delay(1000);
- //pivits robot a small amount
- accelerometer.read(); // updates the x, y, and z axis readings on the acceleromter
- Serial.print("(");
- Serial.print(accelerometer.x);
- Serial.print(", ");
- Serial.print(accelerometer.y);
- Serial.print(", ");
- Serial.print(accelerometer.z);
- Serial.print(") -- ");
- Serial.print("[");
- Serial.print(accelerometer.angleXZ);
- Serial.print(", ");
- Serial.print(accelerometer.angleYZ);
- Serial.print(", ");
- Serial.print(accelerometer.angleXY);
- Serial.println("]");
- // prints the accerlerometer readings to screen
- delay(100);
- loop_amount = loop_amount + 1;
- }
- }
- void loop(void) // repeats code below infinely
- {
- // this has been deliberately left blank
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement