Skip to content

Instantly share code, notes, and snippets.

@GabLeRoux
Created January 27, 2014 20:46
Show Gist options
  • Save GabLeRoux/8656981 to your computer and use it in GitHub Desktop.
Save GabLeRoux/8656981 to your computer and use it in GitHub Desktop.
Fun with with processing :)
#include <Servo.h>
#include <ServoTimers.h>
int sensorSpeedValue;
int sensorDirectionValue;
int motorSpeedValue;
int servoValue;
Servo zeServo;
Servo zeOhterServo;
int potarSpeedPin = 0;
int potarDirectionPin = 1;
int potarservoPin = 2;
int motorDirectionPin = 7;
int motorSpeedPin = 6;
int servoMotorPin = 5;
int otherServoMotorPin = 4;
void setup()
{
pinMode(motorDirectionPin, OUTPUT);
pinMode(motorSpeedPin, OUTPUT);
pinMode(potarSpeedPin, INPUT);
pinMode(potarDirectionPin, INPUT);
zeServo.attach(servoMotorPin);
zeOhterServo.attach(otherServoMotorPin);
}
void loop()
{
sensorSpeedValue = analogRead(potarSpeedPin);
sensorDirectionValue = analogRead(potarDirectionPin);
servoValue = analogRead(potarservoPin);
// Determine motor direction
if (sensorDirectionValue > 512)
{
digitalWrite(motorDirectionPin, HIGH);
Serial.println("Going left!");
}
else if (sensorDirectionValue <= 512)
{
digitalWrite(motorDirectionPin, LOW);
Serial.println("Going right!");
}
// send motor speed
motorSpeedValue = sensorSpeedValue / 4;
analogWrite(motorSpeedPin, motorSpeedValue);
Serial.print("motor Value "); Serial.println(motorSpeedValue);
zeServo.write(servoValue /5.68);
zeOhterServo.write((1024 - servoValue) /5.68);
delay(15);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment