Programming question, best approach for fretboard leds (guitar)

Hello all,

I am a bit of a newby, especially with this programming language. I can accomplish what I want but I want it a little bit smarter and I hope you can direct me to an example that does exactly that, one that is understandable for me.

I used the code below from an example, I have leds on my guitar and now I want guitar scales to light up. In the code below I have few key's but this way I have to define every led separately.

Basically there is a system in this, suppose I declare the key of C somewhere and then I add 8 to the index each time (because thats how I made the leds, 8 per fret and I waist the 2 latest pins of the shift register so I don't have to think about that now)

So can I store the key of C, add 8 to the index and show it (it will be the key of C#) and then use the same key of C and add 16 (it will be the key of D) then add 24 and it will be the key of D#

By the time I get to the 12th fret all will repeat so from there I can automise the whole thing right? or is this too complicated..

Suppose I make an array of the key of C, then how do store it and add 8 using the approach below?

Thanks!!

int SER_Pin = 8;   //pin 14 on the 75HC595
int RCLK_Pin = 9;  //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 11 on the 75HC595

//How many of the shift registers - change this
#define number_of_74hc595s 4 

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

void setup(){
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();
}               


//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}


//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

void loop(){

  setRegisterPin(1, HIGH); // this is the key of C!
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(10, HIGH);
  setRegisterPin(11, HIGH);
  setRegisterPin(12, HIGH);
  setRegisterPin(17, HIGH);
  setRegisterPin(18, HIGH);
  setRegisterPin(19, HIGH);
  setRegisterPin(21, HIGH);
  setRegisterPin(22, HIGH);
  setRegisterPin(28, HIGH);
  //setRegisterPin(2, LOW);
  //setRegisterPin(10, LOW);
  writeRegisters();  
  delay(2000);
  clearRegisters();
  
  setRegisterPin(1, HIGH); //C#
  setRegisterPin(2, HIGH);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(9, HIGH);
  setRegisterPin(13, HIGH);
  setRegisterPin(14, HIGH);
  setRegisterPin(18, HIGH);
  setRegisterPin(19, HIGH);
  setRegisterPin(20, HIGH);
  setRegisterPin(25, HIGH);
  setRegisterPin(26, HIGH);
  setRegisterPin(27, HIGH);
  setRegisterPin(29, HIGH);
  setRegisterPin(30, HIGH);
  writeRegisters();
  delay(2000);
  clearRegisters();
  
  setRegisterPin(9, HIGH); //D
  setRegisterPin(10, HIGH);
  setRegisterPin(11, HIGH);
  setRegisterPin(12, HIGH);
  setRegisterPin(13, HIGH);
  setRegisterPin(14, HIGH);
  setRegisterPin(17, HIGH);
  setRegisterPin(21, HIGH);
  setRegisterPin(22, HIGH);
  setRegisterPin(26, HIGH);
  setRegisterPin(27, HIGH);
  setRegisterPin(28, HIGH);
  writeRegisters();
  delay(2000);
  clearRegisters();

  setRegisterPin(1, HIGH); //D#
  setRegisterPin(2, HIGH);
  setRegisterPin(3, HIGH);
  setRegisterPin(4, HIGH);
  setRegisterPin(5, HIGH);
  setRegisterPin(6, HIGH);
  setRegisterPin(17, HIGH); 
  setRegisterPin(18, HIGH);
  setRegisterPin(19, HIGH);
  setRegisterPin(20, HIGH);
  setRegisterPin(21, HIGH);
  setRegisterPin(22, HIGH);
  setRegisterPin(25, HIGH);
  setRegisterPin(29, HIGH);
  setRegisterPin(30, HIGH);
  writeRegisters();
  delay(2000);
  clearRegisters();
    
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.