Skip to content

Instantly share code, notes, and snippets.

@HerrZatacke
Last active July 9, 2018 21:36
Show Gist options
  • Save HerrZatacke/7c75b03a92776454364b23d022814a13 to your computer and use it in GitHub Desktop.
Save HerrZatacke/7c75b03a92776454364b23d022814a13 to your computer and use it in GitHub Desktop.
ws281x and express
const express = require('express');
const server = express();
server.get('/', express.static(process.cwd()));
server.post('/', (req, res) => {
res.send('a file...');
});
server.use((error, req, res, next) => {
console.log(error.message);
res.status(500);
res.send(error.stack);
});
server.listen(3000, () => {
console.log('Example server listening on port 3000!');
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Wattiswong?</title>
</head>
<body>
<form action="/" method="POST" enctype='multipart/form-data'>
<input type="file" name="file" required/><br />
<button type="submit">!</button>
</form>
</body>
</html>
{
"name": "ws281x_express",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"ws281x": "node ws281x.js",
"express": "node express.js"
},
"author": "Herr_Zatacke",
"license": "MIT",
"dependencies": {
"express": "^4.16.3",
"rpi-ws281x-native": "^0.8.2"
}
}
var ws281x = require('rpi-ws281x-native');
var NUM_LEDS = 8;
var pixelData = new Uint32Array(NUM_LEDS);
ws281x.init(NUM_LEDS);
// ---- trap the SIGINT and reset before exit
process.on('SIGINT', function () {
ws281x.reset();
process.nextTick(function () { process.exit(0); });
});
// ---- animation-loop
var offset = 0;
setInterval(function () {
for (var i = 0; i < NUM_LEDS; i++) {
pixelData[i] = blink(offset + i);
}
offset = (offset + 1) % 256;
ws281x.render(pixelData);
}, 100);
console.log('Press <ctrl>+C to exit.');
function blink(pos) {
return (pos % 3) ? 0 : 16777215;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment