import express from 'express'
//import SerialPort from 'serialport'
import rpio from 'rpio'
/*
 * Set the initial state to low.  The state is set prior to the pin becoming
 * active, so is safe for devices which require a stable setup.
 */
rpio.open(12, rpio.OUTPUT, rpio.LOW)
rpio.open(18, rpio.OUTPUT, rpio.LOW)

/*
 * The sleep functions block, but rarely in these simple programs does one care
 * about that.  Use a setInterval()/setTimeout() loop instead if it matters.
 */
// for (var i = 0; i < 5; i++) {
//         /* On for 1 second */
//         rpio.write(12, rpio.HIGH);
//         rpio.sleep(1);

//         /* Off for half a second (500ms) */
//         rpio.write(12, rpio.LOW);
//         rpio.msleep(500);
// }
// const Serialport = SerialPort
// const serialport = new Serialport("/dev/ttyACM0", {
// 	baudRate: 9600,
// 	parser: SerialPort.parsers.readline('\n')
// })

// serialport.on('open', function(){
//   console.log('Serial Port Opend')
//   serialport.on('data', function(data){
//       console.log('on data' + data)
//   })
// })

const router = express.Router()

router.get('/left', function (req, res) {
	rpio.write(12, rpio.HIGH)

	setTimeout(function () {
		rpio.write(12, rpio.LOW)
		res.json(true)
	}, 3000)
})

router.get('/right', function (req, res) {
	rpio.write(18, rpio.HIGH)

	setTimeout(function () {
		rpio.write(18, rpio.LOW)
		res.json(true)
	}, 3000)
})

router.post('/lights', function (req, res) {
	const light = (req.body.light) ? '0' : '1'

	// serialport.write(new Buffer(light))

	res.json(true)
})

router.post('/colourChange', function (req, res) {
	const colour = req.body.colour
	console.log(colour);
	// serialport.write(new Buffer(colour))

	res.json(colour)
})

export default router

@@ -1223,35 +1223,34 @@
 .json(true)%0A%09%7D, 
-300
+25
 0)%0A%7D)%0A%0Arouter.ge
@@ -1389,11 +1389,10 @@
 %09%7D, 
-300
+25
 0)%0A%7D
@@ -1587,32 +1587,33 @@
 ion (req, res) %7B
+#
 %0A%09const colour =

change turn time