Go Down

### Topic: Newbie Question (Read 812 times)previous topic - next topic

#### Darwin74

##### Jun 28, 2010, 11:14 pm
I am creating an LED bouncing ball effect with 10 LED's set up as an array, bouncing from 9 - 0 - 8 - 0 ...... and want to use a simple method of coding the last highest LED (-1) as the maximum 'bounce point' and then returning to 0 and so on. I am unsure of how to most effectively use the minus sign.

I did have success using the following code to get the LED to bounce from LED 10 back to 0 and then to 9:

Code: [Select]
`void changeLED() {  // turn off all LED's  for (int x=0; x<10; x++) {    digitalWrite(ledPin[x], LOW);  }  // turn on the current LED  digitalWrite(ledPin[currentLED], HIGH);  // increment by the direction value  currentLED += direction;  if (currentLED == 0) {direction = 1;}  if (currentLED == currentLED1) {direction = -1;}`

with int currentLED = 9
int currentLED1 = 8

However, trying to use this principle any futher does not seem to work.

Any help would be appreciated.

#### drhex

#1
##### Jun 29, 2010, 08:11 amLast Edit: Jun 29, 2010, 08:14 am by drhex Reason: 1
well, if the limits are 0 and currentLED1 ("maxLED" might be less confusing), then let currentLED start somewhere between those extremes or you might "bounce" outside the allowed range.

#### Darwin74

#2
##### Jun 30, 2010, 10:40 pm
Thanks for that, makes sense.

I will give it a shot and report back.