Hi, I am new to programming and all stuff. I thought of a project with arduino and RGB led strips.
Here's what I thought:
-Android controls Arduino through BT module
-3 modes in RGB lighting -- 1) Mood Light Mode - Color changes slowly
2) User Mode - User decides the color of the strip
3) Music Reaction Mode - Reaction to music
-Android App controls the functions
Moreover, I am trying to make a new fuction void moodlight(), and it says
"a function-definition is not allowed here before '{' token"
I am unable to understand this.
Here's my code for moodlight:
void mood()
{
#define DELAY_TIME 500
#define MAX_BRIGHT 255
#define PIN_RED 9
#define PIN_GREEN 10
#define PIN_BLUE 11
int red = 0;
int green = 170;
int blue = 170;
int incR = 1;
int incG = 1;
int incB = 0;
void transition()
{
if (red >= MAX_BRIGHT)
incR = 0;
else if (red <= 0)
incR = 1;
if (green >= MAX_BRIGHT)
incG = 0;
else if (green <= 0)
incG = 1;
if (blue >= MAX_BRIGHT)
incB = 0;
else if (blue <= 0)
incB = 1;
if (incR)
red++;
else
red--;
if(incG)
green++;
else
green--;
if(incB)
blue++;
else
blue--;
}
void setColor()
{
analogWrite(PIN_RED, red);
analogWrite(PIN_GREEN, green);
analogWrite(PIN_BLUE, blue);
}
void setup()
{
}
void loop()
{
transition();
setColor();
delay(DELAY_TIME);
}
}
Please post the whole code
All your functions seem to be declared inside the mood() function; you can not declare a function inside another function; you can only call it.
#define DELAY_TIME 500
#define MAX_BRIGHT 255
#define PIN_RED 9
#define PIN_GREEN 10
#define PIN_BLUE 11
int red = 0;
int green = 170;
int blue = 170;
int incR = 1;
int incG = 1;
int incB = 0;
void setup()
{
...
...
}
void loop()
{
transition();
setColor();
delay(DELAY_TIME);
}
void transition()
{
...
...
}
void setColor()
{
...
...
}
void mood()
{
...
...
}
Please use code tags instead of quote tags when posting code or error messages.
[code] your code here [/code] will result in
your code here
I have started this project today itself, only coded the mood light part. Will do the rest afterwards. Thanks for help. But I want a single command, through which I can execute the whole moodlight part, rather to type the whole code again and again. Its like I want to declare the moodlight thing as a function or command, and when conditions are fulfilled it will start the moodlight.
mood() is a function. You can call it from anywhere. Let's say you have a button that goes low when you press it and that will start the moodlight mode.
void loop()
{
if(digitalRead(yourButton) == LOW
{
mood();
}
else
{
...
...
}
}
void mood()
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
}
The above mood() simply switches the onboard LED on for 500ms (on an Uno) and is called when the button is pressed. Your mood() will be more complicated.