Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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