Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. int pin[8]={2,3,4,5,6,7,8};
  2. int steps[][4] =
  3. {
  4. {HIGH,HIGH,LOW,LOW},
  5. {HIGH,LOW,LOW,HIGH},
  6. {LOW,LOW,HIGH,HIGH},
  7. {LOW,HIGH,HIGH,LOW},
  8. } ;
  9. int current=1;
  10. int type=3;
  11. int place=0;
  12.  
  13. int lastLockState = LOW;
  14. long lastLockTime = 0;
  15. int LockState;
  16. int Lockreading;
  17. bool lock=true;
  18.  
  19. int lastReturnState = LOW;
  20. long lastReturnTime = 0;
  21. int ReturnState;
  22. int Returnreading;
  23.  
  24. void setup() {
  25. for (int num=0; num<5; num++) pinMode(pin[num],OUTPUT);
  26. for (int num=5; num<7; num++) pinMode(pin[num],INPUT);
  27. }
  28.  
  29. void reset(){
  30. for(int num=0;num<4;num++) digitalWrite(pin[num],LOW);
  31. }
  32.  
  33. void stepper()
  34. {
  35. for (int num=0; num<4;num++) { digitalWrite(pin[num],steps[abs(type-current)][num]);} if(type==0) {++place;} if(type==3) {--place;} delay(2); } void button1() { Lockreading = digitalRead(pin[5]); if (Lockreading != lastLockState) { lastLockTime = millis(); } if ((millis() - lastLockTime) > 50)
  36. {
  37. if (Lockreading != LockState) {
  38. LockState = Lockreading;
  39. if (LockState == HIGH) {
  40. lock=false;
  41. if ((place!=1024*4)&&(place!=512*4)) {type=abs(type-3);}
  42. }
  43. }
  44. }
  45. lastLockState = Lockreading;
  46. }
  47.  
  48. void button2()
  49. {
  50. Returnreading = digitalRead(pin[6]);
  51. if (Returnreading != lastReturnState)
  52. {
  53. lastReturnTime = millis();
  54. }
  55. if ((millis() - lastReturnTime) > 50)
  56. {
  57. if (Returnreading != ReturnState) {
  58. ReturnState = Returnreading;
  59. if (ReturnState == HIGH) {
  60. type=3;
  61. digitalWrite(pin[4],HIGH);
  62. while (place>0)
  63. {
  64. for (int num=0; num<4;num++) {
  65. digitalWrite(pin[num],steps[3-current][num]);}
  66. --place;
  67. if (current==3) {current=0;}
  68. else ++current;
  69. delay(2);
  70. }
  71. digitalWrite(pin[4],LOW);
  72. reset();
  73. }
  74. }
  75. }
  76. lastReturnState = Returnreading;
  77. }
  78.  
  79. void loop() {
  80. if (lock==true) {button1();button2();}
  81. if (lock==false) {stepper();}
  82. if ((place==2048*4)or(place==0)or(((place==1024*4)or(place==512*4))and(type==3))){lock=true;reset();}
  83. if (current==3) {current=0;}
  84. else ++current;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement