Advertisement
ptnega

button.cpp

Sep 9th, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include "mraa.hpp"
  2. #include <unistd.h>
  3.  
  4. int main() {
  5.  
  6.     mraa::Aio *a0;
  7.     uint16_t value;
  8.     bool flag = false;
  9.     bool on = false;
  10.  
  11.     a0 = new mraa::Aio(0);
  12.     if (a0 = NULL) {
  13.         return MRAA_ERROR_UNSPECIFIED;
  14.     }
  15.  
  16.     while(true) {
  17.         value = a0->read();
  18.         if (value) {
  19.             if (!on) {
  20.                 on = true;
  21.                 system("cd ~/NodeP1 && node index.js");
  22.                 flag = true;
  23.             } else if (flag == false) {
  24.                 system("shutdown -h 0");
  25.             }
  26.         } else {
  27.             if (flag == true)
  28.                 flag = !flag;
  29.         }
  30.         sleep(3);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement