Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a break out of a larger arduino sketch that I'm using to run the plinko board project. I'm running into issues adding interrupts instead of querying the state in the loop.
// * define all of the pins
// * each of these is marked as an interruptable pin on the M0 Adalogger
#define break_beam_ZERO 14
#define break_beam_ONE 11
#define break_beam_TWO 10
#define break_beam_THREE 9
#define break_beam_FOUR 6
#define break_beam_FIVE 5
// * Init some state tracking vars
int breakBeamState_ZERO;
int breakBeamState_ONE;
int breakBeamState_TWO;
int breakBeamState_THREE;
int breakBeamState_FOUR;
int breakBeamState_FIVE;
setup()
{
Serial.begin(115200);
Serial.println("Starting up");
// * Set up each of the break-beam pins
// * Note that this is a modification of the original pinout settings that I was using
// * when I was trying to query the state in the loop.
// * The original settings looked like this:
// pinMode(break_beam_ZERO, INPUT);
// digitalWrite(break_beam_ZERO, HIGH);
pinMode(break_beam_ZERO, INPUT_PULLUP);
digitalWrite(break_beam_ZERO, HIGH);
attachInterrupt(break_beam_ZERO, setBreakbeamState, LOW);
pinMode(break_beam_ONE, INPUT_PULLUP);
digitalWrite(break_beam_ONE, HIGH);
attachInterrupt(break_beam_ONE, setBreakbeamState, LOW);
pinMode(break_beam_TWO, INPUT_PULLUP);
digitalWrite(break_beam_TWO, HIGH);
attachInterrupt(break_beam_TWO, setBreakbeamState, LOW);
pinMode(break_beam_THREE, INPUT_PULLUP);
digitalWrite(break_beam_THREE, HIGH);
attachInterrupt(break_beam_THREE, setBreakbeamState, LOW);
pinMode(break_beam_FOUR, INPUT_PULLUP);
digitalWrite(break_beam_FOUR, HIGH);
attachInterrupt(break_beam_FOUR, setBreakbeamState, LOW);
pinMode(break_beam_FIVE, INPUT_PULLUP);
digitalWrite(break_beam_FIVE, HIGH);
attachInterrupt(break_beam_FIVE, setBreakbeamState, LOW);
}
loop()
{
// * Check our state. In theory these should be updated by the ISR, but I'm not seeing the changes
Serial.println("===================");
Serial.println(breakBeamState_ZERO);
Serial.println(breakBeamState_ONE);
Serial.println(breakBeamState_TWO);
Serial.println(breakBeamState_THREE);
Serial.println(breakBeamState_FOUR);
Serial.println(breakBeamState_FIVE);
Serial.println("===================");
delay(500);
}
void setBreakbeamState()
{
// * Reading in the state of the break beam pins
breakBeamState_ZERO = digitalRead(break_beam_ZERO);
breakBeamState_ONE = digitalRead(break_beam_ONE);
breakBeamState_TWO = digitalRead(break_beam_TWO);
breakBeamState_THREE = digitalRead(break_beam_THREE);
breakBeamState_FOUR = digitalRead(break_beam_FOUR);
breakBeamState_FIVE = digitalRead(break_beam_FIVE);
// * I tried hard coding the zero to test and see if the interrupt was getting called at all (it's not).
// breakBeamState_ZERO = 0;
// breakBeamState_ONE = 0;
// breakBeamState_TWO = 0;
// breakBeamState_THREE = 0;
// breakBeamState_FOUR = 0;
// breakBeamState_FIVE = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment