Go Down

Topic: capacitive sensor (Read 533 times) previous topic - next topic

hilukasz

I'm trying to get my capacitive sensor to turn the brightness of an LED up and down. It is giving me the correct output 0-255 because I have debugged it.

when I set:

analogWrite(lightPin, newVal);

to:
analogWrite(lightPin, 128);

it gives it about half brightness, which is correct. So I am very confused why the variable wont translate to brightness. any ideas?

Code: [Select]
#include <CapSense.h>

CapSense cSensor(4,2);


int lightPin = 13;
int buttonPin = 3; 

void setup() {
 
    Serial.begin(9600);
    pinMode(lightPin, OUTPUT);
    pinMode(buttonPin, INPUT);
}

void loop() {

    int val = digitalRead(buttonPin);
    long sensor = cSensor.capSense(30);

    long newVal = (sensor/1000)*20;
    Serial.print(newVal);
    Serial.print(", ");
      analogWrite(lightPin, newVal);   
    if (newVal < 255 && newVal > 20 && val == 0 ) {

    } else {
      digitalWrite(lightPin, LOW);  // turn LED OFF
    }
}


there is also a button too in case you're wondering, and yes it is on :)
for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

AWOL

Try using one of the pins that supports analogWrite.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

robtillaart

try it without the if, it can set the LED allways off (too fast to see)

Code: [Select]

void loop() {

    int val = digitalRead(buttonPin);
    long sensor = cSensor.capSense(30);

    long newVal = (sensor/1000)*20;
    Serial.print(newVal);
    Serial.print(", ");
      analogWrite(lightPin, newVal);   
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

hilukasz


Try using one of the pins that supports analogWrite.


doh. that was it. totally forgot some pins don't support analog signals. thanks.
for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Go Up