Switching

Hello I’m new to arduino and I’m trying to develop a project as follows:
I want to be able to use momentary push buttons to latch 64 switches low or high by alternate pushes of the button.

I want to store and recall any combination of the button states into 99 memory stores via store / recall buttons
I need to select any memory store up and down again with up / down buttons and display to a two digit LED display.
I need a connection diagram…I suspect using the shift in shift out approach, and I need to know how to program this…anyone out there that can help ??

I need to know what programming you have done on this so far. I need to know how the switches will be wired.

Not just him we all need to know this.

YOU need to read ALL of the how to use this forum sticky post for advice on how to ask a question correctly.

Note we give advice here we do not write code for you.

Are the switches real switches?- as in physical things that you click? Not sure how a push button (which is presumably a different physical artefact from the switch) could latch a switch. Or is the switch more of a "flag", a simple binary memory location, a boolean variable, that's stored as on or off?

You could store the state of the switches in a loooong number where each bit is a switch, then store 99 versions of that. But I think the longest Arduino variable is 32 bits.

Meantime have a look at this.

No the longest is 64 bits, a long long variable type.

Grumpy_Mike: No the longest is 64 bits, a long long variable type.

Ok, I'll have to take your word for that Mike (as always...) since I don't see that listed.

edit... tested and yep long long compiles. Where's that documented?

The project requires physical push button (momentary switches) to latch outputs high or low on alternate pushing of the switch.

No code has been written yet…I have no idea how to start…just needed a nod in the right direction :)

The nod is to google the words addressable latch

There are a few and they can be combined to give you the number of outputs you require.

Other words to google are Port expander

These can do the same sort of thing.

latchkeykid: The project requires physical push button (momentary switches) to latch outputs high or low on alternate pushing of the switch.

Did you look at the buton state change code I linked to?- get your mind round that, is my opinion.

latchkeykid: The project requires physical push button (momentary switches) to latch outputs high or low on alternate pushing of the switch.

Hi, when you say "requires", is that design really being imposed on the design, and if so, why and by whom? Or is it the only way you could think of to achieve what you need?

I would suggest an easier approach would be to use a pot to "dial up" the switch number to be altered, or dial up the memory slot number to be recalled/saved.

If 64 switches are definitely a requirement, then an 8x8 matrix would be the easiest way. You could use a single 74hc595 shift register to drive the columns and 8 Arduino inputs to read the rows of the matrix.

Rather than your led display, I would suggest a character lcd. This would allow more helpful prompts for the user while they are using the device. If you chose a slightly more expensive 20x4 size lcd, there would be room to display the states of all 64 relays, either current or saved in a memory slot. For example:

----*---*-------    
-----------**---    
-***------------ Mem
----------------  43

Paul

Is the "centipede shield" a solution I could stack two ???

latchkeykid: Is the "centipede shield" a solution I could stack two ???

It says on the link you gave:

The IDC connectors will be tall enough to prevent stacking in most cases, so the Centipede shield should be the top device on an Arduino stack.

So you can't stack them with each other, or with any other shield that needs to be on the top of the stack, like an lcd sheld.

I'm going to simplify my request.

I want 64 physical momentary switches to light 64 individual Leds. Is the shift in / shift out approach going to work ???

latchkeykid: I'm going to simplify my request.

I want 64 physical momentary switches to light 64 individual Leds. Is the shift in / shift out approach going to work ???

Yes, it could be made to work. But there are simpler, better ways.

Assuming you want to use the maximum possible shift registers, you will need 8 shift-in registers and 8 shift-out registers. 16 chips, 64 led series resistors, 64 switch pull-up resistors, plus the Arduino.

Alternatively use a single max7219 chip to drive the leds and 16 arduino inputs to read the switches.

Here is one way to read the switches (handles single pushes):

Root_1.pdf (32.5 KB)

hello still experimenting :slight_smile:

I’m using a mcp23017 expander 8 buttons on the A port and 8 LED’s on the B port. I am using the sketch below…. with this sketch the buttons only light the led’s momentarily (whilst the button is held).

What do I need to add to get the led to stay on and go off with the second switch push (i.e a latched toggle) Iv’e looked at button states but I don’t know how to incorporate into the sketch ?? :slight_smile:

……………….

void setup()
{
Wire.begin(); // wake up I2C bus
Wire.beginTransmission(0x20);// Connect to chip
Wire.write((byte)0x01); // Select Bank B
Wire.write((byte)0x00); // Set all of bank B to outputs
Wire.endTransmission(); // Close connection
}

void loop()
{
// Read the inputs of bank A
Wire.beginTransmission(0x20); // Connect to chip
Wire.write(0x12); // Set Memory Pointer to Bank A
Wire.endTransmission(); // Close connection
Wire.requestFrom(0x20, 1); // Request one Byte
a=Wire.read(); // Put the Byte into variable ‘a’

// Write the Byte to Bank B
Wire.beginTransmission(0x20); // Connect to chip
Wire.write(0x13); // Set Memory Pointer to Bank B
Wire.write(a); // Write the Byte
Wire.endTransmission(); // Close connection

delay(100); // Small delay to debounce switch
}

How to use this forum Please read this:- How to use this forum Because your post is breaking the rules about code posting.

Sorry :)

Iv'e looked at button states but I don't know how to incorporate into the sketch ?? :)

SWITCH

Switch

This example demonstrates the use of a pushbutton as a switch: each time you press the button, the LED (or whatever) is turned on (if it's off) or off (if on). It also debounces the input, without which pressing the button once would appear to the code as multiple presses.

Cool ..but how does that merge with the code I posted ? :)