Board type: Arduino UNO
Hello. I am trying to make something with 3 buttons: two to cycle through different numbers(options) and a third to lock in the answer. I've tried using interrupts but they don't call the function that they are assigned to.
#include <SevSeg.h>
#define SELECT_PIN 13 //selects(comfirms) the desired number on the sevseg
#define DOWN_PIN 12 //moves the selection down
#define UP_PIN 11 //moves the selection up
int selection;
int maxOptions;
SevSeg sevseg;
void setup() {
Serial.begin(9600);
//Sets up pins
pinMode(SELECT_PIN, INPUT_PULLUP);
pinMode(DOWN_PIN, INPUT_PULLUP);
pinMode(UP_PIN, INPUT_PULLUP);
//sets up SevSeg
byte numDigits = 1; //number of digits in the display
byte digitPins[] = {}; //defines ground pins, leave blank if numDigits = 1
byte segmentPins[] = {8, 9, 3, 4, 5, 7, 6, 2};
// An array defining the defines arduino pins to the 7 seg display
// (A, B, C, D, E, F, G, DP)
bool resistorsOnSegments = true;
//true if resistors are placed in series to the segment pins
//false if resistors are placed in series to the digit pins
byte hardwareConfig = COMMON_CATHODE; //Defines type of Sevseg display is being used. //(COMMON_CATHODE/COMMON_ANODE)
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); //Configuration of the sevseg
sevseg.setBrightness(90); //Brightness setting
//interrupts my beloved
attachInterrupt(digitalPinToInterrupt(SELECT_PIN), confirm, FALLING);
attachInterrupt(digitalPinToInterrupt(DOWN_PIN), subtract, FALLING);
attachInterrupt(digitalPinToInterrupt(UP_PIN), add, FALLING);
selection = 1;
maxOptions = 5;
}
void loop() {
// put your main code here, to run repeatedly:
if (maxOptions == -1) {
sevseg.blank();
} else {
sevseg.setNumber(selection, selection%2);
sevseg.refreshDisplay();
}
}
void confirm() {
if (maxOptions != -1) {
Serial.println(selection);
maxOptions = -1;
selection = 1;
}
}
void add() {
Serial.print("Add ");
if (maxOptions != -1) {
Serial.print(0);
selection++;
if (selection > maxOptions) selection = 1;
}
Serial.println(selection);
}
void subtract() {
Serial.print("Subtract ");
if (maxOptions != -1) {
Serial.print(0);
selection--;
if (selection <= 0) selection = maxOptions;
}
Serial.println(selection);
}