Pages: 1 [2]   Go Down
Author Topic: Reading button instantly  (Read 1974 times)
0 Members and 1 Guest are viewing this topic.
Central Wisconsin
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
return(RightStrip.Color(r,g,b));
  return(LeftStrip.Color(r,g,b));
Hmm

???
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26218
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
???
That's exactly what I thought too.
Logged

"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.

Central Wisconsin
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)?
Logged

Central Wisconsin
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26218
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"?
Logged

"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.

Central Wisconsin
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int dumb(int a, int b)
{
   if(a < b)
      return -1;
   else
      return +1;
}

Code like:
Code:
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.
Logged

Central Wisconsin
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Central Wisconsin
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: