how can i make code simpler cause right now its using a lot of storage

hi so im trying to make a piano of sorts but im running into in issue where figuring out what note to play is taking up a lot of space so im wondering if there was some way to decrease the size of the code to allow more storage?
here's the code to figure out what note im playing.

if (octive == 1) {
       //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C1);
    if (total2 > 500) tone(buzzer1,NOTE_D1);
    if (total3 > 500) tone(buzzer1,NOTE_E1);
    if (total4 > 500) tone(buzzer1,NOTE_F1);
    if (total5 > 500) tone(buzzer1,NOTE_G1);
    if (total6 > 500) tone(buzzer1,NOTE_A1);
    if (total7 > 500) tone(buzzer1,NOTE_B1);
    if (total8 > 500) tone(buzzer1,NOTE_C2);
    
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS1);
    if (total10 > 500) tone(buzzer1,NOTE_DS1);
    if (total11 > 500) tone(buzzer1,NOTE_FS1);
    if (total12 > 500) tone(buzzer1,NOTE_GS1);
    if (total13 > 500) tone(buzzer1,NOTE_AS1);
    }

    //octive 2
    
    if (octive == 2) {
       //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C2);
    if (total2 > 500) tone(buzzer1,NOTE_D2);
    if (total3 > 500) tone(buzzer1,NOTE_E2);
    if (total4 > 500) tone(buzzer1,NOTE_F2);
    if (total5 > 500) tone(buzzer1,NOTE_G2);
    if (total6 > 500) tone(buzzer1,NOTE_A2);
    if (total7 > 500) tone(buzzer1,NOTE_B2);
    if (total8 > 500) tone(buzzer1,NOTE_C3);
    
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS2);
    if (total10 > 500) tone(buzzer1,NOTE_DS2);
    if (total11 > 500) tone(buzzer1,NOTE_FS2);
    if (total12 > 500) tone(buzzer1,NOTE_GS2);
    if (total13 > 500) tone(buzzer1,NOTE_AS2);
    }

    // octive 3

    if(octive == 3) {
    
    //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C3);
    if (total2 > 500) tone(buzzer1,NOTE_D3);
    if (total3 > 500) tone(buzzer1,NOTE_E3);
    if (total4 > 500) tone(buzzer1,NOTE_F3);
    if (total5 > 500) tone(buzzer1,NOTE_G3);
    if (total6 > 500) tone(buzzer1,NOTE_A3);
    if (total7 > 500) tone(buzzer1,NOTE_B3);
    if (total8 > 500) tone(buzzer1,NOTE_C4);
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS3);
    if (total10 > 500) tone(buzzer1,NOTE_DS3);
    if (total11 > 500) tone(buzzer1,NOTE_FS3);
    if (total12 > 500) tone(buzzer1,NOTE_GS3);
    if (total13 > 500) tone(buzzer1,NOTE_AS3);
    }

    //octive 4
    
    if (octive == 4) {
       //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C4);
    if (total2 > 500) tone(buzzer1,NOTE_D4);
    if (total3 > 500) tone(buzzer1,NOTE_E4);
    if (total4 > 500) tone(buzzer1,NOTE_F4);
    if (total5 > 500) tone(buzzer1,NOTE_G4);
    if (total6 > 500) tone(buzzer1,NOTE_A4);
    if (total7 > 500) tone(buzzer1,NOTE_B4);
    if (total8 > 500) tone(buzzer1,NOTE_C5);
    
    
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS4);
    if (total10 > 500) tone(buzzer1,NOTE_DS4);
    if (total11 > 500) tone(buzzer1,NOTE_FS4);
    if (total12 > 500) tone(buzzer1,NOTE_GS4);
    if (total13 > 500) tone(buzzer1,NOTE_AS4);
    }

    //octive 5
    
    if (octive == 5) {
       //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C5);
    if (total2 > 500) tone(buzzer1,NOTE_D5);
    if (total3 > 500) tone(buzzer1,NOTE_E5);
    if (total4 > 500) tone(buzzer1,NOTE_F5);
    if (total5 > 500) tone(buzzer1,NOTE_G5);
    if (total6 > 500) tone(buzzer1,NOTE_A5);
    if (total7 > 500) tone(buzzer1,NOTE_B5);
    if (total8 > 500) tone(buzzer1,NOTE_C6);
    
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS5);
    if (total10 > 500) tone(buzzer1,NOTE_DS5);
    if (total11 > 500) tone(buzzer1,NOTE_FS5);
    if (total12 > 500) tone(buzzer1,NOTE_GS5);
    if (total13 > 500) tone(buzzer1,NOTE_AS5);
    }
    
    //octive 6
    
    if (octive == 6) {
       //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C6);
    if (total2 > 500) tone(buzzer1,NOTE_D6);
    if (total3 > 500) tone(buzzer1,NOTE_E6);
    if (total4 > 500) tone(buzzer1,NOTE_F6);
    if (total5 > 500) tone(buzzer1,NOTE_G6);
    if (total6 > 500) tone(buzzer1,NOTE_A6);
    if (total7 > 500) tone(buzzer1,NOTE_B6);
    if (total8 > 500) tone(buzzer1,NOTE_C7);
    
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS6);
    if (total10 > 500) tone(buzzer1,NOTE_DS6);
    if (total11 > 500) tone(buzzer1,NOTE_FS6);
    if (total12 > 500) tone(buzzer1,NOTE_GS6);
    if (total13 > 500) tone(buzzer1,NOTE_AS6);
    }

    //octive 7
    
    if (octive == 7) {
       //white keys
    if (total1 > 500) tone(buzzer1,NOTE_C7);
    if (total2 > 500) tone(buzzer1,NOTE_D7);
    if (total3 > 500) tone(buzzer1,NOTE_E7);
    if (total4 > 500) tone(buzzer1,NOTE_F7);
    if (total5 > 500) tone(buzzer1,NOTE_G7);
    if (total6 > 500) tone(buzzer1,NOTE_A7);
    if (total7 > 500) tone(buzzer1,NOTE_B7);
    if (total8 > 500) tone(buzzer1,NOTE_C8);
    
  
    //black keys
    if (total9 > 500) tone(buzzer1,NOTE_CS7);
    if (total10 > 500) tone(buzzer1,NOTE_DS7);
    if (total11 > 500) tone(buzzer1,NOTE_FS7);
    if (total12 > 500) tone(buzzer1,NOTE_GS7);
    if (total13 > 500) tone(buzzer1,NOTE_AS7);
    }

as you can see its the same code repeated over and over again and i have no idea how i can decrease the size of it. thank you :slight_smile:

Welcome

Learn about "for loops" and arrays :slight_smile:

If you've got a bunch of variables with the same name, but a numeric suffix, it's usually a sign that you need arrays.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

What Arduino controller are you using?

Thanks.. Tom.. :slight_smile: