Go Down

Topic: problem with rgb controlling function (Read 270 times) previous topic - next topic

aurelio33

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.

Code: [Select]
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);   
 }
}
 

slipstick

I can't tell what SensorBlinker is intended to do. The code doesn't make any sense to me. There's no real timing in it and you can't blink anything by just turning all LED colours off. The line '   -SensorBlinkTimer' doesn't do anything at all. Can you describe in words what that function is supposed to do?

BTW why are you doing digitalWrite(Pin, 255)? digitalWrite() takes HIGH or LOW. It might work because usually anything other than 0 counts as HIGH, but it's really odd programming.

Steve

aurelio33

im trying to make a function that programs an rgb with simply 3 arguments. now im trying to make another function that makes the led blink alternatively from off to green when the sensor doesnt detect gas

Go Up