Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offset LED #1

Open
jsammarco opened this issue Dec 20, 2017 · 1 comment
Open

Offset LED #1

jsammarco opened this issue Dec 20, 2017 · 1 comment

Comments

@jsammarco
Copy link

jsammarco commented Dec 20, 2017

Hi, I have an LED that is not part of my grid and I have offset it in my alternating-matrix.
ws281x.setIndexMapping(alt_matrix(75,8));
I have text scrolling great but my issue is my 601st led is just yellow and doesnt respond. I tried to manually adjust the array to fix it and just no luck. Here is my code.
-Thanks great work

const Image = require('canvas').Image;
var fs = require('fs'),
	getPixels = require("get-pixels"),
	led_lib = require('ledutils'),
	Gpio = require('pigpio').Gpio,
	ws281x = require('rpi-ws281x-native'),
	alt_matrix = require('./alternating-matrix.js'),
    canvas = require('rpi-ws281x-canvas').create(75,8),
    ctx = canvas.getContext('2d'),
	NUM_LEDS = 602,
	pixelData = new Uint32Array(NUM_LEDS),
	pixelDataArr = new Array(NUM_LEDS);
	moving = false;
	
ws281x.init(NUM_LEDS, {
  frequency: 800000, // 800kHz (some LEDs run at 400kHz)
  dmaNum: 10, // DMA-number to be used
  gpioPin: 12, // GPIO-PIN to use (this is the only one i tested)
  invert: 0,
  brightness: 100
});

ws281x.setIndexMapping(alt_matrix(75,8));

// ---- trap the SIGINT and reset before exit
process.on('SIGINT', function () { //CLEARS LEDS
  ws281x.reset();
  process.nextTick(function () { process.exit(0); });
});

console.log("Started");
var i = -55;
ctx.scale(-1, 1);
setInterval(function () {
	if(i > 75){ i = -55; }
	ctx.fillStyle = 'blue';
	ctx.translate(0, 8);
	ctx.scale(-1, -1);
	ctx.font = 'bold 11px times';
	ctx.fillText("Joe is Cool", i, 8, 75);
	ctx.fillStyle = '#000000';
	ctx.fillRect(-75, 0, 75, 75);
	ctx.fillStyle = '#ffffff';
	ctx.fillRect(0, 0, 1, 8);
	ws281x.render(canvas.toUint32Array());
	i++;
}, 24);

alternating-matrix.js

module.exports = function(width, height) {
    var map = new Uint16Array((width*height)+1);//One for extra LED offset
    for(var i = 0; i<map.length+1; i++) {
        var row = Math.floor(i/width), col = i % width ;

        if((row % 2) === 0) {
            map[i+1] = i;
        } else {
            map[i+1] = (row+1) * width - (col+1);
        }
    }
    //map[599] = 55;//(width*height)-width+1;
    //map[0] = 999;
    map[600] = 525;
    //map[(width*height)-width-1] = (row+1) * width - (col+1);
    console.log(map[524], map[525], map[526]);
    console.log(map[600]);
    return map;
};
@jsammarco
Copy link
Author

I have tried these changes and still have an issue with the last LED in the strip.

module.exports = function(width, height) {
    var map = new Uint16Array((width*height)+2);//One for extra LED offset
    for(var i = 0; i<map.length+1; i++) {
        var row = Math.floor(i/width), col = i % width ;

        if((row % 2) === 0) {
            map[i+1] = i;
        } else {
            map[i+1] = (row+1) * width - (col+1);
        }
    }
    //map[599] = 55;//(width*height)-width+1;
    //map[0] = 999;
    //map[600] = 525;
    map[0] = 999;
    map[601] = 524;
    //map[(width*height)-width-1] = (row+1) * width - (col+1);
    console.log(map);
    return map;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant