Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t wire1 = D8;
- uint8_t wire2 = D7;
- uint8_t wire3 = D6;
- uint8_t wire4 = D5;
- int minDelay = 3;
- int seqNumber = 0;
- const uint16_t _delay = 40; /* delay in between two steps. minimum delay more the rotational speed */
- int currentDelay = 0;
- void sequence(bool a, bool b, bool c, bool d){ /* four step sequence to stepper motor */
- digitalWrite(wire1, a);
- digitalWrite(wire2, b);
- digitalWrite(wire3, c);
- digitalWrite(wire4, d);
- delay(currentDelay);
- }
- void setup() {
- pinMode(wire1, OUTPUT); /* set four wires as output */
- pinMode(wire2, OUTPUT);
- pinMode(wire3, OUTPUT);
- pinMode(wire4, OUTPUT);
- Serial.begin(9600);
- }
- int onMegaSpeed = 0;
- void loop() {
- if(seqNumber < 512){
- sequence(HIGH, LOW, LOW, LOW);
- sequence(LOW, HIGH, LOW, LOW);
- sequence(LOW, LOW, HIGH, LOW);
- sequence(LOW, LOW, LOW, HIGH);
- currentDelay = _delay - (seqNumber/2);
- currentDelay = currentDelay > minDelay ? currentDelay : minDelay;
- Serial.println(currentDelay);
- seqNumber++;
- if(currentDelay == minDelay){
- onMegaSpeed++;
- }
- }else if(seqNumber == 512){
- Serial.println("It's not even my final form.");
- seqNumber++;
- }
- }
- /* Rotation in opposite direction */
- /* for(int j = 0; j<12; j++)
- {
- sequence(LOW, LOW, LOW, HIGH);
- sequence(LOW, LOW, HIGH, HIGH);
- sequence(LOW, LOW, HIGH, LOW);
- sequence(LOW, HIGH, HIGH, LOW);
- sequence(LOW, HIGH, LOW, LOW);
- sequence(HIGH, HIGH, LOW, LOW);
- sequence(HIGH, LOW, LOW, LOW);
- sequence(HIGH, LOW, LOW, HIGH);
- }
- sequence(LOW, LOW, LOW, HIGH);*/
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement