Using a Midi Keyboard to create coloured shapes

I am trying to use a MIDI keyboard to create a red ellipse to start with. I keep getting the same response of cannot convert void to boolean. Any help would be appreciated.

import themidibus.*;
MidiBus myBus;
int x;

void noteOn(int channel, int pitch, int velocity) {

void setup () {
  size (400, 400);
  background (0);

  myBus = new MidiBus(this, 0, 3);

void draw () {
   while (noteOn (0, 60, x));{
    fill (255, 0, 0);
    ellipse (200, 200, 200, 200);
1 Like

noteOn() is a method which is called when a Note On midi signal reaches your sketch. So you are able to write code in that function to do something. The parameters are then set to the specific channel and pitch. To just log which note was pressed, you can add a simple println().

void noteOn(int channel, int pitch, int velocity) {
    println("C: " + channel + " P: " + pitch + " V: " + velocity);

Now to use this information later in the draw method, you need to store the information you get in noteOn. You could just use a simple boolean to indicate if the note was pressed or not.

boolean noteWasPressed = false;

void noteOn(int channel, int pitch, int velocity) {
    if(channel == 0 && pitch == 60) {
        noteWasPressed = true;

Now you can check in draw if the condition is true, and of course reset it again after you’ve drawn the ellipse.

void draw() {
    if(noteWasPressed) {
        // draw your ellipse

         // reset the flag
        noteWasPressed = false;

this really help me too, its really helpfull for beginners ,and I will be stuck in this question for two days until I see your answer.

wish you have a good day