SHARE
TWEET

Untitled

a guest Oct 16th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.    listato originario (o poco modificato!) peraMAZEing Machine
  3.    presentato al VallHACKATHON 2018
  4.  
  5.    autore: Paolo Grosso
  6.  
  7. */
  8.  
  9. #include <Stepper.h>
  10. // Define number of steps per rotation:
  11. const int stepsPerRevolution = 513;
  12.  
  13. // Wiring:
  14. // Pin 8 to IN1 on the ULN2003 driver
  15. // Pin 9 to IN2 on the ULN2003 driver
  16. // Pin 10 to IN3 on the ULN2003 driver
  17. // Pin 11 to IN4 on the ULN2003 driver
  18.  
  19. const int  STATE = 13;
  20. int passi=2;
  21.  
  22. Stepper motoreDx = Stepper(stepsPerRevolution, 1, 2, 3, 4);
  23. Stepper motoreSx = Stepper(stepsPerRevolution, 5, 6, 7, 8);
  24.  
  25. void setup() {
  26.   pinMode(A5, INPUT_PULLUP); //pins pulsanti da Sinistra a Destra
  27.   pinMode(A4, INPUT_PULLUP);
  28.   pinMode(A3, INPUT_PULLUP);
  29.   pinMode(A2, INPUT_PULLUP);
  30.   pinMode(13, INPUT);
  31.   pinMode(9, OUTPUT); // LED
  32.   pinMode(10, OUTPUT);// LED
  33.   pinMode(11, OUTPUT);// LED
  34.   pinMode(12, OUTPUT);// LED
  35.   digitalWrite(9, LOW);
  36.   digitalWrite(10, LOW);
  37.   digitalWrite(11, LOW);
  38.   digitalWrite(12, LOW);
  39.  
  40.   motoreDx.setSpeed(20);
  41.   motoreSx.setSpeed(20);
  42.  
  43.   Serial.begin(9600);
  44. }
  45.  
  46. void loop() {
  47.   if (analogRead(A5) > 500 )  {
  48.     digitalWrite(12, HIGH);
  49.   }
  50.   else   {
  51.     digitalWrite(12, LOW);
  52.   }
  53.  
  54.   if (analogRead(A4) > 500 )  {
  55.     digitalWrite(11, HIGH);
  56.   }
  57.   else  {
  58.     digitalWrite(11, LOW);
  59.   }
  60.  
  61.   if (analogRead(A3) > 500 )  {
  62.     digitalWrite(10, HIGH);
  63.   }
  64.   else  {
  65.     digitalWrite(10, LOW);
  66.   }
  67.  
  68.   if (analogRead(A2) > 500 )  {
  69.     digitalWrite(9, HIGH);
  70.   }
  71.   else  {
  72.     digitalWrite(9, LOW);
  73.   }
  74.  
  75.  
  76.   //MOTORE SINISTRO
  77.   if ((analogRead(A5) > 500 ) && (analogRead(A4) < 100))  //muovi i motori solo se i pulsanti sono prenuti singolarmente
  78.   {
  79.     motoreSx.step(passi);
  80.     delay(50);
  81.   }
  82.  
  83.   if ((analogRead(A4) > 500 ) && (analogRead(A5) < 100))
  84.   {
  85.     motoreSx.step(-passi);
  86.     delay(50);
  87.   }
  88.  
  89.   //----------------------------------------------------------------------------------------------
  90.  
  91.   //MOTORE DESTRO
  92.  
  93.   if ((analogRead(A3) > 500 ) && (analogRead(A2) < 100))  //muovi i motori solo se i pulsanti sono prenuti singolarmente
  94.   {
  95.     motoreDx.step(passi);
  96.     delay(50);
  97.   }
  98.  
  99.   if ((analogRead(A2) > 500 ) && (analogRead(A3) < 100))
  100.   {
  101.     motoreDx.step(-passi);
  102.     delay(50);
  103.   }
  104.  
  105.   //----------------------------------------------------------------------------------------------
  106.  
  107.   //CONDIZIONE DI VITTORIA O SCONFITTA
  108.   Serial.println(digitalRead(STATE));
  109.   if (digitalRead(STATE) == 0) //sensore di vittoria
  110.   {
  111.     digitalWrite (9, HIGH);
  112.     digitalWrite (10, HIGH);
  113.     digitalWrite (11, HIGH);
  114.     digitalWrite (12, HIGH);
  115.     delay(2000);
  116.     digitalWrite (9, LOW);
  117.     digitalWrite (10, LOW);
  118.     digitalWrite (11, LOW);
  119.     digitalWrite (12, LOW);
  120.   }
  121. }
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