Glad you're looking into the different example programs! The FR1 reversal example uses two variables to control the task: trialsToSwitch and counter (lines 23 and 24):
The task determines which poke is active by the following logic: if counter is less than or equal to trialsToSwitch (line 36) the Left poke becomes active; if counter is greater than trialsToSwitch (line 37) the Right poke becomes active; and if counter is a multiple of trialsToSwitch (line 35) counter resets to 1 so the process can repeat. This bit of code could be clearer but
I wrote it in the middle of 2020 when we were stuck indoors with a baby and my brain was probably a bit scrambled :)
The code then accounts for the 4 cases that can happen, based on what the animal does and which poke is active:
1) A left poke while the left poke is active
2) A left poke while the right poke is active
3) A right poke while the left poke is active
4) A right poke while the right poke is active
If you look at the code for each of these cases you'll see that in all four cases the code increments the counter variable by one (the counter++ call in lines 50, 57, 64, and 72). So to make the task reverse only after a certain number of pellets (and not pokes), we want to add one to counter only if the mouse gets a pellet. In practice, this means
we'll comment out the counter++ call when the mouse doesn't get a pellet
(comment out lines 57 and 64) in the original task code. I'm attaching a modified version that has these two lines commented out. You can reflash this (you can also edit trialsToSwitch to be whatever you want) and FED3 will reverse after a set number of pellets and not pokes.
Hope this helps, have fun!