Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AFMotor.h>
- #include <Servo.h>
- #include <Wire.h>
- AF_DCMotor motor1 (1, MOTOR12_64KHZ);
- AF_DCMotor motor2(2, MOTOR12_64KHZ); // připojení DC motoru na konektor M2 64KHz pwm
- Servo myservo;
- char command; // proměnná pro ukládání dat z Bluetooth modulu
- int val = 90;
- int pos = 10;
- void setup()
- {
- Serial.begin(9600); // set up Serial library at 9600 bps
- motor1.setSpeed(250);
- motor2.setSpeed(255);
- myservo.attach(9);
- myservo.write(90);
- //}
- //void loop() {
- // put your main code here, to run repeatedly:
- // if(Serial.availiable()) //Pokud je k dispozici sériový monitor, pokračuje smyčka mezi {a}
- //intstate=Serial.parseInt(); //nastaví „state“ na číslo, které bylo odesláno na sériový monitor
- //servo1.write(val);
- while (!Serial);
- Serial.println("-------------------------");
- Serial.println("ARos is loading....");
- delay(1000);
- Serial.println("ARos loaded succesfully");
- Serial.println("-------------------------");
- myservo.attach(9);
- Serial.println("calibrating servo...");
- for(pos = 0; pos <= 180; pos += 1)
- myservo.write(0);
- delay(1000);
- myservo.write(180);
- delay(1000);
- myservo.write(90);
- delay(1000);
- Serial.println("servo calibrated");
- Serial.println("-------------------------");
- Serial.println("Comand input online, write command to perform action");
- Serial.println("-------------------------");
- }
- void loop() {
- for(pos = 0; pos <= 180; pos += 1)
- if (Serial.available())
- {
- int state = Serial.parseInt();
- if (state < 10)
- {
- Serial.print(">");
- Serial.println(state);
- Serial.println("cannost execute command, too low number");
- }
- if (state >= 10 && state < 170)
- {
- Serial.print(">");
- Serial.println(state);
- Serial.print("turning servo to ");
- Serial.print(state);
- Serial.println(" degrees");
- myservo.write(state);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment