Hello everybody,
First, i am french, so my english is not very correct, please be tolerant with it.
I am making a small project witch consist to control some additional lights on a motorbike depending of the ambient light conditions and the lighting mode selected.
The problem is, it take too much time to switch from a mode to another (almost a second approx). To me it is annoying...
To make it i used an arduino Fio with an xbee series 1 for wireless programming. I also add a thermal sensor for security but the function is not achieved.
I pick some programm parts from ladyada for the light and thermal sensors, the rest is homemade.
//Configuration du thermomètre TMP36
int sensorPin = 1; //TMP36 branché sur l'entrée analogique 1
//Résolution 10 mV / degree centigrade avec
// un offset de 500 mV pour les temperatures negatives
//Configuration du capteur de luminosité
int photocellPin = 0; // La cellule et la résistance de 5k1 sont branchées sur a0
int photocellReading; // La lecture analogique
int LEDpin = 3; // Transistor branché sur la pin 3 (PWM pin)
int LEDbrightness; // Variable du PWM
//Configuration des entrées sorties
int PharesCroisement = 4; // Variable d'entrée du phare de croisement
int PharesRoute = 5; // Variable d'entrée du phare de route
int PharesAntiBrouillard = 6; // Variable d'entrée du bouton du phare antibrouillard
int PharesDetresse = 7; // Variable d'entrée des phares de detresse
int PharesAntiBrouillardArriere = 8; // Variable de sortie du phare antibrouillard arrière
void setup()
{
Serial.begin(57600); //Démarrage de la connection série
pinMode(LEDpin, OUTPUT); //Déclaration du transistor en sortie
pinMode(PharesCroisement, INPUT); //Déclaration de l'entrée
pinMode(PharesRoute, INPUT); //Déclaration de l'entrée
pinMode(PharesAntiBrouillard, INPUT); //Déclaration de l'entrée
pinMode(PharesDetresse, INPUT); //Déclaration de l'entrée
pinMode(PharesAntiBrouillardArriere, OUTPUT); //Déclaration de la sortie
}
void loop()
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 3.3;
voltage /= 1024.0;
// print out the voltage
Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
//Lecture de la cellule photosensible
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(LEDbrightness); // la valeur de sortie PWM
delay (200);
//now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
//Cas en plein phare
if (digitalRead(PharesRoute) == HIGH)
{
analogWrite(LEDpin, 255);
}
//Cas antibrouillard
else if (digitalRead(PharesAntiBrouillard) == HIGH)
{
analogWrite(LEDpin, 255);
digitalWrite (PharesAntiBrouillardArriere, HIGH);
}
//Cas phares de détresse
else if (digitalRead(PharesDetresse) == HIGH)
{
analogWrite(LEDpin, 255);
delay (100);
analogWrite(LEDpin, 25);
delay (800);
}
//Cas en phare de croisement
else
{
analogWrite(LEDpin, LEDbrightness);
}
}
It would be really nice if someone can explain to me why it takes too much time to switch from an if statement to another ![]()