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

Trying to get a button to make a continuous fade in/out sequence, and another button to turn it off. #470

Open
chickenboi12 opened this Issue Jul 11, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@chickenboi12

chickenboi12 commented Jul 11, 2017

I can get it to turn on with one button, but will only run once and then stop. I'm not sure how to get it to run continuously. Any input would be appreciated.

#include <FastLED.h>

#define NUM_LEDS 32
#define ledPin 3

CRGB led[NUM_LEDS];
int d = 10;
int repeat = 0;
int buttonApin = 9;
int buttonBpin = 7;

byte leds = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);  
  pinMode(buttonBpin, INPUT_PULLUP);  
  FastLED.addLeds<NEOPIXEL, ledPin>(led, NUM_LEDS);
  for (int r = 0; r < NUM_LEDS; r++)  {
    led[r] = CRGB(255, 0, 0);
  }

  FastLED.show();

  
  for (int o = 0; o < NUM_LEDS; o++)  {
    led[o] = CRGB(0, 0, 0);
  }

  FastLED.show();
}





void setBlack(int val) {
  for (int o = 0; o < NUM_LEDS; o++)  {
    led[o] = CRGB(0, 0, 0);
  }
  FastLED.show();
}

void setRed(int val) {
  for (int r = 0; r < NUM_LEDS; r++)  {
    led[r] = CRGB(val, 0, 0);
  }
  FastLED.show();
}



void loop() {
{
  if (digitalRead(buttonApin) == LOW)
  {
    digitalWrite(ledPin, HIGH);
  red();
  
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    digitalWrite(ledPin, LOW);
    for (int o = 0; o < 256; o++) {
    setBlack(o);
    delay(5);
  }
    
  }
}
}

 void red(){
  if (repeat <=10){
    fade();
  }
  else {
    for (int o = 0; o < 256; o++) {
    setBlack(o);
    delay(5);
    }
  }
  repeat = 0;
  return repeat;
  setup();
 }
 
  
void fade() {
 for (int r = 0; r < 256; r++) {
    setRed(r);
    delay(d);
  }
   for (int r = 255; r > 0; r--)  {
    setRed(r);
    delay(d);
   }
  repeat = repeat + 1;
  return repeat;
 
}
@jasoncoon

This comment has been minimized.

Show comment
Hide comment
@jasoncoon

jasoncoon Jul 11, 2017

Contributor

The Issues list here is for issues/bugs with FastLED. For assistance with your own code, please post to the FastLED community on G+: https://plus.google.com/u/0/communities/109127054924227823508

Contributor

jasoncoon commented Jul 11, 2017

The Issues list here is for issues/bugs with FastLED. For assistance with your own code, please post to the FastLED community on G+: https://plus.google.com/u/0/communities/109127054924227823508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment