Looks good - there are a few bits you need though:
i2c_address could be in C.i2c_address as it's just a constant
You need to fill in the values in the C structures, but I guess this is kind of a work in progress?
To define a constructor function up the top: function DS3231(_i2c) { this.i2c = _i2c; }
Replace every occurrance of I2C1 with this.i2c
You need to export it at the end. With Espruino I generally export a function called connect, which takes the device name that you attach it to. For example: exports.connect = function(i2c) { return new DS3231(i2c); }
Then to use it, you just do var rtc = require("DS3231").connect(I2C1)
To test it, I'd just put exports = {}; right at the top, and var rtc = exports.connect(I2C1) at the bottom instead of the require. Then, you can develop it all on the right-hand side of the Web IDE.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Looks good - there are a few bits you need though:
i2c_address
could be inC.i2c_address
as it's just a constantC
structures, but I guess this is kind of a work in progress?function DS3231(_i2c) { this.i2c = _i2c; }
I2C1
withthis.i2c
connect
, which takes the device name that you attach it to. For example:exports.connect = function(i2c) { return new DS3231(i2c); }
Then to use it, you just do
var rtc = require("DS3231").connect(I2C1)
To test it, I'd just put
exports = {};
right at the top, andvar rtc = exports.connect(I2C1)
at the bottom instead of the require. Then, you can develop it all on the right-hand side of the Web IDE.