jagomart
digital resources
picture1_Lampiran 2


 148x       Filetype PDF       File size 0.21 MB       Source: eprints.polsri.ac.id


File: Lampiran 2
program arduino int pos 0 int motor1pin1 3 int motor1pin2 4 int enable1pin 6 int motor2pin1 8 int motor2pin2 9 int enable2pin 11 int state int flag 0 int statestop ...

icon picture PDF Filetype PDF | Posted on 31 Jan 2023 | 2 years ago
Partial capture of text on file.
                       PROGRAM ARDUINO 
                               
            
           int pos = 0; 
           int motor1Pin1 = 3; 
           int motor1Pin2 = 4; 
           int enable1Pin = 6; 
           int motor2Pin1 = 8; 
           int motor2Pin2 = 9; 
           int enable2Pin = 11; 
           int state; 
           int flag=0; 
           int stateStop=0; 
           void setup() { 
               // Set Motor DC sebagai output: 
               pinMode(motor1Pin1, OUTPUT); 
               pinMode(motor1Pin2, OUTPUT); 
               pinMode(enable1Pin, OUTPUT); 
               pinMode(motor2Pin1, OUTPUT); 
               pinMode(motor2Pin2, OUTPUT); 
               pinMode(enable2Pin, OUTPUT); 
               // Set Enable pada 2 buah Motor DC 
               digitalWrite(enable1Pin, HIGH); 
               digitalWrite(enable2Pin, HIGH); 
               // inisialisasi komunikasi serial 
               Serial.begin(9600); 
           } 
            
           void loop() { 
               // Jika data diterima, maka dimasukkan ke variabel state 
               if(Serial.available() > 0){      
                 state = Serial.read();    
                 flag=0; 
               }    
               // Jika state = F, maka Motor DC bergerak maju 
               if (state == 'F') { 
                   digitalWrite(motor1Pin1, HIGH); 
                   digitalWrite(motor1Pin2, LOW);  
                   digitalWrite(motor2Pin1, LOW); 
                   digitalWrite(motor2Pin2, HIGH); 
                   if(flag == 0){ 
                     Serial.println("MAJU"); 
                     flag=1; 
                   } 
               } 
               // Jika state = L, maka Motor DC berbelok ke kiri 
               else if (state == 'L') { 
                   digitalWrite(motor1Pin1, HIGH);  
                   digitalWrite(motor1Pin2, LOW);  
                   digitalWrite(motor2Pin1, HIGH); 
                   digitalWrite(motor2Pin2, LOW); 
                   if(flag == 0){ 
                     Serial.println("BELOK KIRI"); 
                     flag=1; 
                   } 
                   delay(350); 
                   state=3; 
                   stateStop=1; 
               } 
               // Jika state = S, maka Motor DC akan berhenti 
               else if (state == 'S' || stateStop == 1) { 
                   digitalWrite(motor1Pin1, LOW);  
                   digitalWrite(motor1Pin2, LOW);  
                   digitalWrite(motor2Pin1, LOW); 
                   digitalWrite(motor2Pin2, LOW); 
                   if(flag == 0){ 
                     Serial.println("BERHENTI DULU"); 
                     flag=1; 
                   } 
                   stateStop=0; 
               } 
               // Jika state = R, maka Motor DC berbelok ke kanan 
               else if (state == 'R') { 
                   digitalWrite(motor1Pin1, LOW);  
                   digitalWrite(motor1Pin2, HIGH);  
                   digitalWrite(motor2Pin1, LOW); 
                   digitalWrite(motor2Pin2, HIGH); 
                   if(flag == 0){ 
                     Serial.println("BELOK KANAN"); 
                     flag=1; 
                   } 
                   delay(350); 
                   state=3; 
                   stateStop=1; 
               } 
               // Jika state = B, maka Motor DC bergerak mundur 
               else if (state == 'B') { 
                   digitalWrite(motor1Pin1, LOW);  
                   digitalWrite(motor1Pin2, HIGH); 
                   digitalWrite(motor2Pin1, HIGH); 
                   digitalWrite(motor2Pin2, LOW); 
                   if(flag == 0){ 
                     Serial.println("MUNDUR"); 
                     flag=1; 
                   } 
               } 
           } 
            
            
The words contained in this file might help you see if this file matches what you are looking for:

...Program arduino int pos motorpin enablepin state flag statestop void setup set motor dc sebagai output pinmode enable pada buah digitalwrite high inisialisasi komunikasi serial begin loop jika data diterima maka dimasukkan ke variabel if available read f bergerak maju low println l berbelok kiri else belok delay s akan berhenti dulu r kanan b mundur...

no reviews yet
Please Login to review.