Go Down

Topic: Changing led sequence with buttons (Read 348 times) previous topic - next topic

Nsewell

I was wondering if any anyone could help me, I have an array of LEDs that I would like to animate however I want to have 4 buttons which change the led's animation. I was unsure of the best way to do this. I was thinking of having the buttons change a variable when pressed and then a Switch case check what the variable is.

HazardsMind

#1
Nov 21, 2012, 01:32 pm Last Edit: Nov 21, 2012, 01:35 pm by HazardsMind Reason: 1
You may be able to set the output as a byte and when a button is pressed it changes the byte being outputed.

Button1: byte:01010101
Button2: byte:00110011
Button3: byte:11001100
Button4: byte:10101010

Im not sure if the I/O pins can be turned on like that, or not, but it is worth a try as opposed to:
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
digitalWrite(led4,LOW);  and so on.

try sending out a byte and see if it works.

Actually im curious as to see if:
digitalWrite(0AAA,HIGH); //0AAA = 0000|1010|1010|1010 as a 13 pin byte
I doubt it will work but, it would nice if it did.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

holmes4

Post your existing code. If you haven't already look at blink without delay and button debouncing.

Mark

HazardsMind

Wait I for got something, it would be 0x0AAA not just 0AAA.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Go Up