Go Down

Topic: Reading button instantly (Read 2 times) previous topic - next topic

joey2point0


Code: [Select]
return(RightStrip.Color(r,g,b));
  return(LeftStrip.Color(r,g,b));

Hmm


???

AWOL

Quote
???

That's exactly what I thought too.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

joey2point0



I am not very familiar with that.

Familiar with what? EEPROM? It's not complicated at all and there are examples you can look at that will explain it.


See i am a total noob, i understand the concept of what you are trying to say, i just am terrible at programming. i tried looking at the examples but i still do not understand. 

PaulS

Look at your Wheel() function. What happens when the first return statement is executed? How many values can you return from a function (using the return statement)?

joey2point0


Look at your Wheel() function. What happens when the first return statement is executed? How many values can you return from a function (using the return statement)?


im sorry, i have no idea what you are talking about

AWOL

Quote
Look at your Wheel() function.

You have a function in the code you posted called "Wheel". Look at it.

Quote
What happens when the first return statement is executed?

At the end of the function you are looking at are two statements containing the word "return".
What happens when your sketch executes the first of those "return"s?

Why doesn't it matter if there is or isn't a second "return"?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

joey2point0

I have two different LED strips hooked up to the arduino, the left one and right one. does that awnser it?

Arrch


See i am a total noob, i understand the concept of what you are trying to say, i just am terrible at programming. i tried looking at the examples but i still do not understand. 


If the examples that they provide are too difficult to understand to you, then there is nothing I could do to help short of writing the code for you.

PaulS

Quote
I have two different LED strips hooked up to the arduino, the left one and right one. does that awnser it?

No. The return keyword says "stop executing code at this point, and return this value to the caller". The function can have multiple return statements, but that only makes sense if one of them is in a conditional block, like so:
Code: [Select]
int dumb(int a, int b)
{
   if(a < b)
      return -1;
   else
      return +1;
}


Code like:
Code: [Select]
int dumb(int a, int b)
{
   // Do some stuff
   return -1;
   return +1;
}

doesn't make sense, but, that is what you have. The function is supposed to return a value, or it is declared wrong. Two unconditional returns don't make sense.

joey2point0

I took one of the Return() functions out and it seems to work the same.

PaulS

Quote
I took one of the Return() functions out and it seems to work the same.

Does that surprise you? The other one was never being executed, anyway. Removing it should have had no impact.

joey2point0

lol, it makes sense now, but back to my real problem. is there an easy way for the push-button to be read consistently, even while the other cycles are running. and be able to stop them mid cycle and switch

PaulS

Quote
is there an easy way for the push-button to be read consistently, even while the other cycles are running. and be able to stop them mid cycle and switch

Sure. Rewrite the code, first, so it does not use delay(). Then, it will be trivial to read the switch and react nearly instantaneously.

If you are having difficulty getting rid of the delay calls, think about how YOU would diddle with the LEDs, given some switches, a watch, and a pad of paper. The switches are the digital pins, the watch is the millis() function, and the pad of paper are the Arduino variables.

Go Up