Facebook
From Flying Lizard, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 83
  1. // IN  PINS  21, 20, 19, 18, 16
  2. // OUT PINS  13, 12, 11, 10, 9
  3. // process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
  4. // SETUP
  5. // const Settings = require('./settings.js');
  6. // const Core = new (require('./core.js'));
  7.  
  8. // PACKAGES
  9.  
  10. const ON = 0;
  11. const OFF = 1;
  12.  
  13. const Gpio = require('onoff').Gpio;
  14.  
  15. const devices = {
  16.     dilim1: {
  17.         in: new Gpio(22, 'in', 'both'),
  18.         out: new Gpio(5, 'out'),
  19.     },
  20.     dilim2: {
  21.         in: new Gpio(18, 'in', 'both'),
  22.         out: new Gpio(21, 'out'),
  23.     },
  24.     dilim3: {
  25.         in: new Gpio(23, 'in', 'both'),
  26.         out: new Gpio(20, 'out'),
  27.     },
  28.     semiRot2: {
  29.         in: new Gpio(24, 'in', 'both'),
  30.         out: new Gpio(16, 'out'),
  31.     },
  32.  
  33.  
  34.     flat3: {
  35.         in: new Gpio(17, 'in', 'both'),
  36.         out: new Gpio(13, 'out'),
  37.     },
  38.     flat4: {
  39.         in: new Gpio(27, 'in', 'both'),
  40.         out: new Gpio(6, 'out'),
  41.     },
  42.  
  43.     flat2: {
  44.         in: new Gpio(15, 'in', 'both'),
  45.         out: new Gpio(19, 'out'),
  46.     },
  47.  
  48.     flat1: {
  49.         in: new Gpio(14, 'in', 'both'),
  50.         out: new Gpio(26, 'out'),
  51.     },
  52.  
  53.  
  54. };
  55.  
  56.  
  57. // const DELAY = 60000; // 60 second
  58.  
  59. setTimeout(function () {
  60.  
  61.     /*devices.dilim1.out.writeSync(OFF);
  62.     devices.dilim2.out.writeSync(OFF);
  63.     devices.dilim3.out.writeSync(OFF);
  64.     devices.semiRot2.out.writeSync(OFF);
  65.  
  66.  
  67.     devices.flat2.out.writeSync(OFF);
  68.     devices.flat3.out.writeSync(OFF);
  69.     devices.flat4.out.writeSync(OFF);
  70.     devices.flat1.out.writeSync(OFF);*/
  71.  
  72.     console.log('dilim1 - ' + devices.dilim1.out.readSync());
  73.     console.log('dilim2 - ' + devices.dilim2.out.readSync());
  74.     console.log('dilim3 - ' + devices.dilim3.out.readSync());
  75.     console.log('semiRot2 - ' + devices.semiRot2.out.readSync());
  76.  
  77.     console.log('flat2 - ' + devices.flat2.out.readSync());
  78.     console.log('flat3 - ' + devices.flat3.out.readSync());
  79.     console.log('flat4 - ' + devices.flat4.out.readSync());
  80.     console.log('flat1 - ' + devices.flat1.out.readSync());
  81.  
  82.     /*devices.dilim2.out.writeSync(OFF);
  83.     devices.dilim3.out.writeSync(OFF);
  84.     devices.semiRot2.out.writeSync(OFF);
  85.  
  86.  
  87.     devices.flat2.out.writeSync(OFF);
  88.     devices.flat3.out.writeSync(OFF);
  89.     devices.flat4.out.writeSync(OFF);
  90.     devices.flat1.out.writeSync(OFF);*/
  91.  
  92. }, 3000);
  93.  
  94.  
  95.  
  96.  
  97. setTimeout(function () {
  98.  
  99.     devices.dilim1.in.watch(function (err, value) {
  100.         if (err) { throw err; }
  101.         console.log('DİLİM 1 - ' + value);
  102.         devices.dilim1.out.writeSync(value ? ON : OFF);
  103.     });
  104.  
  105.     devices.dilim2.in.watch(function (err, value) {
  106.         if (err) { throw err; }
  107.         console.log('DİLİM 2 - ' + value);
  108.         devices.dilim2.out.writeSync(value ? ON : OFF);
  109.     });
  110.  
  111.     devices.dilim3.in.watch(function (err, value) {
  112.         if (err) { throw err; }
  113.         console.log('DİLİM 3 - ' + value);
  114.         devices.dilim3.out.writeSync(value ? ON : OFF);
  115.     });
  116.  
  117.     devices.semiRot2.in.watch(function (err, value) {
  118.         if (err) { throw err; }
  119.         console.log('DEMİ ROT 2 - ' + value);
  120.         devices.semiRot2.out.writeSync(value ? ON : OFF);
  121.     });
  122.  
  123.  
  124.  
  125.     devices.flat3.in.watch(function (err, value) {
  126.         if (err) { throw err; }
  127.         console.log('FLAT 3 - ' + value);
  128.         devices.flat3.out.writeSync(value ? ON : OFF);
  129.     });
  130.  
  131.     devices.flat4.in.watch(function (err, value) {
  132.         if (err) { throw err; }
  133.         console.log('FLAT 4 - ' + value);
  134.         devices.flat4.out.writeSync(value ? ON : OFF);
  135.     });
  136.  
  137.     devices.flat1.in.watch(function (err, value) {
  138.         if (err) { throw err; }
  139.         console.log('FLAT 1 - ' + value);
  140.         devices.flat1.out.writeSync(value ? ON : OFF);
  141.     });
  142.  
  143.     devices.flat2.in.watch(function (err, value) {
  144.         if (err) { throw err; }
  145.         console.log('FLAT 2 - ' + value);
  146.         devices.flat2.out.writeSync(value ? ON : OFF);
  147.     });
  148.  
  149. }, 5000);