#include <Stepper.h>
long randNumberSMER;
// -------------------------STEPPER MOTOR
int bluePin = 2; //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
int pinkPin = 3; //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
int yellowPin = 4; //IN3 on the ULN2003 Board, YELLOW end of the Blue/Yellow motor coil
int orangePin = 5; //IN4 on the ULN2003 Board, ORANGE end of the Pink/Orange motor coil
//Keeps track of the current step.
int currentStep = 0;
//One circle count
int oneCircleNo;
// =====================
void setup(){
Serial.begin(9600);
// STEPPER MOTOR
pinMode(bluePin, OUTPUT);
pinMode(pinkPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(orangePin,OUTPUT);
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
}
void loop() {
// print a random number from 0 to 299
randNumberSMER = random(100);
Serial.println(randNumberSMER);
if (randNumberSMER > 50){
damperOpen();
}
if (randNumberSMER < 50){
damperClose();
}
delay(1000);
}
void damperOpen(){ // clockwise subroutine 1 turn
int fullcircleSteps = 2048;
Serial.println(fullcircleSteps);
long timeOpen = random(2,10); // chosing the speed
Serial.println(timeOpen);
while (fullcircleSteps > 0){
switch(currentStep){
case 0:
digitalWrite(bluePin, HIGH);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
case 1:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
case 2:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(orangePin, LOW);
break;
case 3:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, HIGH);
break;
}
currentStep = (++currentStep < 4) ? currentStep : 0;
delay(timeOpen);
fullcircleSteps--;
}
}
void damperClose(){ // count clockwise subroutine 1 turn
int fullcircleSteps = 2048;
Serial.println(fullcircleSteps);
long timeClose = random(2,10);// chosing the speed
Serial.println(timeClose);
while (fullcircleSteps > 0){
switch(currentStep){
case 0:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, HIGH);
break;
case 1:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(orangePin, LOW);
break;
case 2:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
case 3:
digitalWrite(bluePin, HIGH);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
}
currentStep = (++currentStep < 4) ? currentStep : 0;
delay(timeClose);
fullcircleSteps--;
}
}
Comments