SHARE
TWEET

Untitled

SageScroll18144 Apr 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int dir[] = {8,9,10,11};
  2. int sen[] = {A1,13};
  3.  
  4. void setup(){
  5.      for(int i = 0; i  < 4; i++){
  6.         pinMode(dir[i], OUTPUT);
  7.      }
  8.      for(int i = 0; i < 2; i++){
  9.         pinMode(sen[i], INPUT);
  10.      }
  11.      Serial.begin(9600);
  12. }
  13. void loop(){
  14.   Serial.println(digitalRead(sen[0]));
  15.  
  16. }
  17.  
  18.  
  19. ===========================================
  20.  
  21.  
  22. int dir[] = {8,9,10,11};
  23. int sen[] = {A1,A0};
  24.  
  25. void setup(){
  26.      for(int i = 0; i  < 4; i++){
  27.         pinMode(dir[i], OUTPUT);
  28.      }
  29.      for(int i = 0; i < 2; i++){
  30.         pinMode(sen[i], INPUT);
  31.      }
  32.      Serial.begin(9600);
  33. }
  34. void loop(){
  35.   Serial.print(digitalRead(sen[0]));
  36.   Serial.print("\t");
  37.   Serial.println(digitalRead(sen[1]));
  38.   if(digitalRead(sen[0]) == 0 && digitalRead(sen[1]) == 0){
  39.     motors(0,'F');
  40.     motors(1,'F');
  41.   }
  42.   else if(digitalRead(sen[0]) == 0 && digitalRead(sen[0]) == 1){
  43.     motors(0,'F');
  44.     motors(1,'B');
  45.   }
  46.   else if(digitalRead(sen[0]) == 1 && digitalRead(sen[0]) == 0){
  47.     motors(0,'B');
  48.     motors(1,'F');
  49.   }
  50. }
  51.  
  52. void motors(int motor, char sen){
  53.   if(sen == 'F'){
  54.     digitalWrite(dir[motor*2], HIGH);
  55.     digitalWrite(dir[(motor*2)+1], LOW);  
  56.   }
  57.   else if(sen == 'B'){
  58.     digitalWrite(dir[motor*2], LOW);
  59.     digitalWrite(dir[(motor*2)+1], HIGH);
  60.   }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top