// rotate // sequence 1 2 3 4 5 6 7 8 // 5:Red G G G G G G G G // // 4:Orange H H - - - - - H // 3:Yellow - H H H - - - - // 2:Pink - - - H H H - - // 1:Blue - - - - - H H H #define IN1_PIN 5 //IN1-OUT1-4 Orange #define IN2_PIN 4 //IN2-OUT2-3 Yellow #define IN3_PIN 3 //IN3-OUT3-2 Pink #define IN4_PIN 2 //IN4-OUT4-1 Blue void setup() { pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); pinMode(IN3_PIN, OUTPUT); pinMode(IN4_PIN, OUTPUT); digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, LOW); digitalWrite(IN4_PIN, LOW); } void loop() { for(int n = 0; n < 7; n++) { //正回転(時計回り) motorOutput(n); delay(5); //5ms } } void motorOutput(int sequence) { switch(sequence) { case 0: digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, LOW); digitalWrite(IN4_PIN, LOW); break; case 1: digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, HIGH); digitalWrite(IN3_PIN, LOW); digitalWrite(IN4_PIN, LOW); break; case 2: digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH); digitalWrite(IN3_PIN, LOW); digitalWrite(IN4_PIN, LOW); break; case 3: digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, HIGH); digitalWrite(IN3_PIN, HIGH); digitalWrite(IN4_PIN, LOW); break; case 4: digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, HIGH); digitalWrite(IN4_PIN, LOW); break; case 5: digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, HIGH); digitalWrite(IN4_PIN, HIGH); break; case 6: digitalWrite(IN1_PIN, LOW); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, LOW); digitalWrite(IN4_PIN, HIGH); break; case 7: digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, LOW); digitalWrite(IN4_PIN, HIGH); break; } }