Last active
July 9, 2018 21:36
-
-
Save HerrZatacke/7c75b03a92776454364b23d022814a13 to your computer and use it in GitHub Desktop.
ws281x and express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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