简体   繁体   中英

Detect variable value change in node

I've got node running on my raspberry pi, and when you press a button, rpio.read(22) will return 0 instead of 1.

I would like to detect when this happens, and trigger a function from it. How can I do this?

Probably the best way to do this right now would be to continually loop until the value of rpio.read(22) changes. It's not very elegant, but you could just do something like this:

function buttonCheck(){
    if (rpio.read(22) == 0) {
        // code here
    } else {
        process.nextTick(buttonCheck);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM