have anyone ever build a switch button to control LED matrix?

i had built a 8x8 LED matrix
now i wanna do like 6 pre-programmed messages to store in the adruino chip
and i wanna build a switch button to switch between the messages
note: i have the program for 1 message already*
have anyone ever done something like that before, please help me with some ideas
thanks

here is what i built

If you really want to try it, you could have the arduino read in what position of the switch. assuming the switch has a seperate pin for each position or somethin like that. and then have it read in which position the switch is at and then upload a program that has if statements. like if switch == 3 { do this design}, else if switch ==4 {do other design}.

Like that sort of thing. it wouldn't' be too tough after you've solved the amount of pins issue.

Use a pushbutton like funkyguy says. Everytime it is pressed you add 1 to a counter, when it gets to 7 you reset to 1.

void loop(){
if (digitalRead(message_button)== 0 ){  // assumes input pin with internal pullup resistor, switched to ground
message_count = message_count +1;
if (message_count == 7){message_count = 1;}
}
switch (message_count){
case 1:
// message 1 code here
break;
case 2:
//mesage 2 code here
break;
:
:
case 6:
// message 6 code here
break;
}  // end switch
} // end void loop

It is a bit more complicated than that.
You would need to first define your messages in program memory, so they don't use your RAM.
That would be an array of strings, like this:

char* PROGMEM myMsg[7] = {"message 1", "message 2", ....};

After you figured you need to change the message (the button was pressed), you need to read the appropriate message, based on the counter (as previously suggested), something like that.

char crtChar = pgm_read_byte_near(&myMsg[message_count][charIndex]);

You read each character in a loop (since I don't know how long your messages are, I shouldn't assume you can read the whole message at once).

And this is just the beginning.

There is one other issue you have to think about: do you want to quit the current message once the button is pressed or you want the crt message to finish?

It is a bit more complicated than that.

florinc, thats what we are saying.
put it in the program so it doesn't use the RAM.
No its not difficult. If i had to, I could write a program that would go through pre-programmed messages like you want in like 10 min.

If i had to, I could write a program that would go through pre-programmed messages like you want in like 10 min.

I don't doubt that.
Writing code is easy. Making it work reliably is the part that I said is complicated :slight_smile:
On the other hand, we should spend 10 minutes helping a fellow hobbyist :slight_smile: Seriously, I am just kidding.

Well what you could do, since arduino has a pushbutton on it, you could use that. There are some example in the arduino programmer that work with the on board button. Like I said before, just use if and else if statements. If you want, I can write you a code for the pushbutton dealio and then put comments in with it. Since I don't know how you set it up and such, I can't write the whole thing. I can do it once I get back from the hospital if you like. Do you need help with any hardware? It looks as if youce got that part figured out.

The onboard reset pushbutton?
I suppose you could keep track in EEPROM, and everytime you reset you check the EEPROM value, update it, and then run the for the new value.

Yah i see there is a button on the adruino, it would be great if you can help me on the code for changing the message by using that button( i just need simple messages such as: help, hello, etc... i could change the message later),or do i have to build another button seperate from the adruino
im kinda bad on programming :stuck_out_tongue:
im truly appreciate for any help, comments from anyone

here is the code that i use to control the LED
thank guys

//– Columns (Negative Cathodes) –

int latchPin1 = 2; //Arduino pin connected to Green 10 RCK of TPIC6C595

int clockPin1 = 3; //Arduino pin connected to Yellow 15 SRCK of TPIC6C595

int dataPin1 = 4; //Arduino pin connected to Blue 2 SER IN of TPIC6C595
//– Rows (Positive Anodes) –

int latchPin2 = 5; //Arduino pinn connected to Green Latch 12 ST_CP / RCK of 74HC595

int clockPin2 = 6; //Arduino pin connected to Yellow Clock 11 SH_CP / SCK of 74HC595

int dataPin2 = 7; //Arduino pin connected to Blue Data 14 DS / SI of 74HC595
//=== B I T M A P ===

// 8 is # of rows, 73is # of LED matrix we have

byte bitmap[8][3]; // Change the 3 to however many matrices you want to use.

int numZones = sizeof(bitmap) / 8;

int maxZoneIndex = numZones-1;int numCols = numZones * 8;

//=== F O N T ===

// Font courtesy of aspro648

// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203747843/22

// First char is @, next is A, B, etc. Only lower case, no symbols.

// The @ will display as space character.

