const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
const int buttonPin0 = 0;
const int buttonPin1 = 1;
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
int ledPin = A0; // LEDはデジタルピン13に接続
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// initialize the stepper library on pins 8 through 11:
Stepper xStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
{
// set the speed at 60 rpm:
xStepper.setSpeed(60); // initialize the serial port:
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin0, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
pinMode(12, OUTPUT); // sets the digital pin 13 as output
pinMode(13, OUTPUT); // sets the digital pin 13 as output
pinMode(ledPin, OUTPUT); // 出力に設定
}
}
void loop() {
//高さ調整用 下げ
buttonState = digitalRead(buttonPin1);
if (buttonState == LOW) {
digitalWrite(ledPin, LOW); // LEDをオン
digitalWrite(12, HIGH); // sets the digital pin 12 on
digitalWrite(13, HIGH); // sets the digital pin 13 on
for (int i=1; i <= 1; i++){
Serial.println("counterclockwise");
xStepper.step(-10);
}
{
digitalWrite(ledPin, HIGH); // LEDをオフ
digitalWrite(12, LOW); // sets the digital pin 12 off
digitalWrite(13, LOW); // sets the digital pin 13 off
}
Stepper xStepper(stepsPerRevolution, 8, 9, 10, 11);
}
//高さ調整用 上げ
buttonState = digitalRead(buttonPin2);
if (buttonState == LOW) {
digitalWrite(12, HIGH); // sets the digital pin 12 on
digitalWrite(13, HIGH); // sets the digital pin 13 on
digitalWrite(ledPin, LOW); // LEDをオン
for (int i=1; i <= 1; i++){
Serial.println("counterclockwise");
xStepper.step(10);
}
{
digitalWrite(ledPin, HIGH); // LEDをオフ
digitalWrite(12, LOW); // sets the digital pin 12 off
digitalWrite(13, LOW); // sets the digital pin 13 off
}
}
//繰り返し曲げ試験100回
buttonState = digitalRead(buttonPin3);
if (buttonState == LOW) {
digitalWrite(12, HIGH); // sets the digital pin 12 on
digitalWrite(13, HIGH); // sets the digital pin 13 on
digitalWrite(ledPin, LOW); // LEDをオン
delay(500);
xStepper.step(-33);
delay(500);
for (int i=1; i <= 100; i++){
Serial.println("counterclockwise");
xStepper.step(-100);
xStepper.step(100);
}
{
delay(500);
xStepper.step(33);
delay(500);
digitalWrite(ledPin, HIGH); // LEDをオフ
digitalWrite(12, LOW); // sets the digital pin 12 off
digitalWrite(13, LOW); // sets the digital pin 13 off
}
}
//繰り返し曲げ試験1000回
buttonState = digitalRead(buttonPin4);
if (buttonState == LOW) {
digitalWrite(12, HIGH); // sets the digital pin 12 on
digitalWrite(13, HIGH); // sets the digital pin 13 on
digitalWrite(ledPin, LOW); // LEDをオン
delay(500);
xStepper.step(-33);
delay(500);
for (int i=1; i <= 1000; i++){
Serial.println("counterclockwise");
xStepper.step(-100);
xStepper.step(100);
}
{
delay(500);
xStepper.step(33);
delay(500);
digitalWrite(ledPin, HIGH); // LEDをオフ
digitalWrite(12, LOW); // sets the digital pin 12 off
digitalWrite(13, LOW); // sets the digital pin 13 off
}
}
//繰り返し曲げ試験10000回
buttonState = digitalRead(buttonPin5);
if (buttonState == LOW) {
digitalWrite(12, HIGH); // sets the digital pin 12 on
digitalWrite(13, HIGH); // sets the digital pin 13 on
digitalWrite(ledPin, LOW); // LEDをオン
delay(500);
xStepper.step(-33);
delay(500);
for (int i=1; i <= 10000; i++){
Serial.println("counterclockwise");
xStepper.step(-100);
xStepper.step(100);
}
{
delay(500);
xStepper.step(33);
delay(500);
digitalWrite(ledPin, HIGH); // LEDをオフ
digitalWrite(12, LOW); // sets the digital pin 12 off
digitalWrite(13, LOW); // sets the digital pin 13 off
}
}
}