Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 4 pins of the stepper motor board
- #define _PIN1 8
- #define _PIN2 9
- #define _PIN3 10
- #define _PIN4 11
- // Interruption on PIN2
- #define ITR_PIN 2
- volatile int count = 0;
- volatile int triggers = 0;
- volatile int lastTrigger = 0;
- const unsigned int BAUD_RATE = 9600;
- void Trigger()
- {
- triggers++;
- }
- void setup()
- {
- cli();
- pinMode(ITR_PIN, INPUT_PULLUP);
- attachInterrupt(0, Trigger, FALLING);
- sei();
- Serial.begin(BAUD_RATE);
- Serial.println("Go");
- Serial.flush();
- }
- void loop()
- {
- if (triggers != lastTrigger)
- {
- // Debounce count
- lastTrigger = triggers;
- count++;
- // Output count
- Serial.println(count);
- Serial.flush();
- }
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement