I've just started learning how to use an Arduino as I have a home project i'm making which i'm a little stuck on.
Its a small LED lamp that i want to be controlled by a capacitive sensor using the <CapacitiveSensor.h> library.
I'm trying to make it have a few functions but can't work out how to do it. Below are the functions.
Functions
one tap on capacitive sensor to turn light on - gradual pwm ramp up to full brightness. OR gradual pwm ramp up to previous before light was last switched off.
one tap on capacitive sensor to turn light off - gradual pwm ramp to zero brightness.
If light is on. Double tap capacitive sensor to toggle between 3 different brightnesses. (low, 143) (Medium, 191) (High, 255)
This feels like a simple task, and i've tried using some of the examples to get it to work but can't get a hang of it
If someone could help me out with this I would massively appreciate it.
I've never used such a sensor. What does it return? I see in the example with the library that it prints some value, and I guess that varies as the hand approaches and or taps the sensor?
So I surmise there's a value under (or over? I don't know which way it works) you deem it "hit". (In the same way a digital switch goes from 0 to 1 or 1 to 0, or a pot on an analog pin would goe from above to below, or below to above, some defined threshold?)
So first have you reliably got it displaying some value?
I would be inclined to read the sensor and use a boolean variable (say myCapSensor) according to some threshold, so if the read value is above that, myCapSensor is high, else it's low.
Then you could use the method in the state change detect tutorial to detect a change from high to low or low to high (whichever way round it works) and call that a "tap".
Maybe you're past that stage though: impossible to say, since you gave no indication what your actual problem is, nor did you post your code so far.
Side note... how would one tap know which of these you mean:
one tap on capacitive sensor to turn light on - gradual pwm ramp up to full brightness. OR gradual pwm ramp up to previous before light was last switched off.
Or do you mean the first time it's ever used, go to full bright, and subsequently go to the previous value?