//modules 
import express from 'express'
import BodyParser from 'body-parser'
//routes
//import index from './routes/index'

import rpio from 'rpio'

var pin = 12;           /* P12/GPIO18 */
var range = 1024;       /* LEDs can quickly hit max brightness, so only use */
var max = 128;          /*   the bottom 8th of a larger scale */
var clockdiv = 8;       /* Clock divider (PWM refresh rate), 8 == 2.4MHz */
var interval = 5;       /* setInterval timer, speed of pulses */
var times = 5;          /* How many times to pulse before exiting */

/*
 * Enable PWM on the chosen pin and set the clock and range.
 */
rpio.open(pin, rpio.PWM);
rpio.pwmSetClockDivider(clockdiv);
rpio.pwmSetRange(pin, range);

/*
 * Repeatedly pulse from low to high and back again until times runs out.
 */
var direction = 1;
var data = 0;

var pulse = setInterval(function() {
	console.log('bleep');
        rpio.pwmSetData(pin, data);
        if (data === 0) {
                direction = 1;
                if (times-- === 0) {
                        clearInterval(pulse);
                        rpio.open(pin, rpio.INPUT);
                        return;
                }
        } else if (data === max) {
                direction = -1;
        }
        data += direction;
}, interval, data, direction, times);

const app = express()

app.use(BodyParser.json())

//enable cors
app.all('*', function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
});

app.use('/public', express.static(__dirname + '/public'))

//app.use('/', index);

app.listen(3000, function () {
	console.log('app is listening on port 3000')
})

export default app

@@ -147,20 +147,456 @@
 o'%0A%0A
-var pin = 12
+rpio.open(12, rpio.OUTPUT, rpio.LOW);%0A%0A/*%0A * The sleep functions block, but rarely in these simple programs does one care%0A * about that.  Use a setInterval()/setTimeout() loop instead if it matters.%0A */%0Afor (var i = 0; i %3C 5; i++) %7B%0A        /* On for 1 second */%0A        rpio.write(12, rpio.HIGH);%0A        rpio.sleep(3000);%0A%0A        /* Off for half a second (500ms) */%0A        rpio.write(12, rpio.LOW);%0A        rpio.msleep(3000);%0A%7D%0A%0A// var pin = 19
 ;   
@@ -616,24 +616,27 @@
 2/GPIO18 */%0A
+// 
 var range = 
@@ -698,24 +698,27 @@
 only use */%0A
+// 
 var max = 12
@@ -766,24 +766,27 @@
 er scale */%0A
+// 
 var clockdiv
@@ -845,24 +845,27 @@
 = 2.4MHz */%0A
+// 
 var interval
@@ -913,24 +913,27 @@
 f pulses */%0A
+// 
 var times = 
@@ -991,18 +991,24 @@
 ng */%0A%0A/
-*%0A
+/ /*%0A// 
  * Enabl
@@ -1060,20 +1060,26 @@
  range.%0A
+// 
  */%0A
+// 
 rpio.ope
@@ -1096,16 +1096,19 @@
 o.PWM);%0A
+// 
 rpio.pwm
@@ -1134,16 +1134,19 @@
 ckdiv);%0A
+// 
 rpio.pwm
@@ -1168,19 +1168,20 @@
 ange);%0A%0A
-/*%0A
+%0A// 
  * Repea
@@ -1247,19 +1247,20 @@
 s out.%0A 
-*/%0A
+%0A// 
 var dire
@@ -1270,16 +1270,19 @@
 on = 1;%0A
+// 
 var data
@@ -1288,16 +1288,19 @@
 a = 0;%0A%0A
+// 
 var puls
@@ -1324,24 +1324,27 @@
 unction() %7B%0A
+// 
 %09console.log
@@ -1354,16 +1354,19 @@
 leep');%0A
+// 
         
@@ -1393,16 +1393,19 @@
  data);%0A
+// 
         
@@ -1414,32 +1414,35 @@
  (data === 0) %7B%0A
+// 
                 
@@ -1456,16 +1456,18 @@
 on = 1;%0A
+//
         
@@ -1470,24 +1470,25 @@
             
+ 
 if (times-- 
@@ -1492,24 +1492,27 @@
 -- === 0) %7B%0A
+// 
             
@@ -1545,16 +1545,19 @@
 pulse);%0A
+// 
         
@@ -1600,16 +1600,19 @@
 INPUT);%0A
+// 
         
@@ -1635,16 +1635,18 @@
 return;%0A
+//
         
@@ -1645,34 +1645,38 @@
                 
+ 
 %7D%0A
+// 
         %7D else i
@@ -1690,24 +1690,27 @@
  === max) %7B%0A
+// 
             
@@ -1729,16 +1729,19 @@
 n = -1;%0A
+// 
         
@@ -1742,16 +1742,19 @@
       %7D%0A
+// 
         
@@ -1772,16 +1772,19 @@
 ection;%0A
+// 
 %7D, inter

no pwm