スイッチを押している間、回転するバージョン
-----
//StepMotor sample
//PinAssign
int ST_X1=2;
int ST_X2=4;
int ST_Y1=3;
int ST_Y2=5;
int ledPin=13;
//PotentionMeter
int Pot=5;
//Switch
int Switch=6;
int dly;
void setup(){
pinMode(ST_X1, OUTPUT);
pinMode(ST_X2, OUTPUT);
pinMode(ST_Y1, OUTPUT);
pinMode(ST_Y2, OUTPUT);
pinMode(ledPin, OUTPUT);
//POT is Default AnalogInput
pinMode(Switch,INPUT);
dly = analogRead(Pot)/4;
}
void loop(){
if(digitalRead(Switch)==1){
digitalWrite(ledPin,HIGH);
digitalWrite(ST_X1, HIGH);
digitalWrite(ST_X2, LOW);
digitalWrite(ST_Y1, LOW);
digitalWrite(ST_Y2, LOW);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ST_X1, HIGH);
digitalWrite(ST_X2, HIGH);
digitalWrite(ST_Y1, LOW);
digitalWrite(ST_Y2, LOW);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ST_X1, LOW);
digitalWrite(ST_X2, HIGH);
digitalWrite(ST_Y1, LOW);
digitalWrite(ST_Y2, LOW);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ledPin,LOW);
digitalWrite(ST_X1, LOW);
digitalWrite(ST_X2, HIGH);
digitalWrite(ST_Y1, HIGH);
digitalWrite(ST_Y2, LOW);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ST_X1, LOW);
digitalWrite(ST_X2, LOW);
digitalWrite(ST_Y1, HIGH);
digitalWrite(ST_Y2, LOW);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ST_X1, LOW);
digitalWrite(ST_X2, LOW);
digitalWrite(ST_Y1, HIGH);
digitalWrite(ST_Y2, HIGH);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ST_X1, LOW);
digitalWrite(ST_X2, LOW);
digitalWrite(ST_Y1, LOW);
digitalWrite(ST_Y2, HIGH);
dly = analogRead(Pot)/4;
delay(dly);
digitalWrite(ST_X1, HIGH);
digitalWrite(ST_X2, LOW);
digitalWrite(ST_Y1, LOW);
digitalWrite(ST_Y2, HIGH);
dly = analogRead(Pot)/4;
delay(dly);
}
else{
digitalWrite(ST_X1, LOW);
digitalWrite(ST_X2, LOW);
digitalWrite(ST_Y1, LOW);
digitalWrite(ST_Y2, LOW);
}
}