Neopixels Controlled by a Switch Errors

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
lewiscallaway
 
Posts: 17
Joined: Mon Jan 27, 2014 2:02 pm

Neopixels Controlled by a Switch Errors

Post by lewiscallaway »

I am trying to program a neopixel ring hooked up to my Arduino. I am trying to make it keep color wipe red when the button is pressed and have it stop when I press the button again. The code is below.

Code: Select all

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define     SWITCH              2     
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
///////////////////////////////////////////////////////
// Setup function
//
// Called once at start up.
///////////////////////////////////////////////////////
void setup(void){
   
  // Set up the input and output pins.
  pinMode(SWITCH, INPUT);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

///////////////////////////////////////////////////////
// Loop Function
//
// Called continuously after setup function.
///////////////////////////////////////////////////////
void loop(void) {
  if (ISBUTTONPRESSED()) {  
  colorWipe(strip.Color(255, 0, 0), 50);
  Serial.print("Switch Pressed");
  delay(5000);
  
  }
  else{
    strip.show();
  }

///////////////////////////////////////////////////////
// ISBUTTONPRESSED function
//
// Returns true if the switch is pressed. 
///////////////////////////////////////////////////////
boolean ISBUTTONPRESSED() {
 //check switch status
  if (digitalRead(SWITCH) == LOW) {
    return false; // Switch Isn't Pressed, return false.
  }
{
  return true; // Switch is pressed, return true.
}
}



// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();
     
      delay(wait);
     
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
        }
        strip.show();
       
        delay(wait);
       
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, 0);        //turn every third pixel off
        }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

I am getting the following errors:

Code: Select all

sketch_aug01b.ino: In function 'void loop()':
sketch_aug01b:39: error: a function-definition is not allowed here before '{' token
sketch_aug01b:133: error: expected `}' at end of input
What else do I need to do to the code to make this work?? Thanks!

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: Neopixels Controlled by a Switch Errors

Post by Franklin97355 »

Read this http://playground.arduino.cc/Code/Function and look at some of THESE that should help.

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

Return to “Arduino”