hello guys im doing a gas detector that controls an led based on the output of the sensor, im having a bit of trouble with the function sensor blinker, that is a decorative function that makes the led blink when its not detecting anything, but it seems it doesnt work and the led is still on the green. other aspects of the project work fine.
int SogliaSensore = 200;
int PinLedRosso = 2;
int PinLedBlu = 4;
int PinLedVerde = 7;
int Buzzer = 8;
int Timer = 5;
void setup() {
pinMode (PinLedRosso, OUTPUT);
pinMode (PinLedBlu, OUTPUT);
pinMode (PinLedVerde, OUTPUT);
pinMode (Buzzer, OUTPUT);
pinMode (A3, INPUT);
Serial.begin(9600);
}
void loop() {
SensorBlinker();
int SensorValue = analogRead (A3);
if (SensorValue < SogliaSensore) {
Serial.print ("Sensor: ");
Serial.println ("Gas quantity detected is negligible");
digitalWrite (Buzzer, LOW);
Timer = 0;
RGB_controller (0, 0, 255);
}
else
{
RGB_controller (255, 0, 0);
Serial.print ("Sensor: WARNING! Gas Quantity detected is ");
Serial.println (SensorValue);
digitalWrite (Buzzer, HIGH);
Timer = 5;
SensorValue = analogRead (A3) - Timer;
}
delay(100);
}
void RGB_controller (int Luminosita_rosso, int Luminosita_blu, int Luminosita_verde) {
digitalWrite( PinLedRosso, Luminosita_rosso);
digitalWrite( PinLedBlu, Luminosita_blu);
digitalWrite( PinLedVerde, Luminosita_verde);
}
void SensorBlinker () {
int SensorBlinkTimer = 5;
int SensorBlink = 5;
SensorBlink = SensorBlink + SensorBlinkTimer;
if (SensorBlink < 5 || SensorBlink > 150) {
-SensorBlinkTimer;
}
if (SensorBlink < 5 || SensorBlink > 150) {
RGB_controller (0, 0, 0);
}
}