I am trying to use addressable LED's to show various piano scales using the semi notes formula for each scale as an array and an input to indicate the starting note.

int MajorScale[] = {2,2,1,2,2,2,1}; //represents the semi notes in a major scale
int t= 8 //represents the led number that represent the first C on the keyboard

The following leds should light up -

(8, 8+2, 8+2+2, 8+2+2+1, 8+2+2+1+2, 8+2+2+1+2+2, 8+2+2+1+2+2+2 , 8+2+2+1+2+2+2+1) // This is first C Major Scale on the Piano

so.. (8,10,12,13,15,17,19) // This is first C Major Scale on the Piano where 8 is the first c

Then light up all the other C Major scales available on the piano limited by the number of keys on the piano in this case 76 keys

As there are 12 notes for each octave , add this to the array

if i take just the C note

8, 8+12, 8+12+12 ,8+12+12+12, 8+12+12+12+12 etc

My code so far just lights up the semitone that i set up in the array

enter code here
#include "FastLED.h"
#define DATA_PIN 5
#define NUM_LEDS 76
#define BRIGHTNESS 10
int MajorScale[] = {2,2,1,2,2,2,1};
int delayValue = 1000;

void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

void loop() {
for(int i = 0; i <=6; i++)
    leds[MajorScale[i]] = CRGB::BlueViolet;  


  • 2
    And what is your question? What is the specific problem, that you have with coding the rest? – chrisl Nov 11 '19 at 19:51
  • How do i make this happen .. From the initial array {2,2,1,2,2,2,1} to the first set of LED lights (8,10,12,13,15,17,19) . I cannot visualize the formula that adds each element of the array to its next element. Feels like a running sum with an addition of a constant – Subash Nov 12 '19 at 14:25

Your current code will not show all notes of a scale. Only the notes at 1 and 2 will light up, since you don't sum up the numbers, that you have stored in MajorScale. But I think it is not a great idea to sum them up programatically, since this is a constant and you don't win much by representing the data this way. Instead you should directly initiate the MajorScale variable with the summed up values:

int MajorScale[] = {0, 2, 4, 5, 7, 9, 11};

Then you can enclose your for loop with another for loop, that adds an offset corresponding to the octave:

for(int j=0; j<NUM_LEDS; j+=12){
    for(int i=0; i<=6 && MajorScale[i]+j<NUM_LEDS;i++){
        leds[8+MajorScale[i]+j] = CRGB::BlueViolet;

So we set the LED number 8+MajorScale[i]+j. 8 for the offset to C, MajorScale[i] as the position of the note in the current octave and j for the offset of the current octave relative to the C.

Note, that this is not tested in any way.

| improve this answer | |
  • A fear you forgot to sum the MajorScale values. e.g. leds[MajorScale[ 0 ]+j] == leds[MajorScale[ 1 ]+j] are pointing to the same LED. And must also be an poffset of 6 for each j. IMHO ;-) – Peter Paul Kiefer Nov 12 '19 at 15:07
  • Ah, you are right. I got that mixed in my head. I will change the answer – chrisl Nov 12 '19 at 15:21
  • As I saw the edit, I realized that I did also a mistake. The idea of modyfing the MajorScale array is better than the offset of 6 (good idea).. I was wrong when I said that each j needs an offset of 6 This first MajorScale starts at LED no 8 but the second scale starts with the next LED; I guess. So if the first C is at LED 8 start with j=8 and add 0. The next LED is the D -> add 2 then E add 2 then F add 1 ... the next octave j++ the , 11} must be removed because j++ jumps to the next octave C where you add 0. and so on. Sorry for this "for each". Party fail ;-) – Peter Paul Kiefer Nov 12 '19 at 15:50
  • The position 11 corresponds to the B, which is still 1 half tone under the next octaves C. After that the number of i doesn't matter anymore, since the inner for loop wil exit. But I guess I should initialize i to zero in the for loop. – chrisl Nov 12 '19 at 16:00
  • If you've seen my last comment. I removed it because it was complete nonsense. You're right the code is correct. – Peter Paul Kiefer Nov 12 '19 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.