Monday 23 January 2017

BASIC Tech Group - MyNews 20 - Some useful Hellschreiber font sketches

When writing some sketches for Hellscreiber transmission, you need bit mapped fonts.

A font is made up of glyphs (or characters), each glyph is made up of columns and rows of pixels.

Glyphs come as bit maps, sizes 5x7 and 3x5, that is 5 cols x 7 rows, or the very small 3 cols x 5 rows. They are stored in an array, part of which is shown below. The first column is the glyph in ASCII that can be scanned to find the following bit map. for example, 3x5:

Screen Shot 2017 01 23 at 11 26 15

Data is stored in an array of bytes for each column. e.g. 5 columns of 7 rows. For example:

Screen Shot 2017 01 23 at 11 26 58

When transmitted the columns are scanned in the direction of bottom to top and the output frequency is shifted from the BASEFREQ, upwards in steps of SHIFT. a pixel is transmitted if the map contains a ‘1’. The pixels are transmitted for a PIXTIME of 200-500ms, scanning only the area defining the glyph, from bottom to top: so b1-b7 for 5x7 or b1-b5 for 3x5.

Below are a couple of fonts in Arduino IDE ".ino" files that were found in the internet, take care... these are up-side-down as normal graphic representation start the bit map at top left, and go down not up. Here also is a simple program for inverting these fonts, output is to the Monitor screen from where they can be cut and pasted into other sketches.

Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

// font3x5 +1 array
byte glyphs[]4] = {
  {' ', 0x00, 0x00, 0x00}, // Space
  {'0', 0x20, 0x10, 0x08}, // 0
  {'1', 0x00, 0x7C, 0x00}, // 1
  {'2', 0x64, 0x54, 0x48}, // 2
  {'3', 0x44, 0x54, 0x28}, // 3
  {'4', 0x1C, 0x10, 0x7C}, // 4
  {'5', 0x4C, 0x54, 0x24}, // 5
  {'6', 0x38, 0x54, 0x20}, // 6
  {'7', 0x04, 0x74, 0x0C}, // 7
  {'8', 0x28, 0x54, 0x28}, // 8
  {'9', 0x08, 0x54, 0x38}, // 9
  {'A', 0x78, 0x14, 0x78}, // A
  {'B', 0x7C, 0x54, 0x28}, // B
  {'C', 0x38, 0x44, 0x44}, // C
  {'D', 0x7C, 0x44, 0x38}, // D
  {'E', 0x7C, 0x54, 0x44}, // E
  {'F', 0x7C, 0x14, 0x04}, // F
  {'G', 0x38, 0x44, 0x34}, // G
  {'H', 0x7C, 0x10, 0x7C}, // H
  {'I', 0x00, 0x7C, 0x00}, // I
  {'J', 0x20, 0x40, 0x3C}, // J
  {'K', 0x7C, 0x10, 0x6C}, // K
  {'L', 0x7C, 0x40, 0x40}, // L
  {'M', 0x7C, 0x08, 0x7C}, // M
  {'N', 0x7C, 0x04, 0x7C}, // N
  {'O', 0x7C, 0x44, 0x7C}, // O
  {'P', 0x7C, 0x14, 0x08}, // P
  {'Q', 0x38, 0x44, 0x78}, // Q
  {'R', 0x7C, 0x14, 0x68}, // R
  {'S', 0x48, 0x54, 0x24}, // S
  {'T', 0x04, 0x7C, 0x04}, // T
  {'U', 0x7C, 0x40, 0x7C}, // U
  {'V', 0x3C, 0x40, 0x3C}, // V
  {'W', 0x7C, 0x20, 0x7C}, // W
  {'X', 0x6C, 0x10, 0x6C}, // X
  {'Y', 0x1C, 0x60, 0x1C}, // Y
  {'Z', 0x64, 0x54, 0x4C}  // Z
};
3x5 vfont


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}
// font 5x7
// table of glyphs 0-9 & A-Z
byte glyphs[][6] = {
  {' ', 0x00, 0x00, 0x00, 0x00, 0x00}, // 20 SP
  {'/', 0x20, 0x10, 0x08, 0x04, 0x02}, // 2F /
  {'0', 0x3e, 0x51, 0x49, 0x45, 0x3e}, // 30 0
  {'1', 0x00, 0x42, 0x7f, 0x40, 0x00}, // 31 1
  {'2', 0x42, 0x61, 0x51, 0x49, 0x46}, // 32 2
  {'3', 0x21, 0x41, 0x45, 0x4b, 0x31}, // 33 3
  {'4', 0x18, 0x14, 0x12, 0x7f, 0x10}, // 34 4
  {'5', 0x27, 0x45, 0x45, 0x45, 0x39}, // 35 5
  {'6', 0x3c, 0x4a, 0x49, 0x49, 0x30}, // 36 6
  {'7', 0x01, 0x71, 0x09, 0x05, 0x03}, // 37 7
  {'8', 0x36, 0x49, 0x49, 0x49, 0x36}, // 38 8
  {'9', 0x06, 0x49, 0x49, 0x29, 0x1e}, // 39 9
  {'A', 0x7e, 0x11, 0x11, 0x11, 0x7e}, // 41 A
  {'B', 0x7f, 0x49, 0x49, 0x49, 0x36}, // 42 B
  {'C', 0x3e, 0x41, 0x41, 0x41, 0x22}, // 43 C
  {'D', 0x7f, 0x41, 0x41, 0x22, 0x1c}, // 44 D
  {'E', 0x7f, 0x49, 0x49, 0x49, 0x41}, // 45 E
  {'F', 0x7f, 0x09, 0x09, 0x09, 0x01}, // 46 F
  {'G', 0x3e, 0x41, 0x49, 0x49, 0x7a}, // 47 G
  {'H', 0x7f, 0x08, 0x08, 0x08, 0x7f}, // 48 H
  {'I', 0x00, 0x41, 0x7f, 0x41, 0x00}, // 49 I
  {'J', 0x20, 0x40, 0x41, 0x3f, 0x01}, // 4a J
  {'K', 0x7f, 0x08, 0x14, 0x22, 0x41}, // 4b K
  {'L', 0x7f, 0x40, 0x40, 0x40, 0x40}, // 4c L
  {'M', 0x7f, 0x02, 0x0c, 0x02, 0x7f}, // 4d M
  {'N', 0x7f, 0x04, 0x08, 0x10, 0x7f}, // 4e N
  {'O', 0x3e, 0x41, 0x41, 0x41, 0x3e}, // 4f O
  {'P', 0x7f, 0x09, 0x09, 0x09, 0x06}, // 50 P
  {'Q', 0x3e, 0x41, 0x51, 0x21, 0x5e}, // 51 Q
  {'R', 0x7f, 0x09, 0x19, 0x29, 0x46}, // 52 R
  {'S', 0x46, 0x49, 0x49, 0x49, 0x31}, // 53 S
  {'T', 0x01, 0x01, 0x7f, 0x01, 0x01}, // 54 T
  {'U', 0x3f, 0x40, 0x40, 0x40, 0x3f}, // 55 U
  {'V', 0x1f, 0x20, 0x40, 0x20, 0x1f}, // 56 V
  {'W', 0x3f, 0x40, 0x38, 0x40, 0x3f}, // 57 W
  {'X', 0x63, 0x14, 0x08, 0x14, 0x63}, // 58 X
  {'Y', 0x07, 0x08, 0x70, 0x08, 0x07}, // 59 Y
  {'Z', 0x61, 0x51, 0x49, 0x45, 0x43}, // 5a Z
};
// Font_Reverse
// writes the font up-side-down to the monitor,
// open this first then upload sketch
// monitor output can then be copied into the glyphs array in other programs
// it allows pixel columns to be output bottom up pix = 0 to 7

// paste the source font here
byte glyphs[][4] = {
  {' ', 0x00, 0x00, 0x00}, // Space
  {'0', 0x20, 0x10, 0x08}, // 0
  {'1', 0x00, 0x7C, 0x00}, // 1
  {'2', 0x64, 0x54, 0x48}, // 2
  {'3', 0x44, 0x54, 0x28}, // 3
  {'4', 0x1C, 0x10, 0x7C}, // 4
  {'5', 0x4C, 0x54, 0x24}, // 5
  {'6', 0x38, 0x54, 0x20}, // 6
  {'7', 0x04, 0x74, 0x0C}, // 7
  {'8', 0x28, 0x54, 0x28}, // 8
  {'9', 0x08, 0x54, 0x38}, // 9
  {'A', 0x78, 0x14, 0x78}, // A
  {'B', 0x7C, 0x54, 0x28}, // B
  {'C', 0x38, 0x44, 0x44}, // C
  {'D', 0x7C, 0x44, 0x38}, // D
  {'E', 0x7C, 0x54, 0x44}, // E
  {'F', 0x7C, 0x14, 0x04}, // F
  {'G', 0x38, 0x44, 0x34}, // G
  {'H', 0x7C, 0x10, 0x7C}, // H
  {'I', 0x00, 0x7C, 0x00}, // I
  {'J', 0x20, 0x40, 0x3C}, // J
  {'K', 0x7C, 0x10, 0x6C}, // K
  {'L', 0x7C, 0x40, 0x40}, // L
  {'M', 0x7C, 0x08, 0x7C}, // M
  {'N', 0x7C, 0x04, 0x7C}, // N
  {'O', 0x7C, 0x44, 0x7C}, // O
  {'P', 0x7C, 0x14, 0x08}, // P
  {'Q', 0x38, 0x44, 0x78}, // Q
  {'R', 0x7C, 0x14, 0x68}, // R
  {'S', 0x48, 0x54, 0x24}, // S
  {'T', 0x04, 0x7C, 0x04}, // T
  {'U', 0x7C, 0x40, 0x7C}, // U
  {'V', 0x3C, 0x40, 0x3C}, // V
  {'W', 0x7C, 0x20, 0x7C}, // W
  {'X', 0x6C, 0x10, 0x6C}, // X
  {'Y', 0x1C, 0x60, 0x1C}, // Y
  {'Z', 0x64, 0x54, 0x4C}  // Z
};
byte revglyphs[40][6];

void setup() {
  int r, c;  // row and col

  Serial.begin(9600);

  Serial.println("Font reverse");

  for (r = 0; r < ((sizeof glyphs) / (sizeof glyphs[0])); r++) {
    Serial.print("{'");
    Serial.write(glyphs[r][0]);
    Serial.print("', ");
    for (c = 1; c < 4; c++) {
      revglyphs[r][c] =  reverse(glyphs[r][c]);
      Serial.print("0x");
      if(revglyphs[r][c] < 0x0f) Serial.print("0");
      Serial.print(revglyphs[r][c], HEX);
      Serial.print(", ");
    }
    Serial.println("},");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

byte reverse(byte b) {
   b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
   b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
   b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
   return b;
}

No comments: