Monendero Capture

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

const int coinSignalPin = 2; // COIN signal pin

volatile int coinPulses = 0; // Coin pulses counter

void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
pinMode(coinSignalPin, INPUT_PULLUP); // Set the coinSignalPin as INPUT with
internal pullup resistor
attachInterrupt(digitalPinToInterrupt(coinSignalPin), coinInterruptHandler,
RISING); // Attach interrupt to coinSignalPin
}

void loop() {
static int lastCoinPulses = 0; // Store the last value of coinPulses

if (coinPulses != lastCoinPulses) { // Check if coinPulses has changed


Serial.print("Señal COIN detectada, número de pulsos: ");
Serial.println(coinPulses);
lastCoinPulses = coinPulses; // Update the lastCoinPulses value
coinPulses = 0;
}
}

void coinInterruptHandler() {
coinPulses++; // Increment the coinPulses counter
}

You might also like