Schematic to breadboard layout

It sure is, must of spent about 6 hours over the past 2 days trying to figure out how to do this. I understand what you mean about that the 7 is 0111 which is the binary figure. but I’m not 100% sure what you mean about the polarity and which part of the code you are talking about. because normally 1 is on and 0 is off. Sorry about this, I have connected a rgb common cathode led. I have used 220 resistors on them, is that an okay value? or does each colour need to have a different value?

is the code in question which it looks like should be:

midi.write((byte)0x00);
bitClear(leds,2); /* turn on green led /
bitSet(leds, 1); /
turn off red led */
updateShiftRegister();

(the only change being on swapped for off in the comments). While it is true that in code usually (but not always) 1 is true or on and 0 is false or off, hardware is different. If your leds were common anode (which I think was initially the case and is likely still the case) then 1 is off (as both sides of the diode are at 5V and it isn’t lit) and 0 is on (the bottom of the resistor is 0V the anode of the led is 5V, current flows and light occurs). When you switch to common cathode leds the opposite will be true, the cathode connects to ground and when the shift register pin is 0 no current flows and the led is off, when the sr pin is high there is 5V on one end of the resistor and thus voltage and current through the led and the led is on. The software doesn’t actually care which is which, making it the easy place to make the change as you would have to change led types from common anode to common cathode in the hardware to make this change, and only a 1 to a 0 in a text file to do it in software. If you are indeed still using the red leds, it may be profitable to change to the common cathode ones as they are what you will eventually use (although as noted the change is only a 1 to a 0 in the software).

Peter

Alright thank you for the explanation, I’ve been playing about. Realised I forgot to change the lows back to highs and the highs back to lows. Because I’m not using the pedals at the moments. Just using a push button. It is almost working but there is something not quite right. I have the common cathodes connected now. it first lights up red then when the button is pressed flashes green when it should switch to green and stay lit. But if I continue to click the button it will switch from each colour every now and then. This is what I have got

#include <SoftwareSerial.h>
SoftwareSerial midi(0,1); ///RX TX

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int modebtn = 7;
byte leds = 0;

int toggle8 = 0;

int mode = 0;

void setup(){
leds = 0; /* set the leds initially all off */
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode (modebtn, INPUT_PULLUP);
midi.begin(31250);
}

void loop(){
if (digitalRead(modebtn) == HIGH && toggle8 == 0){
}
toggle8 = 1;
if(mode == 0){

midi.write(0x90);
midi.write(0x17);
midi.write(0x01);
// delay(300);
}

if(mode == 1){


  midi.write(0x90);
  midi.write(0x30);
  midi.write(0x01);
  //  delay(300);
}

if (digitalRead(modebtn) == LOW && toggle8 == 1){
toggle8 = 0;
if(mode == 0){
mode = 1;
midi.write(0x90);
midi.write(0x17);
midi.write((byte)0x00);
bitSet(leds, 7); /* turn on red led /
bitClear(leds, 6); /
turn off green led /
updateShiftRegister();
}
else if(mode == 1){
mode = 0;
midi.write(0x90);
midi.write(0x30);
midi.write((byte)0x00);
bitClear(leds, 7); /
turn off the red led /
bitSet(leds, 6); /
turn on the green led */
updateShiftRegister();}

}
}

void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}

Look back at the same code a couple of posts back and you will see that the way the { and } s should be arranged.

Peter

When I remove } underneath void loop(){ it comes up with the error updateShiftRegister was not declared in this scope

Likely one or more of those three } s needs to be deleted. Every { must have a matching } lower in the code. The ide normally indents correctly (the forum here screws with the indenting making it hard to debug). When it says updateShiftregister isn’t declared it means it found the ending } before it should have (likely because there is one too many of them).

Peter

It’s thrown up the same error message. So frustrating, It is probably the first one you mentioned and probably along with this one too. I know changes the format, link to the program https://www.dropbox.com/s/ciyr34zs6tzsi32/Button_shift_register_test.ino?dl=0

The code is too broken to fix. There are bits and pieces every where and several blocks that are incomplete with no information on what they should do to fix them. You likely need to start with the original code that was modified from (first making sure that compiles and runs) and make small changes and try and compile it (and stop and fix it when it doesn’t compile). It looks like you may need to find a basic tutorial on C (I expect there are a bunch if you google) so you understand the basic code blocks in C or you will likely not succeed.

Peter.

I mentioned it on the arduino forum, this is what a couple of people said "You need the same amount of { as }. The brackets around toggle=1 are probably wrong. Try to autoformat the source to make it better readable.

You need more discipline when you code. Computers are machines and use a syntax that has to be strictly adhered to.

you need to have the same amount of { as }. But moreover, they need to be placed correctly.

