master
Paris_Lizaj 5 years ago
parent
commit
60b97e4717
  1. 32
      Home.md

32
Home.md

@ -1,6 +1,5 @@
//KWDIKAS AUTONOMOU AMAKSIOU //KWDIKAS AUTONOMOU AMAKSIOU
```
#include <Servo.h> // Includes servo library. #include <Servo.h> // Includes servo library.
// defines pins numbers // defines pins numbers
const int trigPin = 12; const int trigPin = 12;
@ -12,7 +11,9 @@ const int rm2=4;
const int servoPin=13; const int servoPin=13;
Servo myservo; Servo myservo;
```
```
// orizw katholikes metavlites gia na tis peirazw apo tis sunartiseis kai na boroun na allazoun kai timh // orizw katholikes metavlites gia na tis peirazw apo tis sunartiseis kai na boroun na allazoun kai timh
long duration; long duration;
int distance; int distance;
@ -20,7 +21,10 @@ int distance_f; //apostash tou amaksiou apo antikeimeno eutheia
int distance_r; //apostash tou amaksiou apo antikeimeno deksia int distance_r; //apostash tou amaksiou apo antikeimeno deksia
int distance_l; //apostash tou amaksiou apo antikeimeno aristera int distance_l; //apostash tou amaksiou apo antikeimeno aristera
int maxLowDistance=20; //elaxisth apostash sthn opia ama vrethw stamataw int maxLowDistance=20; //elaxisth apostash sthn opia ama vrethw stamataw
```
```
void setup() { void setup() {
pinMode(trigPin, OUTPUT); pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); pinMode(echoPin, INPUT);
@ -35,6 +39,11 @@ myservo.write(90);
Serial.begin(9600); // Starts the serial communication Serial.begin(9600); // Starts the serial communication
} }
```
```
****void loop() { ****void loop() {
distance_f=ping(); //Psaxnw gia thn apostash pou exw brosta mou distance_f=ping(); //Psaxnw gia thn apostash pou exw brosta mou
if(distance_f > maxLowDistance){ //An einai megaluteri apo 20cm h apostash tou amaksiou apo to prwto ebodio (diladi thn elaxisth apostash pou tou exw orisei) tote tha paei eutheia if(distance_f > maxLowDistance){ //An einai megaluteri apo 20cm h apostash tou amaksiou apo to prwto ebodio (diladi thn elaxisth apostash pou tou exw orisei) tote tha paei eutheia
@ -60,9 +69,10 @@ Serial.begin(9600); // Starts the serial communication
} }
} }
```
```
//thn exw gia debug ayth thn sunartisi gia na dw an leitourgei o esthitiras swsta kai an katagrafontai oi times gia tis apostaseis eutheia deksia kai aristera //thn exw gia debug ayth thn sunartisi gia na dw an leitourgei o esthitiras swsta kai an katagrafontai oi times gia tis apostaseis eutheia deksia kai aristera
void displayDistance(){ void displayDistance(){
Serial.print("Right Distance : "); Serial.print("Right Distance : ");
@ -76,12 +86,16 @@ void displayDistance(){
Serial.println(""); Serial.println("");
} }
```
```
//Logo tou oloklirwmenou LM298 borw na diaxiristw kai pio eukola to amaksaki mou //Logo tou oloklirwmenou LM298 borw na diaxiristw kai pio eukola to amaksaki mou
//exw ftiaksei 5 sunartiseis gia na boreis na pigainei brosta pisw aristera deksia kai na stamataei //exw ftiaksei 5 sunartiseis gia na boreis na pigainei brosta pisw aristera deksia kai na stamataei
//shnarthsh gia na pigenei brosta to amaksi //shnarthsh gia na pigenei brosta to amaksi
****void front(){ ***void front(){
Serial.println("Forward Move"); //vazw se leitourgeia kai tous 4 troxous Serial.println("Forward Move"); //vazw se leitourgeia kai tous 4 troxous
digitalWrite(lm2,HIGH); digitalWrite(lm2,HIGH);
digitalWrite(rm2,HIGH); digitalWrite(rm2,HIGH);
@ -126,6 +140,9 @@ digitalWrite(rm1,LOW);
digitalWrite(rm1,LOW); digitalWrite(rm1,LOW);
digitalWrite(rm2,LOW); digitalWrite(rm2,LOW);
} }
```
```
****void get_Distance(){ ****void get_Distance(){
myservo.write(0); //gurnaw to servo mou deksia gia na boresei na parei metrisi o aisthitiras myservo.write(0); //gurnaw to servo mou deksia gia na boresei na parei metrisi o aisthitiras
@ -157,6 +174,10 @@ digitalWrite(rm1,LOW);
myservo.write(90); myservo.write(90);
} }
```
```
//thn xrisimopoiw gia na parw tis metriseis tou aisthitira kai na kanw thn katalili metatropi. //thn xrisimopoiw gia na parw tis metriseis tou aisthitira kai na kanw thn katalili metatropi.
****int ping(){ ****int ping(){
// Clears the trigPin // Clears the trigPin
@ -172,4 +193,5 @@ digitalWrite(rm1,LOW);
distance= duration*0.034/2; distance= duration*0.034/2;
// Prints the distance on the Serial Monitor // Prints the distance on the Serial Monitor
return distance; return distance;
} }
```
Loading…
Cancel
Save