Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int servoPin = 2;
- int servoPin2 = 8;
- int minPulse = 600;
- int maxPulse = 2400;
- int turnRate = 30;
- int refreshTime = 60;
- int pulseWidth;
- int pulseWidth2;
- int moveServo;
- long lastPulse = 0;
- long lastPulse2 = 0;
- void setup() {
- pinMode(servoPin, OUTPUT);
- pinMode(servoPin2,OUTPUT);
- Serial.begin(9600);
- Serial.println("Welcome to W3bc4m P4n-Tilt ");
- Serial.println("Initializing...");
- Serial.println();
- }
- void loop() {
- if (Serial.available() > 0) {
- moveServo = Serial.read();
- if (moveServo == 50) {
- pulseWidth = pulseWidth - turnRate;
- if (millis() - lastPulse >= refreshTime) {
- digitalWrite(servoPin, HIGH);
- delayMicroseconds(pulseWidth);
- digitalWrite(servoPin,LOW);
- }
- lastPulse = millis();
- }
- if (moveServo == 51) {
- pulseWidth = pulseWidth + turnRate;
- if (millis() - lastPulse >= refreshTime) {
- digitalWrite(servoPin, HIGH);
- delayMicroseconds(pulseWidth);
- digitalWrite(servoPin,LOW);
- }
- lastPulse = millis();
- }
- if (moveServo == 52){
- pulseWidth2 = pulseWidth2 - turnRate;
- if (millis() - lastPulse2 >= refreshTime) {
- digitalWrite(servoPin2, HIGH);
- delayMicroseconds(pulseWidth2);
- digitalWrite(servoPin2,LOW);
- }
- lastPulse2 = millis();
- }
- if (moveServo == 53){
- pulseWidth2 = pulseWidth2 + turnRate;
- if (millis() - lastPulse2 >= refreshTime) {
- digitalWrite(servoPin2, HIGH);
- delayMicroseconds(pulseWidth2);
- digitalWrite(servoPin2,LOW);
- }
- lastPulse2 = millis();
- }
- if (pulseWidth > maxPulse) {
- pulseWidth = maxPulse;
- if (millis() - lastPulse >= refreshTime){
- digitalWrite(servoPin, HIGH);
- delayMicroseconds(pulseWidth);
- digitalWrite(servoPin,LOW);
- }
- lastPulse = millis();
- }
- if (pulseWidth < minPulse) {
- pulseWidth = minPulse;
- if (millis() - lastPulse >= refreshTime){
- digitalWrite(servoPin, HIGH);
- delayMicroseconds(pulseWidth);
- digitalWrite(servoPin,LOW);
- }
- lastPulse = millis();
- }
- if (pulseWidth2 > maxPulse) {
- pulseWidth2 = maxPulse;
- if (millis() - lastPulse2 >= refreshTime){
- digitalWrite(servoPin2, HIGH);
- delayMicroseconds(pulseWidth2);
- digitalWrite(servoPin2,LOW);
- }
- lastPulse2 = millis();
- }
- if (pulseWidth2 < minPulse) {
- pulseWidth2 = minPulse;
- if (millis() - lastPulse2 >= refreshTime){
- digitalWrite(servoPin2, HIGH);
- delayMicroseconds(pulseWidth2);
- digitalWrite(servoPin2,LOW);
- }
- lastPulse2 = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement