kilya

Control_Game_With_Arduino

May 20th, 2020
1,895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Abdessalam.AADEL
  2. // Control T.REX Game with Stepper Motor and LDR
  3.  
  4. // include Arduino stepper motor library
  5. #include <Stepper.h>
  6.  
  7. // define number of steps per internal motor revolution
  8. #define STEPS 32
  9.  
  10. // define stepper motor control pins
  11. #define IN1  11
  12. #define IN2  10
  13. #define IN3   9
  14. #define IN4   8
  15.  
  16. // Create Instance of Stepper Class
  17. // Specify Pins used for motor coils
  18. // The pins used are 8,9,10,11
  19. // Connected to ULN2003 Motor Driver In1, In2, In3, In4
  20. // Pins entered in sequence 1-3-2-4 for proper step sequencing
  21. Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
  22.  
  23. int light;
  24.  
  25. void setup()
  26. {
  27.   // Nothing for Stepper Library
  28.   Serial.begin(9600);
  29. }
  30.  
  31. void loop()
  32. {
  33.   light = analogRead(0);
  34.   //Serial.println(light);
  35.  
  36.   stepper.setSpeed(1020);
  37.   if(light > 460)
  38.   {
  39.     stepper.step(200);
  40.     stepper.step(-200);
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment