Created
January 27, 2014 20:46
-
-
Save GabLeRoux/8656981 to your computer and use it in GitHub Desktop.
Fun with with processing :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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