0

Metro Mini, on/off with RF Remote?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro Mini, on/off with RF Remote?

by PaperMacheMonkey on Thu Feb 14, 2019 5:31 pm

Hey all, I have some chasing code written for NeoPixels that works fine on my board, but I'm having trouble making it remote controlled.

I'm relatively new to building circuits and am a little confused with what I'm trying to do.

Basically, I'm trying to have the Metro run the code (on/off) using the M4 RF receiver, I can get my neopixels to power with the M4 in the circuit but I'm having trouble getting the remote to do anything. There is definitely some dimming/blinking going on, but nothing like what is supposed to happen.

Am I trying to do something not possible? How should my wiring be set up? Where do i need a resistor/if any? etc.

Any advice?

PaperMacheMonkey
 
Posts: 7
Joined: Wed Apr 25, 2018 11:18 am

Re: Metro Mini, on/off with RF Remote?

by franklin97355 on Thu Feb 14, 2019 5:36 pm

Can you post your code, what you are trying to achieve and the connections between the parts you are using so we have an idea of what is going on?

franklin97355
 
Posts: 20495
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Metro Mini, on/off with RF Remote?

by PaperMacheMonkey on Thu Feb 14, 2019 5:41 pm

I'm using a metro Mini, M4 RF Receiver, and currently a 3.7v 2500mah LiPo battery. The code isn't the problem as it runs perfectly fine by itself ( just a simple light chase with about 60 neopixels), what I'm trying to achieve is when I press the button on the RF remote, the code/chase starts, and when you press it again it stops.

I basically have the circuit designed and working without the M4, need to shoehorn that bad boy in there. Does the button press also need to be part of the code? Or can I just turn power to the Metro on and off using the receiver?

PaperMacheMonkey
 
Posts: 7
Joined: Wed Apr 25, 2018 11:18 am

Re: Metro Mini, on/off with RF Remote?

by franklin97355 on Thu Feb 14, 2019 6:04 pm

You would treat the M4 output the same as a button press in your code. You could use it as a power switch if the output of the M4 toggles on and off with the addition of a transistor.

franklin97355
 
Posts: 20495
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Metro Mini, on/off with RF Remote?

by PaperMacheMonkey on Mon Feb 25, 2019 12:06 pm

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>



class Strip
{
public:
  const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  5;
int buttonState = 0;         // variable for reading the pushbutton status
  uint8_t   effect;
  uint8_t   effects;
  uint16_t  effStep;
  unsigned long effStart;
  Adafruit_NeoPixel strip;
  Strip(uint16_t leds, uint8_t pin, uint8_t toteffects) : strip(leds, pin, NEO_GRB + NEO_KHZ800) {
    effect = -1;
    effects = toteffects;
    Reset();
  }
  void Reset(){
    effStep = 0;
    effect = (effect + 1) % effects;
    effStart = millis();
  }
};

struct Loop
{
  uint8_t currentChild;
  uint8_t childs;
  bool timeBased;
  uint16_t cycles;
  uint16_t currentTime;
  Loop(uint8_t totchilds, bool timebased, uint16_t tottime) {currentTime=0;currentChild=0;childs=totchilds;timeBased=timebased;cycles=tottime;}
};

Strip strip_0(68, 5, 68 );
struct Loop strip0loop0(1, false, 1);

//[GLOBAL_VARIABLES]

void setup() {

  //Your setup here:
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  strip_0.strip.begin();
}


  //Your code here:

{void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  strips_loop();
}

void strips_loop() {
  if(strip0_loop0() & 0x01)
    strip_0.strip.show();
}

uint8_t strip0_loop0() {
  uint8_t ret = 0x00;
  switch(strip0loop0.currentChild) {
    case 0:
           ret = strip0_loop0_eff0();break;
  }
  if(ret & 0x02) {
    ret &= 0xfd;
    if(strip0loop0.currentChild + 1 >= strip0loop0.childs) {
      strip0loop0.currentChild = 0;
      if(++strip0loop0.currentTime >= strip0loop0.cycles) {strip0loop0.currentTime = 0; ret |= 0x02;}
    }
    else {
      strip0loop0.currentChild++;
    }
  };
  return ret;
}

uint8_t strip0_loop0_eff0() {
  if(millis() - strip_0.effStart < 20 * (strip_0.effStep)) return 0x00;
  float factor1, factor2;
  uint16_t ind;
  for(uint16_t j=0;j<68;j++) {
    ind = strip_0.effStep + j * 1;
    switch((ind % 68) / 34) {
      case 0: factor1 = 1.0 - ((float)(ind % 68 - 0 * 34) / 34);
              factor2 = (float)((ind - 0) % 68) / 34;
              strip_0.strip.setPixelColor(j, 0 * factor1 + 255 * factor2, 0 * factor1 + 231 * factor2, 0 * factor1 + 0 * factor2);
              break;
      case 1: factor1 = 1.0 - ((float)(ind % 68 - 1 * 34) / 34);
              factor2 = (float)((ind - 34) % 68) / 34;
              strip_0.strip.setPixelColor(j, 255 * factor1 + 0 * factor2, 231 * factor1 + 0 * factor2, 0 * factor1 + 0 * factor2);
              break;
    }
  }
  if(strip_0.effStep >= 68) {strip_0.Reset(); return 0x03; }
  else strip_0.effStep++;
  return 0x01;
}


So this is the code that I'm using for my chase/rainbow effect, but I'm having an issue inserting a button press into this code and having it still work. Can someone walk me through it or give me an example?

PaperMacheMonkey
 
Posts: 7
Joined: Wed Apr 25, 2018 11:18 am

Please be positive and constructive with your questions and comments.