led master NEW

Author:
License: GPL
Github: rbrt/testing/led master NEW.axo

Inlets

None

Outlets

None

Attributes

spinner thin

Declaration
uint8_t count;
uint8_t ROW;
uint8_t array[308];
bool LOCKED;
#define BARS_ONE_L 0x03
#define BARS_ONE_R 0x04
#define BARS_TWO 0x05
#define BARS_NONE 0x06
uint8_t cell_offset[8] = {8, 17, 25, 34, 42, 51, 59, 68};
int offset;

void disp_cell_value(uint8_t mode, uint8_t column, uint8_t row, int in)
    __attribute__((noinline)) {
  offset = cell_offset[column] + (row * 77);
  int8_t v = in >> 20;
  int8_t fb;
  int16_t nb;
  switch (mode) {
  case 0: {
    if (v <= 0)
      v = 0;
    memset(array + offset, BARS_NONE, 8);
    nb = ((v + 1) << 4) >> 7;
    fb = nb >> 1;
    memset(array + offset, BARS_TWO, fb);
    if (nb % 2)
      array[fb + offset] = BARS_ONE_L;
    break;
  }
  case 1: {
    v = (v >> 1) + 64;
    memset(array + offset, BARS_NONE, 8);
    if (v == 64) {
      array[4 + offset] = 60;
      array[3 + offset] = 62;
    }
    if (v > 64) {
      array[3 + offset] = 62;
      nb = (((v + 1) << 4) >> 7) - 8;
      fb = nb >> 1;
      memset(array + offset + 4, BARS_TWO, fb);
      if (nb % 2)
        array[fb + 4 + offset] = BARS_ONE_L;
    }
    if (v < 64) {
      array[4 + offset] = 60;
      nb = 8 - (((v + 6) << 4) >> 7);
      fb = nb >> 1;
      memset(array + offset + (4 - fb), BARS_TWO, fb);
      if (nb % 2)
        array[offset + 3 - fb] = BARS_ONE_R;
    }
    break;
  }
  case 2: {
    char out[6];
    float v = float(in) / (float)((1 << 21) - 100);
    int wi = v;
    float f = fabs(v - wi);
    int fi = f * 100;
    if (v >= 0)
      out[0] = ' ';
    else
      out[0] = '-';
    wi = fabs(wi);
    out[1] = '0' + (wi / 10);
    out[2] = '0' + (wi % 10);
    out[3] = ',';
    out[4] = '0' + (fi / 10);
    out[5] = '0' + (fi % 10);
    out[6] = 32;
    out[7] = 32;
    memset(array + offset, 32, 8);
    memcpy(&array[offset], &out[0], 6);
    break;
  }
  }
}

void disp_cell_txt(uint8_t row, uint8_t column, const char *text)
    __attribute__((noinline)) {
  offset = cell_offset[column] + (row * 77);
  memset(&array[offset], 32, 8);
  memcpy(&array[offset], text, strlen(text));
}
Init
uint8_t init[8]{240, 71, 127, 21, 0, 0, 69, 0};
memset(&array[0], 32, 308);
int i;
for (i = 0; i < 4; i++) {
  memcpy(&array[i * 77], init, 8);
  array[(i * 77) + 76] = 247;
  array[(i * 77) + 4] = i + 24;
}
Control Rate
if ((ROW && !count) && !MidiGetOutputBufferPending(MIDI_DEVICE_USB_HOST)) {
  MidiSendSysEx(MIDI_DEVICE_USB_HOST, 2, &array[(ROW - 1) * 77], 77);
  ROW = 0;
  count = attr_thin;
}
if (count)
  count--;

Privacy

© 2024 Zrna Research