Advise needed for shift registers and programming buttons on it with hold and multi press

i want to make a custom midi keyboard with 3 pcbs's of 12 buttons each connected to 1 arduino or teensy 4.1

which shift registers should i use?
could someone give me a link about the decoupling cappacitors? this isnt yet clear for me

read allot about the SN74HC165N is this a good choice?
https://playground.arduino.cc/Code/ShiftRegSN74HC165N/

Look at the first page of this: SNx4HC165 8-Bit Parallel-Load Shift Registers datasheet (Rev. H) (ti.com)

link about the decoupling capacitors: Add 100 nF ceramic and 4,7 uF to Vcc. Values are not critical.

hi thank you for your respons
i have some 220μF 10V Capacitor electrolytic laying around
would this suffise you think?

im not quit understanding your ceramic and uf ?
do i choose ore do i set them serial (i think not?)

Each IC gets its own .1µF ceramic capacitor across VCC - GND.

@dougp WOAW this is just what i needed
The information is soooo good and understandable

I found this one a coupler of times and very interesting:

For low-power ICs 10nF capacitors may be sufficient and may be preferred over the 100nF because of their lower internal inductance. For this reason you also find 10nF parallel to the 100nF. In this case the smaller capacitor should be closest to the pins.

Do you know if its done a lot?
Would it benifit if i put them as close as possible to My shift registers?
Do you have a link where you buy your cappzcitors?

If i measure with adc and the value of the voltage is constant, can i conclude that the cappacitors is doing its work?

Still one little question, my teensy is also powered with a 5v 15amp powersupply, should i also put 10nf (and 100 in parallel) as closet to those pins?

Most people just use one .1µF.

Absolutely, that is the goal.

thanks @dougp

i think this will do: https://www.tinytronics.nl/shop/en/components/capacitors/100nf-50v-ceramic-capacitor ??

@

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

hi i understand your remark but i like to keep things a littlbe bit seperated, my previous questions was more about the cappaitors and not the code

@anon57585045 i dont quiet understand your key state advise? im just joining now al the puzzle items to cvheck if my goal is achievable
could you give me an example code

the code i started fgrom is this one:


74HC165 Shift Register Demonstration 1
  74hc165-demo.ino
  Read from 8 switches and display values on serial monitor

  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/

// Define Connections to 74HC165

// PL pin 1
int load = 7;
// CE pin 15
int clockEnablePin = 4;
// Q7 pin 7
int dataIn = 5;
// CP pin 2
int clockIn = 6;

void setup()
{

  // Setup Serial Monitor
  Serial.begin(9600);

  // Setup 74HC165 connections
  pinMode(load, OUTPUT);
  pinMode(clockEnablePin, OUTPUT);
  pinMode(clockIn, OUTPUT);
  pinMode(dataIn, INPUT);
}

void loop()
{

  // Write pulse to load pin
  digitalWrite(load, LOW);
  delayMicroseconds(5);
  digitalWrite(load, HIGH);
  delayMicroseconds(5);

  // Get data from 74HC165
  digitalWrite(clockIn, HIGH);
  digitalWrite(clockEnablePin, LOW);
  byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
  digitalWrite(clockEnablePin, HIGH);

  // Print to serial monitor
  Serial.print("Pin States:\r\n");
  Serial.println(incoming, BIN);
  delay(200);
}

how could i "convert" the incoming decimal to a working key state for all my buttons? because now you get just ones and zeros in return of the shift registry

many thanks for your help!

Yes, find a key press library that offers short press, long press and similar options. Study it, and apply the same logic to the shift register code.

I misinterpreted "hold and multi press" in the title. Usually that is to obtain more functions from a key, like on a wristwatch. Now I see you're making a midi keyboard. That doesn't need short and long press detection, it only requires switch contact debounce.

So please write the sketch and post it, then we'll help you debounce the switches. We'll need to see a schematic too. Please post a genuine hand or CAD schematic, not a Fritzing artwork.

The switch logic for a serialized digital source is not substantially different from that which samples individual I/O ports. The only difference really, is that you have to read them differently. Once you have the current switch state in a variable, everything is the same.

Yes. I've seen that exact type on commercial boards.

Hi aarg

