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

Example for use with micro:bit #2

Open
joachimhs opened this issue Feb 19, 2020 · 1 comment
Open

Example for use with micro:bit #2

joachimhs opened this issue Feb 19, 2020 · 1 comment

Comments

@joachimhs
Copy link

Hello,

I am attemting to use this library for driving NeoPixel LEDs. I notice that the .c file has a uBitPinMap, that maps to 3, 2 and 1. However I am unable to get this to work.

This is the code I am attempting to use. Ideally, I would like to use P12 on the micro:bit to drive the NeoPixels. Or even better, to be able to select an available pin in the code.

`#include "MicroBit.h"
#include "ubit-neopixel/uBit_neopixel.h"

MicroBit uBit;
MicroBitImage defaultImage(5, 5);

neopixel_strip_t m_strip;
uint8_t dig_pin_num = 2;

void setup() {
neopixel_init(&m_strip, 12, 64);
neopixel_clear(&m_strip);
}

void loop() {
neopixel_set_color(&m_strip, 10, 255,0,0);
neopixel_show(&m_strip);
uBit.sleep(500);
}

int main() {
uBit.init();
setup();
while (1) {
loop();
}
}`

@joachimhs
Copy link
Author

joachimhs commented Feb 19, 2020

I changed the code in the ubit-neopixel.c file to:

void neopixel_init(neopixel_strip_t *strip, uint8_t pin_num, uint16_t num_leds)
{
//    int uBitPinMap [3] = {3,2,1}; // micro:bit pin numbers are named differently to the hardware numbers
    strip->leds = (color_t*) malloc(sizeof(color_t) * num_leds);
    strip->pin_num = pin_num;//[pin_num];
    strip->num_leds = num_leds;
    nrf_gpio_cfg_output(pin_num);
    NRF_GPIO->OUTCLR = (1UL << pin_num);
    for (int i = 0; i < num_leds; i++)
    {   
        strip->leds[i].simple.g = 0;
        strip->leds[i].simple.r = 0;
        strip->leds[i].simple.b = 0;
    }
}

And then, from the micro:bit code I used:

neopixel_init(&m_strip, MICROBIT_PIN_P1, 64);

This works somewhat, but the display acts strange where the pixels I do specify to light up does , but when I call uBit.sleep(500); the whole screen lights up for half a second.

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