Go Down

Topic: LilyPad Constellation Troubleshooting (Read 775 times) previous topic - next topic

emilypyatt

Hey, I'm relatively new to lilypad (and coding!), I'm trying to create a panel (which will eventually go into a tote bag) in which different constellations light up as the light level changes. I've included my code below, my four constellations are made of B+C+D+E , A+B+C+D, C+E+FGH, and B+FGH with each letter being an LED connected to its own pin. I'm using a 5v powerbank into the LilyPad USB , but my project doesn't seem to be working. Could anyone offer any advice?

const int darkLevel1 = 10;
const int darkLevel2 = 25;
const int darkLevel3 = 50;
const int darkLevel4 = 100;

int lightValue;

int sensorPin = A2;

int ledPinA = 4;
int ledPinB = 5;
int ledPinC = 6;
int ledPinD = 7;
int ledPinE = 8;
int ledPinFGH = 9;


void setup()
{
    pinMode(sensorPin, INPUT);

    pinMode(ledPinA,OUTPUT);
    pinMode(ledPinB,OUTPUT);
    pinMode(ledPinC, OUTPUT);
    pinMode(ledPinD,OUTPUT);
    pinMode(ledPinE, OUTPUT);
    pinMode(ledPinFGH,OUTPUT);


    Serial.begin(9600);
}

void loop()
{
 
    lightValue = analogRead(sensorPin);

    Serial.print("Light value is:");
    Serial.println(lightValue);

    if ( lightValue >= darkLevel3 && lightValue <= darkLevel4) // between 75 and 100
    {
        digitalWrite(ledPinB, HIGH);
        digitalWrite(ledPinC, HIGH);
        digitalWrite(ledPinD, HIGH);
        digitalWrite(ledPinE, HIGH);// Turn on LED
    }
    else
    {
        digitalWrite(ledPinB, LOW);
        digitalWrite(ledPinC, LOW);
        digitalWrite(ledPinD, LOW);
        digitalWrite(ledPinE, LOW);
    }
     
      if ( lightValue >= darkLevel2 && lightValue <= darkLevel3) // between 50 and 75
    {
        digitalWrite(ledPinA, HIGH);
        digitalWrite(ledPinB, HIGH);
        digitalWrite(ledPinC, HIGH);
        digitalWrite(ledPinD, HIGH);// Turn on LED
    }
    else
    {
        digitalWrite(ledPinA, LOW);
        digitalWrite(ledPinB, LOW);
        digitalWrite(ledPinC, LOW);
        digitalWrite(ledPinD, LOW);
    }
     
      if ( lightValue >= darkLevel1 && lightValue <= darkLevel2) // between 75 and 100
   
    {
        digitalWrite(ledPinC, HIGH);
        digitalWrite(ledPinE, HIGH);
        digitalWrite(ledPinFGH, HIGH);
    }
    else
    {
        digitalWrite(ledPinC, LOW);
        digitalWrite(ledPinE, LOW);
        digitalWrite(ledPinFGH, LOW);
    }
 
   
  if ( lightValue <= darkLevel1) // less than 25
 
    {
        digitalWrite(ledPinB, HIGH);
        digitalWrite(ledPinFGH, HIGH);
     
    }
    else
    {
        digitalWrite(ledPinB, LOW);
        digitalWrite(ledPinFGH, LOW);
    }

    delay(100);
   

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]// your code is here[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.


You're missing the closing brace at the end of your loop function. If you do an Auto Format and then look at the resulting indentation, it makes it easy to spot this type of bug.

freaklabs

Hi. I recommend going through the coding step by step and building to your final code. So make sure you can light each LED or constellation. Then add in the logic to light them according to the dark levels, and slowly progress to get what you want. It's important to isolate your code and logic, especially in an embedded system like this, to make the debugging easier.
Hope that helps.
FreakLabs
Wireless Technology for the environment, wildlife, and agriculture
https://freaklabs.org
https://hackerfarm.jp
Twitter: @freaklabs

Go Up