Skip to content

Instantly share code, notes, and snippets.

@StefKors
Created June 26, 2015 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefKors/11e77b654e9b4e6d242f to your computer and use it in GitHub Desktop.
Save StefKors/11e77b654e9b4e6d242f to your computer and use it in GitHub Desktop.
#include <Servo.h>
// fotocel
float photocellPinL = 0; // the cell and 10K pulldown are connected to a0
float photocellPinR = 1; // the cell and 10K pulldown are connected to a0q
float photocellReadingL; // fotocell reading LINKS
float photocellReadingR; // fotocell reading RECHTS
Servo myServo; // Servo Object
int servoPin = 9; // ServoPin Nummer
float pos = 90; // Positie Servo
int a = 40;
//PROCIMITY
#define trigPin 13
#define echoPin 12
void setup() {
Serial.begin (9600); // Serial Port
//SERVO
myServo.attach(servoPin); // welke pin myServo is
//PROXIMITY
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
//PHOTOCELL
photocellReadingL = analogRead(photocellPinL);
photocellReadingR = analogRead(photocellPinR);
//AFSTAND
long duur, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duur = pulseIn(echoPin, HIGH);
distance = (duur / 2) / 29.1;
Serial.println(distance);
if (distance < 70) {
for ( a = 40; a < 3; a++) {
for (pos = 0; pos < 140; pos += 1) {
myServo.write(pos);
delay(2);
}
for (pos = 140; pos >= 1; pos -= 1) {
myServo.write(pos);
delay(2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment