Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 4 down vote favorite Using javascript functions and the old way of doing things I wrote a piece of code to copy the first file in a directory to a file Test . console.log("Copy First File"); var fs = require('fs'); fs.readdir(".", function(err, files) if (err) console.log(err);process.exit(1); fs.exists(files[0], function(exits) fs.readFile(files[0], function(err, data) if (err) console.log(err);process.exit(1); fs.writeFile('Test', data, function(err) if (err) console.log(err);process.exit(1); console.log("Data Copied"); ); ) ); ); After reading about Promises (and several failed attempts). I managed to convert the above to use Promise and .then() chaining. function getAListOfFiles() return new Promise(function(resolve, reject) fs.readdir(".", function(err, files) if (err)...
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 5 down vote favorite Preliminaries I have optical sensor ADNS2610 (see datasheet here). There are a few problems which it can be used to solve, but for now let us focus on getting an image from that sensor. This sensor is kind of a small camera which has 400 cpi (counts per inch) resolution. And the resulting image consists of 324 = 18 x 18 pixels. The following is from the linked datasheet (p.23): So in order to read a frame I should follow the algorithm: Set the LED to forced awake mode Write anything to the Pixel Data register Read 324 times 6-bit unsigned integer from that register So below is my program. Program Object oriented approach and WriteRegister and ReadRegisters functions (slightly modified) are borrowed from this project by zapmaker. Optical sensor is represented by a class: ADNS2610 class #ifndef ADNS2610_H #define ADNS261...