Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pin[8]={2,3,4,5,6,7,8};
- int steps[][4] =
- {
- {HIGH,HIGH,LOW,LOW},
- {HIGH,LOW,LOW,HIGH},
- {LOW,LOW,HIGH,HIGH},
- {LOW,HIGH,HIGH,LOW},
- } ;
- int current=1;
- int type=3;
- int place=0;
- int lastLockState = LOW;
- long lastLockTime = 0;
- int LockState;
- int Lockreading;
- bool lock=true;
- int lastReturnState = LOW;
- long lastReturnTime = 0;
- int ReturnState;
- int Returnreading;
- void setup() {
- for (int num=0; num<5; num++) pinMode(pin[num],OUTPUT);
- for (int num=5; num<7; num++) pinMode(pin[num],INPUT);
- }
- void reset(){
- for(int num=0;num<4;num++) digitalWrite(pin[num],LOW);
- }
- void stepper()
- {
- 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)
- {
- if (Lockreading != LockState) {
- LockState = Lockreading;
- if (LockState == HIGH) {
- lock=false;
- if ((place!=1024*4)&&(place!=512*4)) {type=abs(type-3);}
- }
- }
- }
- lastLockState = Lockreading;
- }
- void button2()
- {
- Returnreading = digitalRead(pin[6]);
- if (Returnreading != lastReturnState)
- {
- lastReturnTime = millis();
- }
- if ((millis() - lastReturnTime) > 50)
- {
- if (Returnreading != ReturnState) {
- ReturnState = Returnreading;
- if (ReturnState == HIGH) {
- type=3;
- digitalWrite(pin[4],HIGH);
- while (place>0)
- {
- for (int num=0; num<4;num++) {
- digitalWrite(pin[num],steps[3-current][num]);}
- --place;
- if (current==3) {current=0;}
- else ++current;
- delay(2);
- }
- digitalWrite(pin[4],LOW);
- reset();
- }
- }
- }
- lastReturnState = Returnreading;
- }
- void loop() {
- if (lock==true) {button1();button2();}
- if (lock==false) {stepper();}
- if ((place==2048*4)or(place==0)or(((place==1024*4)or(place==512*4))and(type==3))){lock=true;reset();}
- if (current==3) {current=0;}
- else ++current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement