Go Down

Topic: Arduino Lily Pad and FLORA RBG NeoPixels (Read 769 times) previous topic - next topic

ardandfun

I have sewn  8 NEOPixels to fabric coming off of one pin on Lily Pad. I have also sewn the ground and power (different pins) with conductive thread. As far as my code I am getting an error message "green led was not declared in this scope"  see below

int greenLEDPin=3;     // Declaring greenLEDPin as an int, and set it to 3
int redOnTime=900;     // This is the red  LED ontime
int redOffTime= 400;    // This is the red LED offtime
int  greenOnTime=900;    //  This is greenLED ontime
int greenOffTime=400;    // This is green LED offtime
int  blueOnTime=900;   // This is blue LED ontime
int  blueOffTime=400;  // This is blue LED offtime
int redLEDPin=3;   // Declaring redLEDPin as an int, and set it to 3
int blueLEDPin=3;   //  Declaring blueLEDPin as an int and set it to 3








void setup() {
 
 
   pinMode(greenLED,OUTPUT);
   pinMode(redLED,OUTPUT);
    pinMode(blueLED,OUTPUT);
 

}

void loop() {
  digitalWrite(redLED,HIGH); // Turn the red LED on
  delay(redOnTime); 
  digitalWrite(redLED,LOW);
  delay(redOffTime);
  digitalWrite(greenLED,HIGH);
  delay(greenOnTime);
  digitalWrite(greenLED,LOW);
  delay(greenOffTime);
  digitalWrite(blueLED,HIGH);
  delay(blueOnTime);
  digitalWrite(blueLED,LOW);
  delay(blueOffTime);
 
 

}


Still learning. Not sure if this is correct? Any help is welcomed.

uxomm

#1
May 13, 2018, 12:02 am Last Edit: May 13, 2018, 12:13 am by uxomm
If you are really using NEOPixels, this code can not be used to control it (even without erros).
Controling NEOPixels works quite different.
Take a look at the tutorials on the adafruit webpage and learn how to control NEOPixels - here are some (and there are many more):
https://learn.adafruit.com/flora-rgb-smart-pixels?view=all
https://learn.adafruit.com/close-encounters-hat?view=all
https://learn.adafruit.com/neopixel-coat-buttons?view=all


If you are using "normal" sewable LEDs instead of NEOPixels, you need an individual pin for every LED and the code should look more like this:
Code: [Select]
int greenLEDPin = 3; 
int redLEDPin   = 4;
int blueLEDPin  = 5; 

int redOnTime    = 900;  // This is the red  LED ontime
int redOffTime   = 400; 
int greenOnTime  = 900;
int greenOffTime = 400;
int blueOnTime   = 900;
int blueOffTime  = 400; 

void setup() {
  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin,   OUTPUT);
  pinMode(blueLEDPin,  OUTPUT);
}

void loop() {
  digitalWrite(redLEDPin, HIGH); // Turn the red LED on
  delay(redOnTime);
  digitalWrite(redLEDPin, LOW);
  delay(redOffTime);
  digitalWrite(greenLEDPin, HIGH);
  delay(greenOnTime);
  digitalWrite(greenLEDPin, LOW);
  delay(greenOffTime);
  digitalWrite(blueLEDPin, HIGH);
  delay(blueOnTime);
  digitalWrite(blueLEDPin, LOW);
  delay(blueOffTime);
}

You have to use the same names for variables all the time, but not "redLEDPin" in the beginning and "redLED" later.
But as mentioned earlier, this code will _not_ work with NEOPixels, but with normal LEDs only.
Always decouple electronic circuitry.

ardandfun


ardandfun

Yes, NEO pixels with Arduino Lily Pad. I did have FLORA but I was getting confused with the 6 and 9 pins so I changed to LilyPad.

Go Up