final int screenWidth = 1366;
final int screenHeight = 768;
final color black = color(0, 0, 0);

Camera camera;
Mouse mouse;
Room room;

void setup() {
  size(screenWidth, screenHeight, P3D);
  noCursor();
  mouse = new Mouse();
  camera = new Camera(mouse, width, height);
  room = new Room(camera);
}

void draw() {
  background(black);
  if (mouse.centred()) mouse.moved();
  else mouse.centre();
  camera.set();
  room.draw();
}

void keyPressed() {
  switch (key) {
    case 'w':
      if (withinRoom(camera.simulateMoveForward())) camera.moveForward();
      break;
    case 'a':
      if (withinRoom(camera.simulateStrafeLeft())) camera.strafeLeft();
      break;
    case 's':
      if (withinRoom(camera.simulateMoveBackward())) camera.moveBackward();
      break;
    case 'd':
      if (withinRoom(camera.simulateStrafeRight())) camera.strafeRight();
      break;
    case 'q':
      exit();
      break;
  }
}

boolean withinRoom(float[] cameraPosition) {
  float x = cameraPosition[0];
  float z = cameraPosition[1];
  return (x > -100 && x < 100) && (z > -100 && z < 100);
}

final int width = 1366;
final int height = 768;
final color black = color(0, 0, 0);

Camera camera;
Mouse mouse;
Room room;

void setup() {
  size(width, height, P3D);
  noCursor();
  mouse = new Mouse();
  camera = new Camera(mouse, width, height);
  room = new Room(camera);
}

void draw() {
  background(black);
  if (mouse.centred()) mouse.moved();
  else mouse.centre();
  camera.set();
  room.draw();
}

void keyPressed() {
  switch (key) {
    case 'w':
      if (withinRoom(camera.simulateMoveForward())) camera.moveForward();
      break;
    case 'a':
      if (withinRoom(camera.simulateStrafeLeft())) camera.strafeLeft();
      break;
    case 's':
      if (withinRoom(camera.simulateMoveBackward())) camera.moveBackward();
      break;
    case 'd':
      if (withinRoom(camera.simulateStrafeRight())) camera.strafeRight();
      break;
    case 'q':
      exit();
      break;
  }
}

boolean withinRoom(float[] cameraPosition) {
  float x = cameraPosition[0];
  float z = cameraPosition[1];
  return (x > -100 && x < 100) && (z > -100 && z < 100);
}

Rename width and height variables

Rename width and height variables


import wordcram.*;

size(600, 350);
background(255);

/*
 * There are a few different ways to load text.
 * WordCram will parse out the words, count them
 * up, and render more-frequent words bigger than
 * less-frequent ones.
 *
 * Try un-commenting some of the methods below.
 * (If more than one is uncommented, only the last
 * one will have an effect.)
 */

new WordCram(this)

  //.fromWebPage("http://en.wikipedia.org/wiki/Word_cloud")
  //.fromHtmlFile("../kari-the-elephant.html")
  .fromTextFile("../kari-the-elephant.txt")
  //.fromTextString(loadStrings("../kari-the-elephant.txt"))
  //.fromHtmlString(loadStrings("../kari-the-elephant.html"))

  .drawAll();

import wordcram.*;

size(600, 350);
background(255);

/*
 * There are a few different ways to load text.
 * WordCram will parse out the words, count them
 * up, and render more-frequent words bigger than
 * less-frequent ones.
 *
 * Try un-commenting some of the methods below.
 * (If more than one is uncommented, only the last
 * one will have an effect.)
 */

new WordCram(this)

  //.fromWebPage("https://en.wikipedia.org/wiki/Word_cloud")
  //.fromHtmlFile("../kari-the-elephant.html")
  .fromTextFile("../kari-the-elephant.txt")
  //.fromTextString(loadStrings("../kari-the-elephant.txt"))
  //.fromHtmlString(loadStrings("../kari-the-elephant.html"))

  .drawAll();

Update Wikipedia example sketch to use HTTPS.

See f51ad6457a50c910e17e66247b3edabc725f140a and
https://github.com/danbernier/WordCram/pull/64 for more info.


/*
 *  Emulates being plugged into a live CAN network by output randomly valued
 *  JSON messages over USB.
 */

#include "WProgram.h"
#include "chipKITUSBDevice.h"
#include "usbutil.h"

#define SIGNAL_COUNT 6

char* SIGNALS[SIGNAL_COUNT] = {
    "vehicle_speed",
    "transmission_gear_position",
    "accelerator_pedal_position",
    "brake_pedal_status",
    "powertrain_torque",
    "parking_brake_status",
};

void setup() {
    Serial.begin(115200);
    randomSeed(analogRead(0));

    initializeUsb();
}

void loop() {
    while(1) {
        writeMeasurement(SIGNALS[random(SIGNAL_COUNT)],
                random(101) + random(100) * .1);
    }
}

void writeMeasurement(char* measurementName, float value) {
    int messageLength = NUMERICAL_MESSAGE_FORMAT_LENGTH +
        strlen(measurementName) + NUMERICAL_MESSAGE_VALUE_MAX_LENGTH;
    char message[messageLength];
    sprintf(message, NUMERICAL_MESSAGE_FORMAT, measurementName, value);

    sendMessage((uint8_t*) message, strlen(message));
}

/*
 *  Emulates being plugged into a live CAN network by output randomly valued
 *  JSON messages over USB.
 */

#include "WProgram.h"
#include "chipKITUSBDevice.h"
#include "usbutil.h"

#define SIGNAL_COUNT 6

char* SIGNALS[SIGNAL_COUNT] = {
    "vehicle_speed",
    "transmission_gear_position",
    "accelerator_pedal_position",
    "windshield_wiper_speed",
    "steering_wheel_angle",
    "parking_brake_status",
};

void setup() {
    Serial.begin(115200);
    randomSeed(analogRead(0));

    initializeUsb();
}

void loop() {
    while(1) {
        writeMeasurement(SIGNALS[random(SIGNAL_COUNT)],
                random(101) + random(100) * .1);
    }
}

void writeMeasurement(char* measurementName, float value) {
    int messageLength = NUMERICAL_MESSAGE_FORMAT_LENGTH +
        strlen(measurementName) + NUMERICAL_MESSAGE_VALUE_MAX_LENGTH;
    char message[messageLength];
    sprintf(message, NUMERICAL_MESSAGE_FORMAT, measurementName, value);

    sendMessage((uint8_t*) message, strlen(message));
}

Use measurements in emulator that are displayed on Vehicle Dashboard.


int border = 50;
int repetitions = 5;
int w = 100;
int h = 100;
int x = 0;
int y = 0;

void setup() {
  size(800,800);
  rectMode(CORNER);
  noStroke();
  frameRate(1);
}

void draw() {
  background(240);

  for (int i=0; i<repetitions; i++){
    for (int n=0; n<repetitions; n++) {
      int x = (int) random(-5, 5);
      int y = (int) random(-5, 5);

      fill(127,63,62,200);
      rect((width/2-(5*w/2))+(w*i)+x, (height/2-(5*h/2))+(h*n)+y, w, h);
    }
  }
}

//  background(255,237,0);
//  int num = (int) random(3, 12);   // select a random number of squares each frame
//  int gap = (int) random(5, 50); // select a random gap between each square
//
//  // calculate the size of each square for the given number of squares and gap between them
//  float cellsize = ( width - (num + 1) * gap ) / (float)num;
//
//  // print out the size of each square
//  println("cellsize = " + cellsize);
//
//    for (int i=0; i<num; i++) {
//      for (int j=0; j<num; j++) {
//
//        fill(255); // rectangle
//        rect(gap * (i+1) + cellsize * i, gap * (j+1) + cellsize * j, cellsize, cellsize);
//      }
//    }

int border = 50;
int repetitions = 5;
int w = 100;
int h = 100;
int x = 0;
int y = 0;
int c = 0;

void setup() {
  size(800,800);
  rectMode(CORNER);
  noStroke();
  frameRate(0.5);
}

void draw() {
  background(240);

  for (int i=0; i<repetitions; i++){
    for (int n=0; n<repetitions; n++) {
      int x = (int) random(-5, 5);
      int y = (int) random(-5, 5);
      int c = (int) random (0,5);

      if (c < 1) {
        fill(22,213,236,200);
      } else {
        fill(217,40,73,200);
      }

      rect((width/2-(5*w/2))+(w*i)+x, (height/2-(5*h/2))+(h*n)+y, w, h);

    }
  }
}

Add random colour. Finished Vera.

Add random colour. Finished Vera.


class Room {

  final float centreX = 0;
  final float centreY = 0;
  final float centreZ = 0;

  Camera camera;
  float wallSize;

  Room(Camera camera) {
    this.camera = camera;
    wallSize = 200;
  }

  void wall() {
    beginShape(QUADS);
    vertex(0, 0, 0);
    vertex(1, 0, 0);
    vertex(1, 1, 0);
    vertex(0, 1, 0);
    endShape(CLOSE);
  }

  void draw() {
    pushMatrix();
    translate(centreX - (wallSize / 2), centreY - (wallSize / 2), centreZ - wallSize);
    scale(wallSize);
    wall();
    popMatrix();
  }
}

class Room {

  Camera camera;
  float width, height, depth;

  Room(Camera camera) {
    this.camera = camera;
    width = depth = 200;
    height = 100;
  }

  void draw() {
    pushMatrix();
    translate(0, 0, 0);
    box(width, height, depth);
    popMatrix();
  }
}

Use box to make room

Use box to make room


int i;
float border = 20;
float x1;
float y1;
float di;

void setup() {
 size(600,600);
 background(255);
 smooth();
 di = random(5,10);
 x1 = random(border,width-border);
 y1 = random(border,height-border);
 fill(random(0,200));
 noStroke();
 ellipse(x1,y1,di,di);
}

void draw() {
  if ( i < 49 ) {

    float x2 = random(border,width-border);
    float y2 = random(border,height-border);
    stroke(random(0,200));
    line (x1,y1,x2,y2);
    x1 = x2;
    y1 = y2;
    i = i+1;
    di = random(5,10);
    fill(random(0,250));
    noStroke();
    ellipse(x1,y1,di,di);
 }
}

int i;
float border = 15;  //MARGIN
float x1;
float y1;
float di;

//ADD THE VARIATION OF SHADE
float fiftyShadeOfGrey = random(0,50);
float alph = random(80,200);

void setup() {
 size(600,600);
 background(random(230,255));
 smooth();

 //DRAW THE FIRST POINT AT THE FIRST RANDOM POSITION
 di = random(5,15);
 x1 = random(border,width-border);
 y1 = random(border,height-border);
 fill(fiftyShadeOfGrey,fiftyShadeOfGrey,fiftyShadeOfGrey, alph);
 noStroke();
 ellipse(x1,y1,di,di);

}

void draw() {
  // CREATE OTHER 49 POINTS & CONNECTING LINE
  if ( i < 49 ) {
    // CREATE A NEW RANDOM POSITION
    float x2 = random(border,width-border);
    float y2 = random(border,height-border);

    // DRAW THE LINE FROM AN OLD POSITION TO A NEW POSITION
    stroke(fiftyShadeOfGrey,fiftyShadeOfGrey,fiftyShadeOfGrey, alph);
    line (x1,y1,x2,y2); // DRAW

    // NOW X1 and Y1 REFER TO THE NEW POSITION
    x1 = x2;
    y1 = y2;

    // DRAW THE NEW POINT AT THE NEW POSITION
    di = random(5,15);
    fiftyShadeOfGrey = random(0,50);
    alph = random(80,200);
    fill(fiftyShadeOfGrey,fiftyShadeOfGrey,fiftyShadeOfGrey, alph);
    noStroke();
    ellipse(x1,y1,di,di); // DRAW

    // NEXT
    i = i+1;
 }
}

ADD SOME COLOR EFFECT AND COMMENTS

ADD SOME COLOR EFFECT AND COMMENTS

Add shades of grey and put some comments


#include <SoftPWM.h>

void setup()
{
  SoftPWMBegin();

  // Sets the PWM value to 0 for the built-in LED (WLED).
  SoftPWMSet(WLED, 0);

  // Sets the default fade time for WLED to
  // 100 ms fade-up and 550 ms to fade-down.
  SoftPWMSetFadeTime(WLED, 100, 550);
}

void loop()
{
  // Turn on WLED
  SoftPWMSet(WLED, 255);
  // Wait for the fade-up and some extra delay.
  delay(250);
  // Turn off WLED
  SoftPWMSet(WLED, 0);
  // Wait for the fade-down, and some extra delay.
  delay(650);
}

#include <SoftPWM.h>

#ifndef WLED
#define WLED LED_BUILTIN
#endif

void setup()
{
  SoftPWMBegin();

  // Sets the PWM value to 0 for the built-in LED (WLED).
  SoftPWMSet(WLED, 0);

  // Sets the default fade time for WLED to
  // 100 ms fade-up and 550 ms to fade-down.
  SoftPWMSetFadeTime(WLED, 100, 550);
}

void loop()
{
  // Turn on WLED
  SoftPWMSet(WLED, 255);
  // Wait for the fade-up and some extra delay.
  delay(250);
  // Turn off WLED
  SoftPWMSet(WLED, 0);
  // Wait for the fade-down, and some extra delay.
  delay(650);
}

Use LED_BUILTIN instead of WLED when compiling on Arduino IDE


final int screenWidth = 1366;
final int screenHeight = 768;
final color black = color(0, 0, 0);

Camera camera;
Room room;

void setup() {
  size(screenWidth, screenHeight, P3D);
  noCursor();
  camera = new Camera(width, height);
  room = new Room(camera);
}

void draw() {
  background(black);
  camera.set();
  room.draw();
}

void keyPressed() {
  switch (key) {
    case 'w':
      camera.moveForward();
      break;
    case 'a':
      camera.strafeLeft();
      break;
    case 's':
      camera.moveBackward();
      break;
    case 'd':
      camera.strafeRight();
      break;
    case 'q':
      exit();
      break;
  }
}

import java.awt.AWTException;
import java.awt.Robot;

final int screenWidth = 1366;
final int screenHeight = 768;
final color black = color(0, 0, 0);

Camera camera;
Robot robot;
Room room;

void setup() {
  size(screenWidth, screenHeight, P3D);
  noCursor();
  camera = new Camera(width, height);
  room = new Room(camera);
  try {
    robot = new Robot();
  } catch (AWTException e) {
    println("Unable to instantiate Robot");
    exit();
  }
  robot.mouseMove(width / 2, height / 2);
}

void draw() {
  background(black);
  camera.set();
  room.draw();
}

void keyPressed() {
  switch (key) {
    case 'w':
      camera.moveForward();
      break;
    case 'a':
      camera.strafeLeft();
      break;
    case 's':
      camera.moveBackward();
      break;
    case 'd':
      camera.strafeRight();
      break;
    case 'q':
      exit();
      break;
  }
}

Use Robot class to set camera position to the center of the screen on startup


BDIM flow;
Body body;
FloodPlot flood;

void setup(){
  size(800,800);         // display window size
  int n=(int)pow(2,7);   // number of grid points
  float L = n/8.;        // length-scale in grid units
  Window view = new Window(n,n);

  body = new CircleBody(n/3,n/2,L,view);     // define geom
  flow = new BDIM(n,n,1.5,body);             // solve for flow using BDIM
//  flow = new BDIM(n,n,0.,body,L/200,true);  // BDIM+QUICK
  flood = new FloodPlot(view);
  flood.setLegend("vorticity",-.5,.5);
}
void draw(){
  body.update();
  flow.update(body); flow.update2();
  flood.display(flow.u.vorticity());
  body.display();
}
void mousePressed(){body.mousePressed();}
void mouseReleased(){body.mouseReleased();}

/*********************************************************
                  Main Window!

Click the "Run" button to Run the simulation.

Change the geometry, flow conditions, numercial parameters
visualizations and measurments from this window.

*********************************************************/
BDIM flow;
Body body;
FloodPlot flood;

void setup(){
  size(800,800);         // display window size
  int n=(int)pow(2,7);   // number of grid points
  float L = n/8.;        // length-scale in grid units
  Window view = new Window(n,n);

  body = new CircleBody(n/3,n/2,L,view);     // define geom
  flow = new BDIM(n,n,1.5,body);             // solve for flow using BDIM
//  flow = new BDIM(n,n,0.,body,L/200,true);   // BDIM+QUICK
  flood = new FloodPlot(view);               // intialize...
  flood.setLegend("vorticity",-.5,.5);       // and label a flood plot
}
void draw(){
  body.update();                             // update the body
  flow.update(body); flow.update2();         // 2-step fluid update
  flood.display(flow.u.vorticity());         // compute and display vorticity
  body.display();                            // display the body
}
void mousePressed(){body.mousePressed();}    // user mouse...
void mouseReleased(){body.mouseReleased();}  // interaction methods

Add comments to main page

Add comments to main page


/*
 *  Emulates being plugged into a live CAN network by output randomly valued
 *  JSON messages over USB.
 */

#include "WProgram.h"
#include "chipKITUSBDevice.h"
#include "usbutil.h"

#define SIGNAL_COUNT 12

char* SIGNALS[SIGNAL_COUNT] = {
    "vehicle_speed",
    "transmission_gear_position",
    "accelerator_pedal_position",
    "windshield_wiper_speed",
    "steering_wheel_angle",
    "parking_brake_status",
    "brake_pedal_status",
    "engine_speed",
    "latitude",
    "longitude",
    "transmission_gear_pos",
    "veh_button_event",
};

void writeMeasurement(char* measurementName, float value) {
    int messageLength = NUMERICAL_MESSAGE_FORMAT_LENGTH +
        strlen(measurementName) + NUMERICAL_MESSAGE_VALUE_MAX_LENGTH;
    char message[messageLength];
    sprintf(message, NUMERICAL_MESSAGE_FORMAT, measurementName, value);

    sendMessage((uint8_t*) message, strlen(message));
}

void setup() {
    Serial.begin(115200);
    randomSeed(analogRead(0));

    initializeUsb();
}

void loop() {
    while(1) {
        writeMeasurement(SIGNALS[random(SIGNAL_COUNT)],
                random(101) + random(100) * .1);
    }
}

/*
 *  Emulates being plugged into a live CAN network by output randomly valued
 *  JSON messages over USB.
 */

#include "WProgram.h"
#include "chipKITUSBDevice.h"
#include "usbutil.h"

#define SIGNAL_COUNT 11

char* SIGNALS[SIGNAL_COUNT] = {
    "vehicle_speed",
    "transmission_gear_position",
    "accelerator_pedal_position",
    "windshield_wiper_speed",
    "steering_wheel_angle",
    "parking_brake_status",
    "brake_pedal_status",
    "engine_speed",
    "latitude",
    "longitude",
    "transmission_gear_pos",
};

void writeMeasurement(char* measurementName, float value) {
    int messageLength = NUMERICAL_MESSAGE_FORMAT_LENGTH +
        strlen(measurementName) + NUMERICAL_MESSAGE_VALUE_MAX_LENGTH;
    char message[messageLength];
    sprintf(message, NUMERICAL_MESSAGE_FORMAT, measurementName, value);

    sendMessage((uint8_t*) message, strlen(message));
}

void setup() {
    Serial.begin(115200);
    randomSeed(analogRead(0));

    initializeUsb();
}

void loop() {
    while(1) {
        writeMeasurement(SIGNALS[random(SIGNAL_COUNT)],
                random(101) + random(100) * .1);
    }
}

Remove button event from emulator - this one needs custom handling.


import java.util.*;
import java.text.*;
import java.nio.file.*;

class PrimitiveGroup {

  Primitive[] primitives = new Primitive[30];

  PrimitiveGroup() {

    // Populate the PrimitiveGroup with junk
    for (int i = 0; i < 30; i++) {
      PVector rand_loc = PVector.random3D();
      rand_loc.mult(100);

      int rand_size = int(random(10,45));

      if (i % 2 == 0) {
        primitives[i] = new PrimitiveSphere(rand_loc, rand_size);
      }
      else {
        primitives[i] = new PrimitiveCube(rand_loc, rand_size);
      }

    }
  }

  void update() {
    // Update every Primitive in the PrimitiveGroup
    for (int i = 0; i < primitives.length; i++) {
      primitives[i].update();
    }
  }

  void display() {
    // Update every Primitive in the PrimitiveGroup
    for (int i = 0; i < primitives.length; i++) {
      primitives[i].display();
    }
  }
}

import java.util.*;
import java.text.*;
import java.nio.file.*;

class PrimitiveGroup {

  Primitive[] primitives = new Primitive[30];

  PrimitiveGroup() {
    populate();
  }

  void update() {
    // Update every Primitive in the PrimitiveGroup
    for (int i = 0; i < primitives.length; i++) {
      primitives[i].update();
    }
  }

  void display() {
    // Update every Primitive in the PrimitiveGroup
    for (int i = 0; i < primitives.length; i++) {
      primitives[i].display();
    }
  }

  void populate() {
    // Populate the PrimitiveGroup with junk
    for (int i = 0; i < 30; i++) {
      PVector rand_loc = PVector.random3D();
      rand_loc.mult(100);

      int rand_size = int(random(10, 45));

      if (i % 2 == 0) {
        primitives[i] = new PrimitiveSphere(rand_loc, rand_size);
      } else {
        primitives[i] = new PrimitiveCube(rand_loc, rand_size);
      }
    }
  }
}

Move test populate code to its own method.


/**
 * textAnalyse_basic
 * by wrongPowder Library.
 *
 * Use wrongPowder.util.string package to analyze text.
 *
 * @author    Paul Vollmer
 * @modified  2011.10.31
 */

//import wrongPowder.util.string.TextAnalyse;

//TextAnalyse textAnalyse = new TextAnalyse();

void setup() {
  size(400, 400);
}

void draw() {
}

void keyPressed() {
  char letter = char(key);
  println("KEY\t[ ASCII DEC: "+(int)key+
          " Unicode: "+(int)key+
          " char: "+ letter +
          " end ]");
}

/**
 * textAnalyse_basic
 * by wrongPowder Library.
 *
 * Use wrongPowder.util.string package to analyze text.
 *
 * @author    Paul Vollmer
 * @modified  2011.10.31
 */

import wrongPowder.util.string.*;
TextAnalyse textAnalyse = new TextAnalyse();

String[] text;

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

  // Load a text file and initialize the string array.
  text = loadStrings("example.txt");
  //textAnalyse.init(text);
  //textAnalyse.analyse();
  textAnalyse.analyse("hello world abc 1");
  textAnalyse.totalWords();

}

Delete old TextAnalyse file, changes at analyse example


class DelayButton extends Button {

  final color COLOR_WHITE = color(255);

  DelayButton(int x, int y, int w, int h) {
    super(x, y, w, h);
  }

  void drawMe(){
    super.drawMe();

    fill(COLOR_WHITE);
    textSize(buttonW/3);
    text("Delay", buttonX+buttonW/12, buttonY+buttonH*3/4);
  }

}

class DelayButton extends Button {

  final color COLOR_WHITE = color(255);

  static final String TEXT_DELAY = "Delay";

  DelayButton(int x, int y, int w, int h) {
    super(x, y, w, h);
  }

  void drawMe(){
    super.drawMe();

    fill(COLOR_WHITE);
    textSize(buttonW/3);
    text(
      TEXT_DELAY,
      buttonX + buttonW/12,
      buttonY + buttonH*3/4
    );
  }

}

Change delay button text to string variable

Please don't ask me why the parameters for the text in the
Delay button are set to that. If you have a better idea,
please send a merge request and I'd be happy to discuss it.
Until then...

"...but why?"
- Ryan Reynolds
Harold and Kumar Go to White Castle (2004)


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

#include "WProgram.h"
#include "Wire.h"

void setup() {
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

#include "Wire.h"

void setup() {
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

Remove old WProgram.h import from test case.


import wordcram.*;

void setup() {
  size(1000, 500);
  smooth();
  background(255);

  new WordCram(this)
    .fromWebPage("http://wordcram.org")
      .drawAll();
}

void wordsCounted(Word[] words) {
  println("counted " + words.length + " words!");
}

void beginDraw() {
  println("beginDraw: drawing the sketch...");
}

int wordsDrawn = 0;
void wordDrawn(Word word) {
  //println("drew this word! " + word.word);
  wordsDrawn++;
}

int wordsSkipped = 0;
void wordSkipped(Word word) {
  //println("skipped " + word.word + " because " + word.wasSkippedBecause());
  wordsSkipped++;
}

void endDraw() {
  println("endDraw!");
  println("- skipped: " + wordsSkipped);
  println("- drawn:   " + wordsDrawn);
}

import wordcram.*;

void setup() {
  size(1000, 500);
  smooth();
  background(255);

  new WordCram(this)
    .fromTextFile("../kari-the-elephant.txt")
    .drawAll();
}

void wordsCounted(Word[] words) {
  println("counted " + words.length + " words!");
}

void beginDraw() {
  println("beginDraw: drawing the sketch...");
}

int wordsDrawn = 0;
void wordDrawn(Word word) {
  wordsDrawn++;
}

int wordsSkipped = 0;
void wordSkipped(Word word) {
  wordsSkipped++;
}

void endDraw() {
  println("endDraw!");
  println("- skipped: " + wordsSkipped);
  println("- drawn:   " + wordsDrawn);
}

Clean up callbacks example sketch

Clean up callbacks example sketch


// Checking int casting

// int -> int cast
int a = 40, b = 20;
int r1 = (int)a;
_checkEqual(r1, 40);

int r2 = (int)a + (int)b;
_checkEqual(r2, 60);

float c = 5.5, d = -5.5;
int r3 = (int)c;
_checkEqual(r3, 5);

int r3 = (int)d;
_checkEqual(r3, -5);

int r4 = 7 + (int)c;
_checkEqual(r4, 12);

int r5 = (int)d + 13;
_checkEqual(r5, 8);

float[] arr = { 1.2, 3.4 };
int r6 = 7 + (int)arr[1];
_checkEqual(r6, 10);

int r7 = (int)(d + 3);
_checkEqual(r7, -2);

class Obj1 {
  float run() { return -4.3; }
}

Obj1 obj = new Obj1();
int r8 = 4 * (4 + (int)obj. run() + 1);
_checkEqual(r8, 4);

int neg  = -(int)3.6;
int neg2 = (int)3.6;
_checkEqual(neg, -neg2);

Add test for negative with int casts.

Add test for negative with int casts.


// HeaterMeter Copyright 2011 Bryan Mayland <bmayland@capnbry.net>
#include <WProgram.h>
#include <ShiftRegLCD.h>
#include "hmcore.h"

// See hmcore.h for most options and tweaks

#ifdef HEATERMETER_NETWORKING
// these are redundant but if you don't include them, the Arduino build
// process won't include them to the temporary build location
#include <WiServer.h>
#include <dataflash.h>
#include "wishieldconf.h"
#endif /* HEATERMETER_NETWORKING */

#ifdef HEATERMETER_RFM12
#include <RF12.h>
#include <Ports.h>
#endif /* HEATERMETER_RFM12 */

void setup(void)
{
  hmcoreSetup();
}

void loop(void)
{
  hmcoreLoop();
}

// HeaterMeter Copyright 2011 Bryan Mayland <bmayland@capnbry.net>
#include <WProgram.h>
#include <ShiftRegLCD.h>
#include "hmcore.h"

// See hmcore.h for most options and tweaks

#ifdef HEATERMETER_NETWORKING
// these are redundant but if you don't include them, the Arduino build
// process won't include them to the temporary build location
#include <WiServer.h>
#include <dataflash.h>
#include "wishieldconf.h"
#endif /* HEATERMETER_NETWORKING */

#ifdef HEATERMETER_RFM12
#include <RF12.h>
#include <Ports.h>
#endif /* HEATERMETER_RFM12 */

int main(void)
{
  init();
  hmcoreSetup();
  for (;;)
    hmcoreLoop();
  return 0;
}

[hm] Add int main(void) instead of using default Arduino


import wordcram.*;
import java.awt.*;

void setup() {
  PImage image = loadImage("../heart.png");
  size(image.width, image.height);

  background(128);

  Shape imageShape = new ImageShaper().shape(image, #000000);
  ShapeBasedPlacer placer = new ShapeBasedPlacer(imageShape);

  new WordCram(this).
    fromTextFile("../kari-the-elephant.txt").
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(8, 40).
    withColor(#ffffff).
    drawAll();

  imageShape = new ImageShaper().shape(image, #ffffff);
  placer = new ShapeBasedPlacer(imageShape);

  new WordCram(this).
    fromTextFile("../kari-the-elephant.txt").
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(8, 40).
    withColor(#000000).
    drawAll();
}

import wordcram.*;
import java.awt.*;

void setup() {
  PImage image = loadImage("../heart.png");
  size(image.width, image.height);

  background(128);

  Shape imageShape = new ImageShaper().shape(image, #000000);
  ShapeBasedPlacer placer = new ShapeBasedPlacer(imageShape);

  new WordCram(this).
    fromTextFile("../kari-the-elephant.txt").
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(7, 40).
    withColor(#ffffff).
    drawAll();

  imageShape = new ImageShaper().shape(image, #ffffff);
  placer = new ShapeBasedPlacer(imageShape);

  new WordCram(this).
    fromTextFile("../kari-the-elephant.txt").
    withPlacer(placer).
    withNudger(placer).
    sizedByWeight(7, 40).
    withColor(#000000).
    drawAll();
}

Speed up image-mask example: smaller fonts


/*
 *  Emulates being plugged into a live CAN network by output randomly valued
 *  JSON messages over USB.
 */

#include "WProgram.h"
#include "chipKITUSBDevice.h"
#include "usbutil.h"

#define SIGNAL_COUNT 11

char* SIGNALS[SIGNAL_COUNT] = {
    "vehicle_speed",
    "transmission_gear_position",
    "accelerator_pedal_position",
    "windshield_wiper_speed",
    "steering_wheel_angle",
    "parking_brake_status",
    "brake_pedal_status",
    "engine_speed",
    "latitude",
    "longitude",
    "transmission_gear_pos",
};

void writeMeasurement(char* measurementName, float value) {
    int messageLength = NUMERICAL_MESSAGE_FORMAT_LENGTH +
        strlen(measurementName) + NUMERICAL_MESSAGE_VALUE_MAX_LENGTH;
    char message[messageLength];
    sprintf(message, NUMERICAL_MESSAGE_FORMAT, measurementName, value);

    sendMessage((uint8_t*) message, strlen(message));
}

void setup() {
    Serial.begin(115200);
    randomSeed(analogRead(0));

    initializeUsb();
}

void loop() {
    while(1) {
        writeMeasurement(SIGNALS[random(SIGNAL_COUNT)],
                random(101) + random(100) * .1);
    }
}

/*
 *  Emulates being plugged into a live CAN network by output randomly valued
 *  JSON messages over USB.
 */

#include "WProgram.h"
#include "chipKITUSBDevice.h"
#include "usbutil.h"

#define SIGNAL_COUNT 9

char* SIGNALS[SIGNAL_COUNT] = {
    "vehicle_speed",
    "accelerator_pedal_position",
    "windshield_wiper_speed",
    "steering_wheel_angle",
    "parking_brake_status",
    "brake_pedal_status",
    "engine_speed",
    "latitude",
    "longitude",
};

void writeMeasurement(char* measurementName, float value) {
    int messageLength = NUMERICAL_MESSAGE_FORMAT_LENGTH +
        strlen(measurementName) + NUMERICAL_MESSAGE_VALUE_MAX_LENGTH;
    char message[messageLength];
    sprintf(message, NUMERICAL_MESSAGE_FORMAT, measurementName, value);

    sendMessage((uint8_t*) message, strlen(message));
}

void setup() {
    Serial.begin(115200);
    randomSeed(analogRead(0));

    initializeUsb();
}

void loop() {
    while(1) {
        writeMeasurement(SIGNALS[random(SIGNAL_COUNT)],
                random(101) + random(100) * .1);
    }
}

Remove gear position from emulator - requires custom handler.


  class WaveSequence {
  private Game game;

  private LinkedList<Wave> waves;
  private Path path;

  // TODO: Need to spawn initial wave's units first, then others at spawnsAt.

  WaveSequence(JSONArray wavedataArray, Path path, Game game) {
    this.waves = new LinkedList();
    for (int i = 0; i < wavedataArray.size(); i++) {
      this.waves.add(new Wave(wavedataArray.getJSONObject(i), path, game));
    }
  }
}

class Wave {

  private Game game;

  private LinkedList<Unit> creeps;
  private int spawnsAt;

  private Path path;

  Wave(JSONObject wavedata, Path path, Game game) {
    this.game = game;
    this.path = path;
    this.creeps = new LinkedList();

    // Parse "creeps" json object.
    JSONObject creepdata = wavedata.getJSONObject("creeps");
    Iterator creepdataKeys = creepdata.keys()
      .iterator();
    while(creepdataKeys.hasNext()){
      String id = (String) creepdataKeys.next();
      int amount = creepdata.getInt(id);

      for (int i = 0; i < amount; i++) {
        // TODO: Delay spawning by a few ms to add space
        this.creeps.add(
          new Creep(UnitUtils.stringToId(id), path.getSpawnpoint(), (CustomWorld) game)
        );
      }
    }

    this.spawnsAt = wavedata.getInt("spawnsAt");
  }
}

  class WaveSequence {
  private Game game;

  private LinkedList<Wave> waves;
  private Path path;

  // TODO: Need to spawn initial wave's units first, then others at spawnsAt.

  WaveSequence(JSONArray wavedataArray, Path path, Game game) {
    this.waves = new LinkedList();
    for (int i = 0; i < wavedataArray.size(); i++) {
      this.waves.add(new Wave(wavedataArray.getJSONObject(i), path, game));
    }
  }
}

class Wave {

  private Game game;

  private LinkedList<Unit> creeps;
  private int spawnsAt;

  private Path path;

  Wave(JSONObject wavedata, Path path, Game game) {
    this.game = game;
    this.path = path;
    this.creeps = new LinkedList();

    // Parse "creeps" json object.
    JSONObject creepdata = wavedata.getJSONObject("creeps");
    Iterator creepdataKeys = creepdata.keys()
      .iterator();
    while(creepdataKeys.hasNext()){
      String id = (String) creepdataKeys.next();
      int amount = creepdata.getInt(id);

      for (int i = 0; i < amount; i++) {
        // TODO: Delay spawning by a few ms to add space
        this.creeps.add(
          new Creep(UnitUtils.stringToId(id), path.getSpawnpoint(), (CWorld) game)
        );
      }
    }

    this.spawnsAt = wavedata.getInt("spawnsAt");
  }
}

Rename CustomWorld to CWorld pt2

Rename CustomWorld to CWorld pt2


public class ThreadTask extends TimerTask {
 Thread thread;
 ThreadTask(Thread thread) {
	 this.thread = thread;
 }

 public void run() {
	 thread.setDaemon(true);
	 thread.start();
 }
}

public class ThreadTask extends TimerTask {
 Thread thread;
 ThreadTask(Thread thread) {
	 this.thread = thread;
 }

 public void run() {
	 thread.setDaemon(false);
	 thread.start();
 }
}

Set daemon thread to be false

Set daemon thread to be false

Seems to have improved the garbage collection process


/*
 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

IRsend irsend;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() != -1) {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(100);
    }
  }
}

/*
 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

IRsend irsend;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() != -1) {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(40);
    }
  }
}

Reduce gap between Sony messages. This should work more reliably.


final int width = 1366;
final int height = 768;
final color black = color(0, 0, 0);

Mouse mouse;
Camera camera;
Room room;

void setup() {
  size(width, height, P3D);
  noCursor();
  mouse = new Mouse();
  camera = new Camera(mouse, width, height);
  room = new Room();
}

void draw() {
  background(black);
  if (mouse.centred()) mouse.moved();
  else mouse.centre();
  camera.set();
  room.draw();
}

void keyPressed() {
  switch (key) {
    case 'w':
      if (withinRoom(camera.simulateMoveForward())) camera.moveForward();
      break;
    case 'a':
      if (withinRoom(camera.simulateStrafeLeft())) camera.strafeLeft();
      break;
    case 's':
      if (withinRoom(camera.simulateMoveBackward())) camera.moveBackward();
      break;
    case 'd':
      if (withinRoom(camera.simulateStrafeRight())) camera.strafeRight();
      break;
    case 'q':
      exit();
      break;
  }
}

boolean withinRoom(float[] cameraPosition) {
  float x = cameraPosition[0];
  float z = cameraPosition[1];
  return (x > -100 && x < 100) && (z > -100 && z < 100);
}

final int width = 1366;
final int height = 768;
final color black = color(0, 0, 0);

Mouse mouse;
Camera camera;
Room room;

void setup() {
  size(width, height, P3D);
  noCursor();
  mouse = new Mouse();
  camera = new Camera(mouse);
  room = new Room();
}

void draw() {
  background(black);
  if (mouse.centred()) mouse.moved();
  else mouse.centre();
  camera.set();
  room.draw();
}

void keyPressed() {
  switch (key) {
    case 'w':
      if (room.within(camera.forwardPosition())) {
        camera.moveForward();
      }
      break;
    case 'a':
      if (room.within(camera.leftPosition())) {
        camera.strafeLeft();
      }
      break;
    case 's':
      if (room.within(camera.backwardPosition())) {
        camera.moveBackward();
      }
      break;
    case 'd':
      if (room.within(camera.rightPosition())) {
        camera.strafeRight();
      }
      break;
    case 'q':
      exit();
      break;
  }
}

Use new Camera and Room methods

Use new Camera and Room methods


class Button {
  final int buttonX;
  final int buttonY;
  final int buttonW;
  final int buttonH;

  final color COLOR_BLACK = color(0);
  final color COLOR_GREY_DARK = color(51);
  final color COLOR_GREY = color(102);

  final color buttonColor = COLOR_BLACK;
  final color baseColor = COLOR_GREY;
  final color buttonHighlight = COLOR_GREY_DARK;
  final color currentColor = baseColor;

  boolean buttonOver;

  Button(int x, int y, int w, int h) {
    buttonX = x;
    buttonY = y;
    buttonW = w;
    buttonH = h;
    buttonOver = false;
  }

  void update(int x, int y) {
    buttonOver = overButton(buttonX, buttonY, buttonW, buttonH);
  }

  boolean overButton(int x, int y, int width, int height)  {
    return mouseX > x && mouseX < x+width &&
           mouseY > y && mouseY < y+height;
  }

  void drawMe () {
    if (buttonOver) {
      fill(buttonHighlight);
    }
    else {
      fill(buttonColor);
    }
    stroke(255);
    rect(buttonX, buttonY, buttonW, buttonH);
  }

}

class Button {
  final int buttonX;
  final int buttonY;
  final int buttonW;
  final int buttonH;

  final color COLOR_BLACK = color(0);
  final color COLOR_GREY_DARK = color(51);
  final color COLOR_GREY = color(102);
  final color COLOR_WHITE = color(255);

  final color buttonColor = COLOR_BLACK;
  final color baseColor = COLOR_GREY;
  final color buttonHighlight = COLOR_GREY_DARK;
  final color outlineColor = COLOR_WHITE;
  final color currentColor = baseColor;

  boolean buttonOver;

  Button(int x, int y, int w, int h) {
    buttonX = x;
    buttonY = y;
    buttonW = w;
    buttonH = h;
    buttonOver = false;
  }

  void update(int x, int y) {
    buttonOver = overButton(buttonX, buttonY, buttonW, buttonH);
  }

  boolean overButton(int x, int y, int width, int height)  {
    return mouseX > x && mouseX < x+width &&
           mouseY > y && mouseY < y+height;
  }

  void drawMe () {
    if (buttonOver) {
      fill(buttonHighlight);
    }
    else {
      fill(buttonColor);
    }
    stroke(outlineColor);
    rect(buttonX, buttonY, buttonW, buttonH);
  }

}

Replace magic number for button outline color


import java.awt.AWTException;
import java.awt.Robot;

class Mouse {

  Robot robot;
  int prevX;

  Mouse(int x) {
    try {
      robot = new Robot();
    } catch (AWTException e) {
      println("Unable to instantiate Robot");
      exit();
    }
    prevX = x;
  }

  int dx() {
    if (width % 2 == 0 && mouseX == 0) return 1 - prevX;
    return mouseX - prevX;
  }

  void move(int x, int y) {
    robot.mouseMove(x, y);
  }

  void moved() {
    if (width % 2 == 0 && mouseX == 0) prevX = 1;
    else prevX = mouseX;

    if (mouseX == width - 1) {
      robot.mouseMove(1, mouseY);
      prevX = 1;
    } else if ((width % 2 == 0 && mouseX == 1) || mouseX == 0) {
      robot.mouseMove(width - 1, mouseY);
      prevX = width - 1;
    }
  }
}

import java.awt.AWTException;
import java.awt.Robot;

class Mouse {

  Robot robot;
  int prevX;

  Mouse(int x) {
    try {
      robot = new Robot();
    } catch (AWTException e) {
      println("Unable to instantiate Robot");
      exit();
    }
    prevX = x;
  }

  int dx() {
    if (width % 2 == 0 && mouseX == 0) return 1 - prevX;
    return mouseX - prevX;
  }

  void move(int x, int y) {
    robot.mouseMove(x, y);
  }

  void moved() {
    if (mouseX == width - 1) {
      robot.mouseMove(1, mouseY);
      prevX = 1;
    } else if ((width % 2 == 0 && mouseX == 1) || mouseX == 0) {
      robot.mouseMove(width - 1, mouseY);
      prevX = width - 1;
    } else {
      prevX = mouseX;
    }
  }
}

Store previous mouse location x-coordinate


import java.awt.AWTException;
import java.awt.Robot;

class Mouse {

  Robot robot;
  boolean centred;
  int pass;

  Mouse() {
    try {
      robot = new Robot();
    } catch (AWTException e) {
      e.printStackTrace();
      exit();
    }
    centred = false;
    pass = 3;
  }

  boolean centred() {
    return centred;
  }

  int x() {
    return mouseX;
  }

  int y() {
    return mouseY - (height / 2);
  }

  void centre() {
    robot.mouseMove(width / 2, height / 2);
    if (--pass == 0) centred = true;
  }

  void move() {
    if (mouseX == width - 1) {
      robot.mouseMove(0, mouseY);
    } else if (mouseX == 0) {
      robot.mouseMove(width - 1, mouseY);
    }
  }
}

import java.awt.AWTException;
import java.awt.Robot;

class Mouse {

  Robot robot;
  boolean centred;
  int attempt;

  Mouse() {
    try {
      robot = new Robot();
    } catch (AWTException e) {
      e.printStackTrace();
      exit();
    }
    centred = false;
    attempt = 3;
  }

  boolean centred() {
    return centred;
  }

  int x() {
    return mouseX;
  }

  int y() {
    return mouseY - (height / 2);
  }

  void centre() {
    robot.mouseMove(width / 2, height / 2);
    if (--attempt == 0) centred = true;
  }

  void move() {
    if (mouseX == width - 1) {
      robot.mouseMove(0, mouseY);
    } else if (mouseX == 0) {
      robot.mouseMove(width - 1, mouseY);
    }
  }
}

Rename pass field to attempt

Rename pass field to attempt


#include <MidiClockPage.h>
#include <MidiEuclidSketch.h>
#include <AutoMidiController.h>

PitchEuclidSketch sketch;
AutoMidiControllerSketch sketch2;
SketchSwitchPage sketchSwitchPage(NULL, &sketch, &sketch2);

void setup() {
  sketch.setupMonster(true);
  sketch2.setupMonster(true);
  GUI.setSketch(&_defaultSketch);
  GUI.setPage(&sketchSwitchPage);
  GUI.addEventHandler(handleEvent);

  initClockPage();
}

bool handleEvent(gui_event_t *event) {
  return sketchSwitchPage.handleGlobalEvent(event);
}

void loop() {
}

Add new sketch for olli: midieuclid, automagiccontroller, magic sysex page


import hypermedia.net.*;
import java.util.*;

List<String> history = new ArrayList<String>();

int PORT_RX=4242;
String HOST_IP = "localhost";//IP Address of the PC in which this App is running
UDP udp;//Create UDP object for recieving

void setup(){
  udp= new UDP(this, PORT_RX, HOST_IP);
  udp.log(false);
  udp.listen(true);

  size(700, 400);

}

void draw(){
  background(0);

  int count = history.size();

  for(int i = count - 1; i >= 0; i--){
    int y_offset = i * 12;
    text(history.get(i), 10, y_offset);
  }

}

void receive(byte[] data, String HOST_IP, int PORT_RX){

  String value=new String(data);
  history.add(value);

}

Add another approach to a logview using processing 3


#include <GUI.h>

class ClockCallbackTest : public ClockCallback {
  public:
  ClockCallbackTest() {
  }

  void onStartCallback() {
    GUI.flash_strings_fill("RECEIVED", "START");
  }

  void onStopCallback() {
    GUI.flash_strings_fill("RECEIVED", "STOP");
  }

  void onContinueCallback() {
    GUI.flash_strings_fill("RECEIVED", "CONTINUE");
  }

  void on32Callback(uint32_t pos) {
    if (BUTTON_DOWN(Buttons.BUTTON1)) {
      delay(100);
    }
    GUI.setLine(GUI.LINE2);
    GUI.put_value16(2, pos & 0xFFFF);
  }
};

ClockCallbackTest cbTest;

void setup() {
  GUI.flash_strings_fill("CLOCK CALLBACK", "TEST FIRMWARE");
//  MidiClock.addOn16Callback(&cbTest, (midi_clock_callback_ptr_t)&ClockCallbackTest::on16Callback);
  MidiClock.addOn32Callback(&cbTest, (midi_clock_callback_ptr_t)&ClockCallbackTest::on32Callback);
  MidiClock.addOnStartCallback(&cbTest, (midi_clock_callback_ptr0_t)&ClockCallbackTest::onStartCallback);
  MidiClock.addOnStopCallback(&cbTest, (midi_clock_callback_ptr0_t)&ClockCallbackTest::onStopCallback);
  MidiClock.addOnContinueCallback(&cbTest, (midi_clock_callback_ptr0_t)&ClockCallbackTest::onContinueCallback);
  MidiClock.useImmediateClock = true;
}

Add blocking midi clock callback test sketch


void setup()
{
  fullScreen();
  background(51);
}

void draw()
{
  int cx = width/2;
  int cy = height/2;

  noFill();
  stroke(0,255,255);
  strokeWeight(4);

  rectMode(CENTER);
  rect(cx, cy, (2 * cx) - 10 ,cx);

  float lines = cx/5;
  float startpoint = (height - cx) / 2;

  for( int i = 0; i < 5; i++)
  {
    strokeWeight(1);
    line(5, startpoint, width, startpoint);
    startpoint += lines;
  }

  fill(51);
  strokeWeight(4);
  ellipse(cx, cy, cx, cx);

  int y1 = cy + cx/2;
  float y2 = cy + cx/2;
  float cx2 = cx;

    strokeWeight(1);
    stroke(0,255,0);

    ellipse(cx, y2, 30, 30);
    y2 = y2 - 0.5;

}

Add First pde file (frame).

Add First pde file (frame).


void setup() {
  GUI.setLine(GUI.LINE1);
  GUI.put_string_fill("HELLO WORLD");
}

void handleEvent(gui_event_t *evt) {
  GUI.setLine(GUI.LINE2);
  for (uint8_t i = Buttons.BUTTON1; i <= Buttons.BUTTON4; i++) {
    if (EVENT_PRESSED(evt, i)) {
      GUI.flash_printf_fill("%b PRESSED", i);
    }
    else if (EVENT_RELEASED(evt, i)) {
      GUI.flash_printf_fill("%b RELEASED", i);
    }
  }
}

Add video tutorial hello world

Add video tutorial hello world


#include <MNM.h>

void setup() {

}

class DebugCallbacks : public MNMCallback {
public:
  DebugCallbacks() {
  }

  void onKitMessage() {
    MNM.kit.fromSysex(MidiSysex.data + 5, MidiSysex.recordLen - 5);
//    printf("got kit \"%s\"\n", kit.name);
  }
};

void loop() {
  uint8_t track = MNM.getCurrentTrack(1000);
  GUI.flash_p_strings_fill(PSTR("MNM KIT"), PSTR(""));
  GUI.setLine(GUI.LINE2);
  GUI.flash_put_value(0, track);
  delay(500);
}

Add debug sketch for MNM sysex

Add debug sketch for MNM sysex


#include <MNM.h>

class TestMNMSketch : public Sketch, MNMCallback {
public:
  EncoderPage page;

  TestMNMSketch() {
  }

  void setup() {
  }

  bool handleEvent(gui_event_t *event) {
    if (EVENT_PRESSED(event, Buttons.BUTTON1)) {
      GUI.setLine(GUI.LINE2);
      GUI.put_value(0, 0);
      uint8_t track = MNM.getCurrentTrack(1000);
      GUI.setLine(GUI.LINE1);
      GUI.put_p_string(PSTR("TRACK"));
      GUI.setLine(GUI.LINE2);
      GUI.put_value(0, track);
    }

    return false;
  }
};

TestMNMSketch sketch;

void setup() {
  MidiUart.sendString("HELLO");
  //  enableProfiling();
//  initMNMTask();
  sketch.setup();
  MNMSysexListener.setup();
  GUI.setSketch(&sketch);
}

void loop() {
}

Add test firmware for MNM messages

Add test firmware for MNM messages


#include <MD.h>

MDTempoEncoder foo("TMP", 130);
MDTrackFlashEncoder foo2("TRK", 0, true);
EncoderPage page(&foo, &foo2);

void setup() {
  GUI.setPage(&page);
}

Test the tempo encoder for MD

Test the tempo encoder for MD


import processing.serial.*;

Serial serial;
PrintWriter out;

void setup() {
  serial = new Serial(this, "COM3", 115200);
  out = createWriter("data.txt");
}

void draw() {
  if (serial.available() > 0) {
    int data = serial.read();
    out.println(data);
  }
}

void keyPressed() {
  out.flush();
  out.close();
  exit();
}

Add Processing sketch for logging serial data