Disabled User Button Interfering with Neopixels

Ringo setup, hardware, basic programming. User to user support.
Posts: 10
Joined: Tue Sep 15, 2015 3:37 pm

Disabled User Button Interfering with Neopixels

Postby mikasami » Fri Jan 08, 2016 2:19 am

I have a question about using the neopixels/button bus.
It seems that even though the button is not enabled in code when I press it it interferes with the neopixels. Consider the simple code below:

If i press the button randomly while the neopixel is enabled it hangs to the current color (sometimes green, sometimes blue or red) and does not proceed until the button is not pressed anymore.. How do I work around this? Thanks!


Code: Select all

#include "RingoHardware.h"

void setup(){
  HardwareBegin();        //initialize Ringo's brain to work with his circuitry
  PlayStartChirp();       //Play startup chirp and blink eyes
  SwitchMotorsToSerial(); //Call "SwitchMotorsToSerial()" before using Serial.print functions as motors & serial share a line

void loop(){

  if (ButtonPressed()){
    LeftEye(255, 0, 0);
    RightEye(0, 0, 0);

  } else {
    LeftEye(0, 0, 0);
    RightEye(0, 0, 255);   
    RightEye(0, 255, 0);   
    RightEye(255, 0, 0);

Posts: 180
Joined: Tue Jul 28, 2015 12:56 am

Re: Disabled User Button Interfering with Neopixels

Postby Kevin » Mon Jan 11, 2016 8:30 pm

I think we cleared this up in an email conversation but wanted to respond here also in case anyone else had the same question.

The button is on the same line as the Neopixels. We had to do this because that small Arduino processor doesn't have very many I/O lines. To use the button together with the NeoPixels, the best way is to set the pin to INPUT_PULLUP which enables the weak pull-up of the line. When you press the button it will pull this low.

So even if you're flashing and updating the pixels, you can still quickly in your code change this to an INPUT_PULLUP then go read the pin - if it's low then the button is being pressed. You may need to have a short delay between setting the pull-up, maybe an extra line of delayMicroseconds(200); or something between them. Then you can go right back to running the pixels following this.

Pushing the button with the pixels updating doesn't hurt anything as there's a resistor between the processor and the button/pixels. Pushing the button will just block the data from reaching the pixels so they won't update while the button is being pressed.

Who is online

Users browsing this forum: No registered users and 16 guests