Go Down

Topic: Please assist me in optimizing my (beginner) code (Read 3 times) previous topic - next topic

stereomuffin

PaulS: i should change it to this?

Code: [Select]


int pushbutton_state[] = {};



Imahilus: thanks, i will get back to tomorrow :)

Another question about this part:

Code: [Select]

}else{
         pushbutton_pressed = false;
         BlinkM_setRGB(leds[i],0x00,0x00,0x00);
      }



How would i go about making sure that this else part in the loop only runs once? Do i need to do the same as above and use some kind of counter? I only want it run once because i want to implement midi note off there and its enough if it sends a noteoff once.

Same goes with the BlinkM_setRGB(leds,0x00,0x00,0x00);
statement, it turns my leds off (black) - but really i don't need it to keep on running forever do i?

PaulS

Quote
i should change it to this?

Code:

int pushbutton_state[] = {};

No.
Code: [Select]
int pushbutton_state[number_of_pushpins];
Also, this:
Code: [Select]
int number_of_pushpins = 16;
should be this:
Code: [Select]
[glow]const[/glow] int number_of_pushpins = 16;
This prevents the sketch from altering the value in number_of_pushpins.

PaulS

Quote
Do i need to do the same as above and use some kind of counter? I only want it run once because i want to implement midi note off there and its enough if it sends a noteoff once.

Either a counter or a simple flag, midiOffSent, initialized to false, and set false again whenever a MIDI note is sent. Then, test midiOffSent before sending a MIDI off note. Only send the off note if one has not been sent.

stereomuffin

#18
Dec 11, 2010, 07:01 pm Last Edit: Dec 11, 2010, 07:03 pm by stereomuffin Reason: 1
Thanks, now i'm confused though.
Can you tell in english what this means:

Code: [Select]

int pushbutton_state[number_of_pushpins];


something like: define an array of type integer that holds the value of the number_of_pushpins (=16) ? i dont get the logic behind it...  :-?

PaulS

The value in the [] is the number of elements in the array. When no value is present, the initializer list is used to determine the number of elements.

When there is no initializer list, the number of elements in the array must be explicitly defined.

Go Up