const WebSocket = require('ws');
const gpio = require('rpi-gpio')

const wss = new WebSocket.Server({ port: 8080 });

var power = false;
var mute = false;

const pinConfig = {
    power: {
        number: 18,
        direction: gpio.DIR_OUT
    },
    mute: {
        number: 17,
        direction: gpio.DIR_OUT
    },
}

wss.on('connection', function connection(ws) {
    gpio.setMode(gpio.MODE_BCM);
    gpio.setup(pinConfig.power.number, pinConfig.power.direction);
    gpio.setup(pinConfig.mute.number, pinConfig.mute.direction);

    ws.on('message', function incoming(message) {
        if (message == 'powerToggle') {
            power = !power;

            writePin(pinConfig.mute.number, true);
            writePin(pinConfig.power.number, power);
        }

        if (message == 'muteToggle') {
            mute = !mute;

            writePin(pinConfig.mute.number, mute);
        }
    });

    ws.send('something');
});


function writePin(pinNumber, value) {
    gpio.write(pinNumber, value, function (err) {
        if (err) throw err;
        console.log('Written to pin ' + pinNumber);
    });
}

@@ -184,352 +184,105 @@
 er: 
-%7B%0A        number: 18,%0A        direction: gpio.DIR_OUT%0A    %7D,%0A    mute: %7B%0A        number: 17,%0A        direction: gpio.DIR_OUT%0A    %7D,%0A%7D%0A%0Awss.on('connection', function connection(ws) %7B%0A    gpio.setMode(gpio.MODE_BCM);%0A    gpio.setup(pinConfig.power.number, pinConfig.power.direction);%0A    gpio.setup(pinConfig.mute.number, pinConfig.mute.direction
+18,%0A    mute: 17%0A%7D%0A%0Awss.on('connection', function connection(ws) %7B%0A    gpio.setMode(gpio.MODE_BCM
 );%0A%0A
@@ -435,23 +435,16 @@
 fig.mute
-.number
 , true);
@@ -480,23 +480,16 @@
 ig.power
-.number
 , power)
@@ -606,15 +606,8 @@
 mute
-.number
 , mu
@@ -700,24 +700,105 @@
 alue) %7B%0A    
+gpio.setup(pinNumber, gpio.DIR_OUT, write);%0A%0A    function write() %7B%0A        this.
 gpio.write(p
@@ -835,24 +835,28 @@
 ) %7B%0A        
+    
 if (err) thr
@@ -871,16 +871,20 @@
         
+  
+  
 console.
@@ -923,14 +923,24 @@
 r);%0A    
-%7D);
+    %7D);%0A    %7D
 %0A%7D%0A

Fix pin writing