Examples > 04.Communication > Dimmer

Do you remember the line in Shawshank Redemption when Andy (the prisoner) says to the warden, "How can you be so obtuse?" I wanted to scream those words at Examples > 04.Communication > Dimmer

Follow these steps to get the Dimmer example to run properly (as originally explained in this video: Arduino Interfacing with processing: dimming - YouTube )

  1. Build your circuit as shown in the Circuit (https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer#circuit) or Schematic (https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer#schematic) sections

  2. Upload Dimmer.ino (i.e. all of the Examples > 04.Communication > Dimmer code) to your Arduino board

  3. Go to Download Processing / Processing.org and download the Processing software

  4. Unzip the download (for example, processing-3.5.4-windows64.zip)

  5. The Processing software does not have an Install program. Instead, simply double-click on the file "processing.exe" to start the Processing software.

  6. An empty sketch file appears.

  1. In the Dimmer.ino file or in the Code (https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer#code) section or here :slight_smile: , copy the following block of code:
  // Dimmer - sends bytes over a serial port

  // by David A. Mellis

  // This example code is in the public domain.

  import processing.serial.*;

  Serial port;

  void setup() {

    size(256, 150);

    println("Available serial ports:");

    // if using Processing 2.1 or later, use Serial.printArray()

    println(Serial.list());

    // Uses the first port in this list (number 0). Change this to select the port

    // corresponding to your Arduino board. The last parameter (e.g. 9600) is the

    // speed of the communication. It has to correspond to the value passed to

    // Serial.begin() in your Arduino sketch.

    port = new Serial(this, Serial.list()[0], 9600);

    // If you know the name of the port used by the Arduino board, you can specify

    // it directly like this.

    //port = new Serial(this, "COM1", 9600);

  }

  void draw() {

    // draw a gradient from black to white

    for (int i = 0; i < 256; i++) {

      stroke(i);

      line(i, 0, i, 150);

    }

    // write the current X-position of the mouse to the serial port as

    // a single byte

    port.write(mouseX);
}


[color=#93a1a1]
[/color]

without the color command, which the Arduino forum editor appends for some unknown reason.

  1. Paste the code into the empty Processing sketch file

  2. Click on the "Run" icon

  1. A small window appears with the same title as the Processing sketch file. This window contains a gradient from
    black on the left to white on the right.

  1. Move your mouse cursor within the small window. As you move your mouse cursor toward the black side of the gradient, the LED on your Arduino breadboard will dim. As you move your mouse cursor toward the white side of the gradient, the LED on your Arduino breadboard will brighten.
1 Like