Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Naped_PP
- #define Naped_PT
- #define Naped_LP
- #define Naped_PT
- #define trigPin
- #define echoPin
- #define vacuum
- void setup() {
- pinMode(Naped_PP, OUTPUT);
- pinMode(Naped_LP, OUTPUT);
- pinMode(Naped_PT, OUTPUT);
- pinMode(Naped_LT, OUTPUT);
- pinMode(trigPin,OUTPUT);
- pinMode(echoPin,INPUT);
- pinMode(vacuum, OUTPUT);
- }
- long distance;
- void loop() {
- digitalWrite(vacuum, HIGH);
- distance = pomiarOdleglosci();
- jazda(distance);
- }
- int pomiarOdleglosci(){
- long duration
- //pomiar odleglosci
- digitalWrite(trigPin,LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin,LOW);
- delayMicroseconds(10);
- digitalWrite(trigPin,LOW);
- //odczyt pomiaru
- duration = pulseIn(echoPin, HIGH);
- return duration/58;
- }
- void jazda( int distance) {
- if(distance < 15){
- digitalWrite(Naped_PP, LOW);
- digitalWrite(Naped_PT, HIGH);
- digitalWrite(Naped_LP, HIGH);
- digitalWrite(Naped_LT, LOW);
- }
- else{
- digitalWrite(Naped_PP, HIGH);
- digitalWrite(Naped_PT, LOW);
- digitalWrite(Naped_LP, HIGH);
- digitalWrite(Naped_LT, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement