Ciao a tutti,
Ho un problema con un progetto che sto svolgendo: sto cercando di cambiare l'intensità luminosa di un LED toccando il Capacitive sensor ( un foglio di metallo in questo caso) più volte: ovvero schiacciandolo la prima volta il Led dovrebbe avere una bassa intensità, la seconda volta più alta, la terza ancora di più, e alla quarta dovrebbe tornare spento.
Il problema é di sicuro nel codice, perché ho provato semplicemente ad accenderlo e spegnerlo con un codice più semplice e funziona bene.
Qualcuno riesce ad aiutarmi? Grazie
#include <CapacitiveSensor.h>
/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Uses a high value resistor e.g. 10M between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin - try different amounts of foil/metal on this pin
* Modified by Becky Stern 2013 to change the color of one RGB Neo Pixel based on touch input
*/
CapacitiveSensor capSensor = CapacitiveSensor(9,10);
int threshold = 900;
int threshold2 = 850;
int threshold3 = 800;
int threshold4 = 750;
int brightness = 0; // how bright the LED is
const int ledPin= 12;
unsigned long previousTime = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
long total1 = capSensor.capacitiveSensor(30);
unsigned long currentTime = millis();
Serial.println(total1);
analogWrite(ledPin, brightness);
if (total1 > threshold){
digitalWrite(ledPin, 50);
}
if (total1 > threshold2 && ledPin == 50 ){
(previousTime || currentTime);
digitalWrite(ledPin, 200);
}
if (ledPin == 200 && total1 > threshold3){
digitalWrite(ledPin, 255);
}
if (ledPin == 255 && total1 > threshold4){
digitalWrite(ledPin, 0);
}
delay(10); // arbitrary delay to limit data to serial port
}