byte alphabets[][5] = {

{0,0,0,0,0},

{31, 36, 68, 36, 31},

{127, 73, 73, 73, 54},

{34, 65, 65, 65, 62},

{127, 65, 65, 34, 28},

{65, 65, 73, 73, 127},

{127, 72, 72, 72, 64},

{62, 65, 65, 69, 38},

{127, 8, 8, 8, 127},

{0, 65, 127, 65, 0},

{2, 1, 1, 1, 126},

{127, 8, 20, 34, 65},

{1, 1, 1, 1, 127},

{127, 32, 16, 32, 127},

{127, 32, 16, 8, 127},

{62, 65, 65, 65, 62},

{127, 72, 72, 72, 48},

{62, 65, 69, 66, 61},

{127, 72, 76, 74, 49},

{50, 73, 73, 73, 38},

{64, 64, 127, 64, 64},

{126, 1, 1, 1, 126},

{124, 2, 1, 2, 124},

{126, 1, 6, 1, 126},

{99, 20, 8, 20, 99},

{96, 16, 15, 16, 96},

{67, 69, 73, 81, 97},};

//=== S E T U P ===
void setup() {

Serial.begin(57600);

pinMode(latchPin1, OUTPUT);

pinMode(clockPin1, OUTPUT);

pinMode(dataPin1, OUTPUT);
pinMode(latchPin2, OUTPUT);

pinMode(clockPin2, OUTPUT);

pinMode(dataPin2, OUTPUT);

//– Clear bitmap –

for (int row = 0; row < 8; row++) {

for (int zone = 0; zone <= maxZoneIndex; zone++) {

bitmap[row][zone] = 0;

}

}

}
//=== F U N C T I O N S ===
// This routine takes whatever we’ve setup in the bitmap array and display it on the matrix

void RefreshDisplay()

{

for (int row = 0; row < 8; row++) {

int rowbit = 1 << row;

digitalWrite(latchPin2, LOW); //Hold latchPin LOW for as long as we’re transmitting data

shiftOut(dataPin2, clockPin2, MSBFIRST, ~rowbit); //Transmit data
//– Start sending column bytes –

digitalWrite(latchPin1, LOW); //Hold latchPin LOW for as long as we’re transmitting data
//– Shift out to each matrix (zone is 8 columns represented by one matrix)

for (int zone = maxZoneIndex; zone >= 0; zone–) {

shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);

}
//– Done sending Column bytes, flip both latches at once to eliminate flicker

digitalWrite(latchPin1, HIGH); //Return the latch pin high to signal chip that it no longer needs to listen for information digitalWrite(latchPin2, HIGH); //Return the latch pin high to signal chip that it no longer needs to listen for information

delayMicroseconds(500);//make it easier for us to see, you can change this number

}

}
// Converts row and colum to actual bitmap bit and turn it off/on

void Plot(int col, int row, bool isOn)

{

int zone = col / 8;

int colBitIndex = col % 8;

byte colBit = 1 << colBitIndex;

if (isOn)

bitmap[row][zone] = bitmap[row][zone] | colBit;

else bitmap[row][zone] = bitmap[row][zone] & (~colBit);}
// Plot each character of the message one column at a time, updated the display, shift bitmap left.

void AlphabetSoup(){char msg[] = “HELLO “;

for (int charIndex=0; charIndex < (sizeof(msg)-1); charIndex++)

{

int alphabetIndex = msg[charIndex] – ‘@’;

if (alphabetIndex < 0) alphabetIndex=0;

//– Draw one character of the message –

for (int col = 0; col < 7; col++)

{

for (int row = 0; row < 8; row++)

{

// Set the pixel to what the alphabet say for columns 0 thru 4, but always leave columns 5 and 6 blank.

bool isOn = 0;

if (col<5) isOn = bitRead( alphabets[alphabetIndex][col], 7-row ) == 1;

Plot( numCols-1, row, isOn); //The shift loop below will scroll it leftward.

}

//– The more times you repeat this loop, the slower the text scroll –

for (int refreshCount=0;refreshCount < 5; refreshCount++)

RefreshDisplay();

//– Shift the bitmap one column to left –

for (int row=0; row<8; row++)

{

for (int zone=0; zone < numZones; zone++)

{

bitmap[row][zone] = bitmap[row][zone] >> 1;

// Roll over lowest bit from the next zone as highest bit of this zone.
if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7, bitRead(bitmap[row][zone+1],0));

}

}

}

}

}
//=== L O O P ===
void loop() {

AlphabetSoup();

/* if (Serial.available() > 0) {

AlphabetSoup(Serial.read());

} */

}

i attached the schematic for the LED matrices in case you guys wanna know more about hardware

**note: blue lines are data input, green and yellow: clock and latch
red: hot, grey: neutral

Diagram for LED project 1.pdf (180 KB)

.............

Sorry.

I would recommend working with the example code named Pushbutton that is provided by arduino.
Since you can get through all that code and such, i'm sure you'll have no problem.
The pushbutton example code will show you how to use the onboard pushbutton to do certain things.
:slight_smile:

I use the reset button to switch modes for a LED display.

Multiple Modes | Blinkenlight.

For the full story you may want to also follow these links: