Relay Shield and NeoPixel Strip Warning Light

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cmckay
 
Posts: 30
Joined: Tue Nov 26, 2013 12:00 pm

Relay Shield and NeoPixel Strip Warning Light

Post by cmckay »

Hello All-

I am currently finishing a custom TV stand in which (all from Adafruit except the relay shield) and RF transmitter controls a linear actuator that lifts a quasi hidden compartment that houses my Xbox controller, 3D glasses, and TV/SAT remotes. I literally just finished all of the wiring and coding and am more than pleased with my accomplishment. Needless to say I suffer from a disease that minutes after completion I realize I wanted to change or already improve the project. I would like to add one or two NeoPixel strips that will serve a flashing yellow warning light that will run while the linear actuator is lifting/closing and then turn off. I have not been able to figure out how to work in the "while" function for this. I am completely stumped on this an appreciate any and all help one can provide. I am rather new to these types of functions and have tried to read and understand, but to no avail. So, thanks in advance to anyone who provides any input. Please let me know if you need pics or anything more. Thanks!

Chris

-portion of the code that will lift the lid when keyfob button A is pressed and lower when button B is pressed. this is where is want the Neo strip to flash/color wipe/ or whatever only while the linear actuator is running. Roughly 25 seconds in both directions up/down-

Code: Select all

void loop ()  { 
  buttonState0 = digitalRead(buttonPin0);//Keyfob D
  buttonState1 = digitalRead(buttonPin1);//Keyfob C
  buttonState2 = digitalRead(buttonPin2);//Keyfob B
  buttonState3 = digitalRead(buttonPin3);//Keyfob A 

 if (buttonState3 == HIGH) {

    digitalWrite(Relay1,HIGH);//Actuator Lift Segment Up
    delay(22000);
    digitalWrite(Relay1,LOW);    
  }

  if (buttonState3 == LOW){
  }
  
  if (buttonState2 == HIGH) {
    
    digitalWrite(Relay2,HIGH);//
    delay(23000);
    digitalWrite(Relay2,LOW);
  }
  
  if (buttonState2 == LOW);{
  }

User avatar
cmckay
 
Posts: 30
Joined: Tue Nov 26, 2013 12:00 pm

Re: Relay Shield and NeoPixel Strip Warning Light

Post by cmckay »

I also wanted to make mention this is a 2nd attempt at this question. I previously posted the same question and received very good answers, however i pulled an epic fail on my attempts. Thanks again.

1st post "Running Neopixels During Another Program"

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Relay Shield and NeoPixel Strip Warning Light

Post by adafruit_support_bill »

The big problem here is the "delay(22000);". Nothing can happen during that 22 seconds. The simplest approach to doing some work while waiting is something like this:

Code: Select all

long start = millis();  // get the start time.
while (millis() - start < 2200)
{
    // do some neopixel stuff here.
}

User avatar
cmckay
 
Posts: 30
Joined: Tue Nov 26, 2013 12:00 pm

Re: Relay Shield and NeoPixel Strip Warning Light

Post by cmckay »

Hi Again-

I think I placed all the correct coding where it should be, however the leds won't light. If I use "void loop" the leds just run continuously once the board has power. If i use only "loop" they aren't triggered when the input pin receives a HIGH charge. I didn't put the new code into the project as i wanted to test it first. i have second board just for testing this new code and the leds. i have two Neopixel bars connected ( i know they work because i tried a regular code prior to this and they run fine).

Right now for testing i have my neopixels hooked up to the Uno's Gnd/5v and PIN 11. I am jumping a line from the 5v to any digital input 0-4 as they are the inputs i use to receive the RF trasmitter trigger. i am hoping you can see where i made my mistake. please let me know if you need pics or something to help you decipher my setup. below is the full code. I really appreciate any help you can offer. Thanks in advance.
-Chris

Code: Select all

//2015 TV Stand and Controller Control
#include <Adafruit_NeoPixel.h>

const int Relay1 = 7;    
const int Relay2 = 6;
const int Relay3 = 5;
const int Relay4 = 4;

int Relay1a = 8;
int Relay2a = 9;
int Relay3a = 10;
int Relay4a = 11;

const int buttonPin0 = 0;
const int buttonPin1 = 1;
const int buttonPin2 = 2;
const int buttonPin3 = 3;

int buttonState0 = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;

#define PIN 12
#define TPIXEL 16
int wait_T=40;
int PixelCount=16;
int Pixel_Start_End=0;
boolean UsingBar = true;//true is for 3 LEDs & false is for 5 LEDs
long start = millis();//gets the start time

Adafruit_NeoPixel strip = Adafruit_NeoPixel(TPIXEL, PIN, NEO_GRB + NEO_KHZ800);

// the setup routine runs once when you press reset:
void setup()  {
   
  pinMode(buttonPin0, INPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);  
  
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay4, OUTPUT);
  pinMode(Relay1a, OUTPUT);
  pinMode(Relay2a, OUTPUT);
  pinMode(Relay3a, OUTPUT);
  pinMode(Relay4a, OUTPUT);
  
  strip.begin();
  strip.show();
  
}

void loop ()  { 
  buttonState0 = digitalRead(buttonPin0);//Keyfob D
  buttonState1 = digitalRead(buttonPin1);//Keyfob C
  buttonState2 = digitalRead(buttonPin2);//Keyfob B
  buttonState3 = digitalRead(buttonPin3);//Keyfob A 

 if (buttonState3 == HIGH) {

    digitalWrite(Relay1,HIGH);//Actuator Lift Segment Up
    delay(22000);
    digitalWrite(Relay1,LOW);    
  }
  
  while (millis() - start < 22000){//Should Run Knight Rider Bar for open duration
   loop(); {
    //Example: CylonEyeUp(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeUp(strip.Color(0,100,0), strip.Color(0,0,40), strip.Color(0,0,15), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
  //Example: CylonEyeDown(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeDown(strip.Color(0,100,0), strip.Color(0,0,40), strip.Color(0,0,15), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
    }
  }

  if (buttonState3 == LOW){
  }
  
  if (buttonState2 == HIGH) {
    
    digitalWrite(Relay2,HIGH);//
    delay(23000);
    digitalWrite(Relay2,LOW);
  }
  while (millis() - start < 23000){//SHould run Knight Rider Bar during close duration
   loop(); {
    //Example: CylonEyeUp(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeUp(strip.Color(0,100,0), strip.Color(0,0,40), strip.Color(0,0,15), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
  //Example: CylonEyeDown(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeDown(strip.Color(0,100,0), strip.Color(0,0,40), strip.Color(0,0,15), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
    }
  }
  
  if (buttonState2 == LOW);{
  }
  
  if (buttonState1 == HIGH) {
    
    digitalWrite(Relay1a, HIGH);//XBox Controller Tray
    delay(1000);
    digitalWrite(Relay1a, LOW);
    delay(10000);
    digitalWrite(Relay2a, HIGH);
    delay(1000);
    digitalWrite(Relay2a,LOW);
  }
  
  if (buttonState0 == HIGH){
    
    digitalWrite(Relay3a, HIGH);//Remote Control Tray
    delay(1000);
    digitalWrite(Relay3a, LOW);
    delay(10000);
    digitalWrite(Relay4a, HIGH);
    delay(1000);
    digitalWrite(Relay4a, LOW);
  }

}

void CylonEyeUp(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pStart) {
  for(int i=pStart; i<TotalPixels; i++) {
    if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } //Third Dot Color
    strip.setPixelColor(i+1, Ct);   //Second Dot Color
    strip.setPixelColor(i, Co);     //Center Dot Color
    strip.setPixelColor(i-1, Ct);   //Second Dot Color
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } //Third Dot Color

    if(!UsingBar) {
      strip.setPixelColor(i-3, strip.Color(0,0,0)); //Clears the dots after the 3rd color
    } else {
      strip.setPixelColor(i-2, strip.Color(0,0,0)); //Clears the dots after the 2rd color
    }
    strip.show();
    //Serial.println(i); //Used For pixel Count Debugging
    delay(Delay);
  }
}
void CylonEyeDown(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pEnd) {
  for(int i=TotalPixels-1; i>pEnd; i--) {
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } //Third Dot Color
    strip.setPixelColor(i-1, Ct);   //Second Dot Color
    strip.setPixelColor(i, Co);    //Center Dot Color
    strip.setPixelColor(i+1, Ct);  //Second Dot Color
    if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } //Third Dot Color

    if(!UsingBar) { 
      strip.setPixelColor(i+3, strip.Color(0,0,0)); //Clears the dots after the 3rd color
    } else {
      strip.setPixelColor(i+2, strip.Color(0,0,0)); //Clears the dots after the 2rd color
    }
    strip.show();
    //Serial.println(i); //Used For pixel Count Debugging
    delay(Delay);
  }
}


User avatar
cmckay
 
Posts: 30
Joined: Tue Nov 26, 2013 12:00 pm

Re: Relay Shield and NeoPixel Strip Warning Light

Post by cmckay »

A quick note: i know the led code works because i got that from another user and i ran it on its own to test the leds. I also know the relay and keyfob coding works because it currently is in use on the project. I think it's somewhere in the merging of the two codes that i screwed up.

Pins 0-3 are RF momentary inputs
Pins 4-11 are used to control the two relay shields (4-7 relay shield 1...... 8-11 are the second relay shield)
Pin 12 is reserved for the NeoPixel PWM
the Uno is powered via a power adapter

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Relay Shield and NeoPixel Strip Warning Light

Post by adafruit_support_bill »

You still have your 22 second delay. You need to replace that as shown above.

Code: Select all

 if (buttonState3 == HIGH) {

    digitalWrite(Relay1,HIGH);//Actuator Lift Segment Up
    delay(22000);
    digitalWrite(Relay1,LOW);    
  }
Not sure what the intent of this was, you have a recursive call to loop().

Code: Select all

  while (millis() - start < 22000){//Should Run Knight Rider Bar for open duration
   loop(); {

User avatar
cmckay
 
Posts: 30
Joined: Tue Nov 26, 2013 12:00 pm

Re: Relay Shield and NeoPixel Strip Warning Light

Post by cmckay »

oh i see, i misunderstood..i thought you meant to have another loop using the millis() to run the neopixel code. you intended for me to replace all of the "delay()'' with the millis() call. I need to rewrite the whole time portion to use millis() and not use delay().


Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”