Terminate Return()

Hi everyone. I am a beginner in arduino field. I’m working on a bluetooth RGB controller.

I want to sent 'W' to HC-05 to run "Dimmer Function" and it will always run the function until it receive any other character.

The problem is, HC-05 did't response any character while in dimmer function.

I need Ur help … thanks :slight_smile:

Code:

#include <SoftwareSerial.h>
SoftwareSerial BLU(2,3);
#define redPin 5
#define greenPin 6
#define bluePin 9
char Incoming_value = 0;

void setup()
{
Serial.begin(9600);
BLU.begin(9600);
pinMode(13, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

setColor(255, 0, 0);
delay(500);
setColor(0, 255, 0);
delay(500);
setColor(0, 0, 255);
delay(500);
setColor(255, 255, 255);
delay(500);
setColor(0, 0, 0);
}

void loop()
{
if(BLU.available() > 0)
{
Incoming_value = BLU.read();
Serial.print("Incoming_value = ");
Serial.println(Incoming_value);

switch (Incoming_value)
{
 case 'r':
 setColor(255, 0, 0);
 break; 

 case 'w':
 dimmer();
 break;
}

}
}

void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

void dimmer()
{
unsigned int rgbColour[3];
rgbColour[0] = 255;
rgbColour[1] = 0;
rgbColour[2] = 0;

for (int decColour = 0; decColour < 3; decColour += 1)
{
int incColour = decColour == 2 ? 0 : decColour + 1;

for(int i = 0; i < 255; i += 1) 
{
  rgbColour[decColour] -= 1;
  rgbColour[incColour] += 1;
  setColor(rgbColour[0], rgbColour[1], rgbColour[2]);
  delay(5);
}

}
return dimmer();
}

OF course it didn't because you never ask for any in the dimmer function.

Paul

@syahmishy, please read How to get the best out of this forum and next apply what you've read / learned about code tags to the code in your post. It makes the code easier to read and copy and prevents that the the forum software mangles the code.

void dimmer()
{
  ...
  ...
  
  return dimmer();
}

Never use recursion (calling a function directly or indirectly from within the function itself) unless you know what you're doing and handle the limitations; you will run out of memory in no time.

...also, you can't return the value that a void function or expression doesn't provide