hey guys.
i am new here on this platform and i already checked out some topics but i did not really found something about my problem.
i have an rgb led and one button and an arduino (uno, nano, ...). i want to press the button and then the mode changes between my different programs. like mode=0 is all leds are off. mode=1 just blue. mode=2 just green. mode=3 just red. mode=4 smooth change between all colors.. and so on
i found a video on youtube of a guy who makes some mushrooms out of silicon, with an led included. i want to use a rgb led and a an arduino to control pwm colors. i want to use an arduino nano. the boards will arrive soon.
i dont have any program to give u my electric scheme, but so far all different colors and the buttons are working, so dont mind.
my sourcecode is following:
int mode = 0; // Beim Start LED aus
int rotPin = 9;
int blauPin = 10;
int grunPin = 11;
int buttonPin = 7;
void setup() {
pinMode(blauPin, OUTPUT); // LED Blau
pinMode(grunPin, OUTPUT); // LED Gelb
pinMode(rotPin, OUTPUT);
pinMode(buttonPin, INPUT); // Signal - Taster
}
boolean buttonPressed() // Taster abfragen auf drücken des Buttons
{
static boolean lastButtonState;
boolean buttonState=digitalRead(buttonPin);
if (buttonState!=lastButtonState) // Status hat sich geändert
{
lastButtonState=buttonState; // letzten Status merken
if (buttonState==HIGH) return true; // Status hat sich auf "gedrückt" geändert
}
return false;
}
void loop() {
switch(mode){
case 0:
while(mode==0){
analogWrite(rotPin,255);
analogWrite(grunPin,255);
analogWrite(blauPin,255);
if (buttonPressed()){
mode++;
delay(5);}
}
break;
case 1:
while(mode==1){
analogWrite(rotPin,30);
analogWrite(grunPin,30);
analogWrite(blauPin,10);
if (buttonPressed()){
mode++;
delay(5);}
}
break;
case 2:
while(mode==2){
analogWrite(rotPin,255);
analogWrite(grunPin,255);
analogWrite(blauPin,30);
if (buttonPressed()){
mode++;
delay(5);}
}
break;
delay(5);
}
i hope u can help me out. it should not be to difficult but i dont get any solution myself and i am searching now for about a week.
i tried links like:
http://forum.arduino.cc/index.php?topic=273438.0
but in this explaination there are just three modes and the 'solution sourcecode' is to complicated for my simple programming knowledge. they differ just between on, off and blinking. i dont want to use commands like onmode and offmode and so on because i dont know how to handle them. of course its easier and you could give me a solution like this.
i have allready written some while loops for changing the colors smoothly or do some color changing blink or something like that and i would be happy to use my own code. but i just dont know how to set the switch-case to give the button the command to change the mode.
i also have some potentiometers programmed to change the indensity of the different colors
i would be really happy if you give me some help or some links to check out. of course it can be that i missed some topics where they already discussed problems, like those that i have.