hello hello,
I'm sorry i'm french , even if i hope i have a good english tell me if you don't understand me.
I expose you my problem :
I'm trying to do a sensor lamp, if you touch a piezo sensor, you increase a LED strip in 5 step.
The code is fine for it. The real problem is to fade my led step by step .
I found lot of exemple to fade a led, but it's always to fade it from 0 to 255, i need to fade from 0 to 50, after from 50 to 100 ...
Here is the code without any fade (sorry the description is in french)
int PIEZO = A0; // Piezo branché sur la pin analog A0
int LED = 11; //Led branchée sur la pin PWM 11
int PIEZOReading; //Lit les valeurs analog du piezo
int PIEZOCompteur = 0; // Compte le nombre de caresse
void setup() {
Serial.begin(9600); // Envoi de message de déboggage sur connexion série
pinMode(LED, OUTPUT); // Configure la led en sortie
pinMode(PIEZO, INPUT); // Configure le Piezo en entrée
}
void loop() {
PIEZOReading = analogRead(PIEZO); //lit la valeur de mon piezo
if (PIEZOReading>7){ //A chaque fois que mon piezo dépasse 7 je rajoute +1 à mon compteur
PIEZOCompteur=PIEZOCompteur+1;
delay(500); //Je met un delay sinon mon compteur va augmenter trop vite (si c'est le cas augmente le)
}
if(PIEZOCompteur>9) { // "si j'ai fais mes 9 caresses pour augmenter diminuer l'intensité mon compteur revient a 0 "(=led éteintes)
PIEZOCompteur = 0; //Remet mon compteur à 0 lorsqu'il dépasse 9 pour recommencer le cycle
}
switch (PIEZOCompteur){ // déclare les luminosité pour les différentes caresses (case1=caresse1, case2=caresse2...)
case 0:
digitalWrite (LED,LOW);
delay (100);
break;
case 1:
analogWrite (LED,50);
delay (100);
break;
case 2:
analogWrite (LED,100);
delay (100);
break;
case 3:
analogWrite (LED,150);
delay (100);
break;
case 4:
analogWrite (LED,200);
delay (100);
break;
case 5:
analogWrite (LED,255);
delay (1000);
break;
case 6:
analogWrite (LED,200);
delay (100);
break;
case 7:
analogWrite (LED,150);
delay (100);
break;
case 8:
analogWrite (LED,100);
delay (100);
break;
case 9:
analogWrite (LED,50);
delay (100);
break;
}
Serial.print("nb de coups PIEZO = ");
Serial.print(PIEZOCompteur); // permet de lire le nombre de caresses dans le moniteur série
Serial.print("\t");
Serial.print("PIEZO reading = ");
Serial.println(PIEZOReading); // permet de lire les valeurs analogiques du Piezo (0-1023) dans le moniteur série
}
I have an other pb :
I want to use a led stripe 24V warm white, i have a rgb shiel but i don't know what kind of alimentation i need because i tried with 24v and it didn't work. Maybe it's my connexion is bad. Do you know any exemple like that i can refer?
I'm not sorry to be french, i'm just sorry for my language errors (it happens^^)
What values ARE you reading from the sensor? A threshold of 7 seems pretty low.
about the value of the sensor , 7 is really low but it's perfect for me, and it's working
i'm hidding the piezo sensor under a textile, i'm doing a senor lamp with textile and we need to press the textile 5 time to increase the intensity of the led stripe and 5 time to turn off the light .
Why can't you change the limits of the for loop?
I tried with :
switch (PIEZOCompteur){ // déclare les luminosité pour les différentes caresses (case1=caresse1, case2=caresse2...)
case 0:
digitalWrite (LED,LOW);
delay (100);
break;
case 1:
for (int i = 0; i < 50; i++){
analogWrite (LED,50);
delay (100);
}
But it's not working
i know i have to do it like in the exemple for - Arduino Reference but i don't know what i'm doing wrong and i use de for loop badly.
for (int i = 0; i < 50; i++){
analogWrite (LED,50);
delay (100);
}
The difference between that for loop and the one that goes from 0 to 255 is not in the for statement. It is in the fact that each time through the loop you write the same value to the pin. Write the value of i to the pin, not the constant 50.
Hello Hello i'm back,
Actually i didn't use thé serial.print , and by using it i realized that my LED was constantly writing something around 20. The LEDMax is around 529 and the LEDMin was around 12 . Do you know why it's like that while the analog values of the led should be between 0 and 255 ? How do i calibrate it?
Here is the code
ps : thank you a lot, I'm getting better ising arduino thanks to you!
int PIEZO = A0; // Piezo branché sur la pin analog A0
int LED = 5; //Led branchée sur la pin PWM 11
int PIEZOReading; //Lit les valeurs analog du piezo
int PIEZOCompteur = 0; // Compte le nombre de caresse
int LEDValue;
void setup() {
Serial.begin(9600); // Envoi de message de déboggage sur connexion série
pinMode(LED, OUTPUT); // Configure la led en sortie
pinMode(PIEZO, INPUT); // Configure le Piezo en entrée
}
void loop() {
PIEZOReading = analogRead(PIEZO); //lit la valeur de mon piezo
LEDValue = analogRead(LED); //lit la valeur de mon piezo
if (PIEZOReading>7){ //A chaque fois que mon piezo dépasse 7 je rajoute +1 à mon compteur
PIEZOCompteur=PIEZOCompteur+1;
delay(500); //Je met un delay sinon mon compteur va augmenter trop vite (si c'est le cas augmente le)
}
if(PIEZOCompteur>9) { // "si j'ai fais mes 9 caresses pour augmenter diminuer l'intensité mon compteur revient a 0 "(=led éteintes)
PIEZOCompteur = 0; //Remet mon compteur à 0 lorsqu'il dépasse 9 pour recommencer le cycle
}
switch (PIEZOCompteur){ // déclare les luminosité pour les différentes caresses (case1=caresse1, case2=caresse2...)
case 0:
digitalWrite (LED,LOW);
delay (100);
break;
case 1:
analogWrite (LED,50);
delay (100);
break;
case 2:
analogWrite (LED,100);
delay (100);
break;
case 3:
analogWrite (LED,150);
delay (100);
break;
case 4:
analogWrite (LED,200);
delay (100);
break;
case 5:
analogWrite (LED,400);
delay (1000);
break;
case 6:
analogWrite (LED,200);
delay (100);
break;
case 7:
analogWrite (LED,150);
delay (100);
break;
case 8:
analogWrite (LED,100);
delay (100);
break;
case 9:
analogWrite (LED,50);
delay (100);
break;
}
Serial.print("nb de coups PIEZO = ");
Serial.print(PIEZOCompteur); // permet de lire le nombre de caresses dans le moniteur série
Serial.print("\t");
Serial.print("PIEZO reading = ");
Serial.println(PIEZOReading);
Serial.print("LED LUMINOSITE = ");
Serial.println(LEDValue); // permet de lire les valeurs analogiques du Piezo (0-1023) dans le moniteur série
}