Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DRV2605L Haptic Motor

Basic code + wiring

Code

//connect to the driver module


I2C1.setup({scl: B6, sda: B7 });
let hap = require('DRV2605').connect(I2C1);

let effect = 1;

//loop through all the effects


setInterval(function(){
hap.trigger(effect);
effect++;
if(effect > 120) effect = 0;
}, 1000);

Wiring diagram
Multicolor LED
Basic code + wiring

Code

var colFrom = [0,0,1]; // blue


var colTo = [1,0,0]; // red
var colFade = 0;
var colors = [
[1,0,0],
[1,1,0],
[0,1,1],
[0,0,1],
[0,1,1],
[0,1,0],
[1,1,0]
];

function onTimer() {
// fade a bit more...
colFade += 0.05;
// we've completed fading
if (colFade>=1) {
// try and fade to a new color
if (colors.length) {
colFrom = colTo;
colTo = colors.shift();
colors.push(colTo);
colFade = 0;
} else {
// no more colors - stop for now
colFade = 1;
}
}

// you may not need soft:true - it depends on your board and what pins you're using
analogWrite(redPin,colFrom[0]*(1-colFade) + colTo[0]*colFade, {soft:true});
analogWrite(greenPin,colFrom[1]*(1-colFade) + colTo[1]*colFade, {soft:true});
analogWrite(bluePin,colFrom[2]*(1-colFade) + colTo[2]*colFade, {soft:true});
}

setInterval(onTimer, 100);
Wiring diagram

LED pinout

Code - Alt. approach w. hex code

let led = require("RGBLed").connect([A5, A6, A7]);

led.setColor("0000FF");

//see https://www.espruino.com/RGBLed
Espruino Pico Basic Pinout

You might also like