Go Down

Topic: LED is dim when lit from first if statement? (Read 814 times) previous topic - next topic

XOIIO

Apr 03, 2013, 07:45 am Last Edit: Apr 03, 2013, 07:49 am by XOIIO Reason: 1
Alright, so after all to long and help from many forum members I have this sketch working, however I have encountered something weird.

First, here is the LED portion of the sketch.
Code: [Select]

void loop()                   
{
  long total1 =  cs_1_2.capacitiveSensor(30);
  if (total1 > 500) {
    counter = counter +1;
    delay(5000);
  }
  if (counter == 1) {
    digitalWrite(led1, LOW);
  }
  else {
    digitalWrite(led1, HIGH);
  }
  if (counter == 2) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
  }
  else {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
  }
}


As you can see, I have the first LED set to turn on when the counter is 1, and that works, but it is very very dim. If I make the counter hit 2, both LED's light up at full brightness.

I have tried other LEDs, and adding a loop that did nothing if the counter was 0 but that did not help, so, what is the cause of this?

Also, I do have both LED's pins set as output.

XOIIO

Ahh, figured it out, and changed the code, now it works fine!

Code: [Select]

#include <CapacitiveSensor.h>


CapacitiveSensor   cs_3_4 = CapacitiveSensor(3,4);
int led1 = 0;
int led2 = 1;
int led3 = 2;
int counter = 0;


void setup()                   
{
  cs_3_4.set_CS_AutocaL_Millis(0xFFFFFFFF);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
}


void loop()                   
{
  long total1 =  cs_3_4.capacitiveSensor(30);
  if (total1 > 500) {
    counter = counter +1;
    delay(5000);
  }
  if (counter ==0) {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
  }
  if (counter == 1) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
  }
  if (counter == 2) {
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, HIGH);
  }
  if (counter == 3) {
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
}
}

Go Up