1
여기
내 코드입니다 :Arduino의 특정 키패드 버튼을 누를 때까지 스테퍼 모터가 실행되게하려면 어떻게해야합니까?
#include <LiquidCrystal.h>
#include <Stepper.h>
#include <Key.h>
#include <Keypad.h>
const int stepsPerRevolution = 200;
const byte ROWS = 4; //four rows
const byte COLS = 1; //one column
char keys[ROWS][COLS] = {
{'-'},
{'+'},
{'I'},
{'0'}};
byte rowPins[ROWS] = {6,7,8,9};
byte colPins[COLS] = {10};
int count = 0;
LiquidCrystal lcd(A5,A4,A3,A2,A1,A0);
Stepper myStepper(stepsPerRevolution, 2,4,3,5);
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int plannedSpeed = 50;
void setup() {
lcd.begin(16,2);
Stepper.setSpeed(plannedSpeed);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
Serial.println(plannedSpeed);
if (key == '-') {
plannedSpeed = plannedSpeed - 1;
Serial.println(plannedSpeed);
delay(10);
}
if (key == '+') {
plannedSpeed = plannedSpeed +1;
Serial.println(plannedSpeed);
delay(10);
}
if (key == 'I') {
myStepper.step(stepsPerRevolution);
Serial.print("Running at ");
Serial.println(plannedSpeed);
delay(10);
}
}
나는 키패드와 속도를 선택할 수 있도록 코딩하기 위해 노력하고있어, 나는이 'I'버튼을 누르면 모터가 시작하고, 내가 누르면 중지 'O'버튼. 어떻게해야합니까? 감사!