Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. uint8_t wire1 = D8;
  2. uint8_t wire2 = D7;
  3. uint8_t wire3 = D6;
  4. uint8_t wire4 = D5;
  5.  
  6. int minDelay = 3;
  7.  
  8.  
  9.  
  10.  
  11. int seqNumber = 0;
  12.  
  13. const uint16_t _delay = 40; /* delay in between two steps. minimum delay more the rotational speed */
  14. int currentDelay = 0;
  15.  
  16. void sequence(bool a, bool b, bool c, bool d){  /* four step sequence to stepper motor */
  17.   digitalWrite(wire1, a);
  18.   digitalWrite(wire2, b);
  19.   digitalWrite(wire3, c);
  20.   digitalWrite(wire4, d);
  21.   delay(currentDelay);
  22. }
  23.  
  24. void setup() {
  25.   pinMode(wire1, OUTPUT); /* set four wires as output */
  26.   pinMode(wire2, OUTPUT);
  27.   pinMode(wire3, OUTPUT);
  28.   pinMode(wire4, OUTPUT);
  29.   Serial.begin(9600);
  30. }
  31.  
  32. int onMegaSpeed = 0;
  33.  
  34. void loop() {
  35.   if(seqNumber < 512){
  36.     sequence(HIGH, LOW, LOW, LOW);
  37.     sequence(LOW, HIGH, LOW, LOW);
  38.     sequence(LOW, LOW, HIGH, LOW);
  39.     sequence(LOW, LOW, LOW, HIGH);
  40.  
  41.     currentDelay = _delay - (seqNumber/2);
  42.     currentDelay = currentDelay > minDelay ? currentDelay : minDelay;
  43.     Serial.println(currentDelay);
  44.    
  45.     seqNumber++;
  46.  
  47.     if(currentDelay == minDelay){
  48.       onMegaSpeed++;
  49.     }
  50.   }else if(seqNumber == 512){
  51.     Serial.println("It's not even my final form.");
  52.     seqNumber++;
  53.   }
  54. }
  55.  
  56.  
  57.  
  58.  
  59.   /* Rotation in opposite direction */
  60. /*  for(int j = 0; j<12; j++)
  61.   {
  62.     sequence(LOW, LOW, LOW, HIGH);
  63.     sequence(LOW, LOW, HIGH, HIGH);
  64.     sequence(LOW, LOW, HIGH, LOW);
  65.     sequence(LOW, HIGH, HIGH, LOW);
  66.     sequence(LOW, HIGH, LOW, LOW);
  67.     sequence(HIGH, HIGH, LOW, LOW);
  68.     sequence(HIGH, LOW, LOW, LOW);
  69.     sequence(HIGH, LOW, LOW, HIGH);
  70.   }
  71.   sequence(LOW, LOW, LOW, HIGH);*/
  72. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement