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 ??
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.
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
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.
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 ??
……………….
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
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.