attachInterrupt function doesn't work within a while loop?

92 views
Skip to first unread message

fmadison

unread,
Feb 28, 2015, 9:02:00 PM2/28/15
to beagl...@googlegroups.com

I am finding that the bonescript attachInterrupt function doesn't seem to work when the program is in a while statement. I need to loop indefinitely while monitoring a process. As part of the monitoring I need to record a switch closing so that's where the interrupt comes in... 

The interrupt here works just fine, but it doesn't loop so I can do the rest of the monitoring and logging functions I want to do: 
var b = require('bonescript');
var cycles=0;
var inputPin = 'P8_19';
b.pinMode(inputPin, b.INPUT);
b.attachInterrupt(inputPin, true, b.CHANGE, cyclecounter);

function cyclecounter() {
    cycles++);
}


In this code the while loop allows me to monitor and log, but the interrupt doesn't work from within the while loop, so I can't record cycles:
var b = require('bonescript');
var cycles=0;
var inputPin = 'P8_19';
b.pinMode(inputPin, b.INPUT);
b.attachInterrupt(inputPin, true, b.CHANGE, cyclecounter);
while (true){
//extensive code to monitor and log a process external to the beaglebone black
}

function cyclecounter() {
    cycles++);
}


Is there a way I can setup an interrupt function within a while loop? 

This is my first time working with interrupts so I may be missing something obvious... but if anyone can point me in the right direction it would be greatly appreciated.

Cheers

Reply all
Reply to author
Forward
0 new messages