The usual way of placing brackets is the following: When starting a block (Something between brackets) Place the opening bracket at the end of the first line, indent the code inside the bracket, place the ending bracket alone one it’s line, at the same indentation than the start of the block.

Here is an example :
void myCode(int someParameter) {
for (i = 1 ; i<8 ; i++) {
analogWrite(13, someParameter)
}
}

Looking at the closing brackets, you know instantly to which block it belongs.

Rearange your code, and you will find the missing closing brackets. (The Arduino IDE is very helping in this task: when you select a bracket, it highlights it’s matching counterpart. Use this help.)

Moreover, know that updateShiftRegister() is a function that is used by your sketch. It is like a little helper that simplifies the code inside the loop() portion of your sketch, but is independent of the loop(). Think of it as giving a name to a piece of code that can be used over and over in the loop, without re-writing the same code each time. Therefore, it has to reside outside of the loop. Make sure that the closing bracket of the loop() is before the code for updateShiftRegister()." I had a play today. Don’t think I’m going to get this sorted because even if I did I’d then have to be able to program it somehow so the green does light up when track is play and also light up red when recording. Don’t think I’ll manage this. Going to probably have to keep it simple just have the peddles one LED and a screen. But I really don’t want to go down that route

The problem with the code you posted is that it isn’t a program, it is a series of unconnected fragments of C. Even if I could make it compile (which is doubtful) it wouldn’t do anything useful. The arduino environment is specifically aimed at new programmers so if you want to do this there is no reason you can’t learn if you are willing to invest the time to learn. In this case I think you have the midi code that you tried to modify in working form somewhere earlier to get the buttons to or from midi, if you start with that and add the code to light a single led with the shift register even if it only lights the led when the button is pushed and it then stays on for ever, you should form there be able to figure out how the code works and how to change it to do what you want. I haven’t actually looked at the arduino starting stuff because I already knew how to program micros in assembler or C but it is aimed at makers and artists who have never programmed before and thus must be able to teach someone inexperienced how. I isn’t easy though, no type of programming is.

Peter

Hello, long time since I have commented on here. I want to revive my project. Do you know anything about state changes?

What kind of state change? That would usually be an input pin going from 0 to 1 or 1 to 0 which needs to be detected to cause an action to occur (such as your button pushes).

Peter

Yeah so a when a button is pressed (depending on its state) it will light up either red for recording green for playing and off when idle

Yes that would be the state change. What do you need to know about it.? Generally there is a variable that remembers to last state. You compare the current value of the input port to the variable that remembers the last state and if they aren’t the same then a state change has taken place. As long as the state variable and the input port are the same you don’t do anything. When a change occurs you change the color of the leds (by writing the output port) to reflect the new state value, then update the state variable to record the new state (and possibly do other things that the new state requires). This is basically what your code is supposed to be doing.

Peter

You will most likely want to look at attaching the pin (using the correct pins is essential) to an interrupt and use an interrupt routine to determine button state and do the debouncing.

Something like this for an arduino.
void setup() { // Setup button pins pinMode(Button, INPUT); attachInterrupt(0, button_press, CHANGE); }
void button_press() { unsigned long Current_Millis = millis(); if (digitalRead(Button) == HIGH) { Button_HIGH_Time = Current_Millis; } else if (digitalRead(Button) == LOW && Current_Millis - Button_HIGH_Time > Debounce) { Button_HIGH_Time = 0; if (Current_Millis - Last_Button_Time < Double_Click_Time) { Last_Button_Time = Current_Millis; Double_Click = true; } else { Last_Button_Time = Current_Millis; } } }
The forum seems to remove all the indentation.

Yes, you need to use the preformatted text button (6th icon from the left in the reply menu), which is a pain even then as it wants a 4 space indentation, in order to get the formatting to be retained. Also I think he is likely too inexperienced to be able to use interrupts successfully. He has some polling code that almost works above but was having troubles modifying it when last we talked.

Peter

I tried that and it didn’t work. You will notice the grey boxes around my text. I think it is because I use Tab not spaces and it strips the tabs.

Well I have my program working with all the pedals, I now want to add the leds for certain track. That will either light up green or red. I went onto Reddit and got talking to someone who suggested using state changes to make the leds light the way I need them to when pedals are pressed in states. I’ve tried to look at tutorials about this. But can’t seem to find any tutorials with more than one button. I did a tutorial and used the led on the uno for every four times the button was pressed it would turn off. Just want to learn how to do it with multiple buttons, leds and to light the leds up red or green depending on the state

If you just want the LED on while the button is pressed and your button is high when pressed you only need this. If the button is low when pressed you will have to reverse the logic in the if statement.

If (digitalRead(button_pin) == HIGH) {
digitalWrite(led_pin, HIGH);
} else {
digitalWrite(led_pin, LOW);
}