Maybe i exlain a little bith more
I have x number of switches
They should be sending indeed midi buth:

  • single click is just a midi note on and like 100 Mil sec note off sended
    -hold is also a midi note sended buth cannot be release EG the note off cant be send (for example smoke machine activating press and hold is smoke, release stops smoke
    -the double tap is eventually Not needed anymire

I have the code for shift registers how to Get in a decimaal like 11110 which key is activated
Buth i dont understand the link to making a keys from a decimaal who has al the keys in it?
I understand debouncing Ive done it in a previous project buth i dont understand how to make this "key object" from a decimaal who contains al the keys

Could you help me with this Braun twister?
Would be very appreciatied!

It is not a brain twister. It's just a typical program application. You just need to study the problem and code it.

If you don't know how, you need to follow a genuine learning path by writing a lot of simpler sketches, a lot of simpler projects, to get up to speed on how things are done.

This is a self help forum, not a please give me the code forum.

Also, I asked you for a schematic. I don't see any.

Then please post it.

You can isolate a particular bit with something like bitRead.

I Will post everything tonight for you, schematic with the teensy, the code,.... Pleas be patiënt for this, and thank you for the help

hi @anon57585045

you asked for schematic and code wel here it is :slight_smile:

74HC165 Shift Register Demonstration 1
  74hc165-demo.ino
  Read from 8 switches and display values on serial monitor

  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/

// Define Connections to 74HC165

// PL pin 1
int load = 7;
// CE pin 15
int clockEnablePin = 4;
// Q7 pin 7 //
int dataIn = 5; 
// CP pin 2
int clockIn = 6;

void setup()
{

  // Setup Serial Monitor
  Serial.begin(9600);

  // Setup 74HC165 connections
  pinMode(load, OUTPUT);
  pinMode(clockEnablePin, OUTPUT);
  pinMode(clockIn, OUTPUT);
  pinMode(dataIn, INPUT);
}

void loop()
{

  // Write pulse to load pin
  digitalWrite(load, LOW);
  delayMicroseconds(5);
  digitalWrite(load, HIGH);
  delayMicroseconds(5);

  // Get data from 74HC165
  digitalWrite(clockIn, HIGH);
  digitalWrite(clockEnablePin, LOW);
  byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
  digitalWrite(clockEnablePin, HIGH);

  // Print to serial monitor
  Serial.print("Pin States:\r\n");
  Serial.println(incoming, BIN);
  delay(200);
}

so i ca read the incoming but i dont know how i could change those bits to the object buttons?

so i started searching and reading on the bitrate item you sended and found this link about the button object

this part i found interesting

*/
Button::Button(uint8_t buttonPin, uint8_t buttonMode){
	pin=buttonPin;
  pinMode(pin,INPUT);
  
	buttonMode==BUTTON_PULLDOWN ? pulldown() : pullup(buttonMode);
  state = 0;
  bitWrite(state,CURRENT,!mode);
  
  cb_onPress = 0;
  cb_onRelease = 0;
  cb_onClick = 0;
  cb_onHold = 0;
  
  numberOfPresses = 0;
  triggeredHoldEvent = true;
}

is there a way i could change the pinmode to number of the shift register pin (eg A,B,C,D,E,F)?
i can split the results, the actual 6 states of all the buttons, in single states eg 6 ints for example.
So the state i can put intthis button but how about the pinmode (which is the link where the button is physically attached to) how can i make this link to the virtual shift register number for example?
if i can do this than i think i can make it work :wink:

im feeling im coming close, just a little push is needed i think :slight_smile:
making the button object based on the shift register number will be the key i think :slight_smile:
any help would be grately appreciated!

btw i forget to draw the 0.1uF ceramic cappacitor between gnd and vin saa close to the shifter, my bad

update did some more diggin about bitrade

x: number from which = that would be the shift register
n: which bit = that would be the button

so could id be that i just let the shift register constantly update
and do for each button that i make a class from; do something like:

button1.updateButton(bitRead(adress of shifter, 1);
button2.updateButton(bitRead(adress of shifter, 2);
...
button6.updateButton(bitRead(adress of shifter, 6);

stil a bit stuk on the adress of the shifter now, could i use the dataIn pin that i postedf from my previous post (post 19) code where the date in pin is = 5 ?

so the code woulde be:

74HC165 Shift Register Demonstration 1
  74hc165-demo.ino
  Read from 8 switches and display values on serial monitor

  DroneBot Workshop 2020
  https://dronebotworkshop.com
*/

// Define Connections to 74HC165

// PL pin 1
int load = 7;
// CE pin 15
int clockEnablePin = 4;
// Q7 pin 7 //
int dataIn = 5; 
// CP pin 2
int clockIn = 6;

void setup()
{

  // Setup Serial Monitor
  Serial.begin(9600);

  // Setup 74HC165 connections
  pinMode(load, OUTPUT);
  pinMode(clockEnablePin, OUTPUT);
  pinMode(clockIn, OUTPUT);
  pinMode(dataIn, INPUT);
}

void updateAllButtons(){

//todo declare the buttons first in setup

button1.updateButton(bitRead(dataIn, 1));
button2.updateButton(bitRead(dataIn, 2));
button3.updateButton(bitRead(dataIn, 3));
button4.updateButton(bitRead(dataIn, 4));
button5.updateButton(bitRead(dataIn, 5));
button6.updateButton(bitRead(dataIn, 6));

}

void loop()
{

  // Write pulse to load pin
  digitalWrite(load, LOW);
  delayMicroseconds(5);
  digitalWrite(load, HIGH);
  delayMicroseconds(5);

  // Get data from 74HC165
  digitalWrite(clockIn, HIGH);
  digitalWrite(clockEnablePin, LOW);
  byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
  digitalWrite(clockEnablePin, HIGH);

  // Print to serial monitor
  Serial.print("Pin States:\r\n");
  Serial.println(incoming, BIN);
updateAllButtons();
  delay(200);
}