const int BTN_PIN = 12;
const int NUM_TYPES = 5;
const int PAPER_TYPES[NUM_TYPES][2] = {
{1000, 5},
{2000, 4},
{3000, 3},
{4000, 2},
{5000, 1}
};
int type = 0;
void checkButton() {
static int oldBtnState = HIGH;
int btnState = digitalRead(BTN_PIN);
if (btnState != oldBtnState) {
oldBtnState = btnState;
if (btnState == LOW) { // button was pressed
Serial.print("Paper type: ");
Serial.println(type);
Serial.print("Feed time: ");
Serial.println(PAPER_TYPES[type][0]);
Serial.print("Servo count: ");
Serial.println(PAPER_TYPES[type][1]);
Serial.println();
type++;
if (type >= NUM_TYPES) type = 0;
} else { // button was released
// nothing to do
}
delay(20); // for debounce
}
}
void setup() {
Serial.begin(115200);
pinMode(BTN_PIN, INPUT_PULLUP);
}
void loop() {
checkButton();
}