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?
#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