Making a binary typewriter

I have a project to make an 8 bit binary typewriter as an education interactive display for kids.
It will have 8 switches which will be set to represent a single ASCII character, then a button to enter the character, one letter at a time, once the switches have been set. The characters will appear on a screen, shifting left once new characters are added, and a clear button will restart the input.
Im wondering if there is an easy way to convert the input from the 8 switches into ascii characters. whether i compare the straight binary input, or convert to decimal then compare or if there is another option.
Im just starting the code for this now so dont have much to show yet.
Any thoughts would be appreciated.

You can read 8 switches directly from port D or C using a single command: PIND or PINC. Beware that some pins might be used by other functions, for example PORTD pins 0 and 1 are used for uploading and often for other serial communications.

If the switch values correspond to an ASCII character, you are done.

I'm embarrassed that I've forgotten exactly how to do that but once you've got a binary value in a variable the "simple trick" is in formatting the print statement. Are you using the serial monitor?

Of course, everything in memory is a binary value. It's the context that determines if a byte represents a character, part of a number, a machine instruction, etc.

For example, an ASCII 'A' stored in memory has a decimal value of 65 (41 Hex), which is 0100 0001 in binary (space added for readability and/or easy hex conversion).

It's just a binary value like anything else in memory and if you print it out as an ASCII character you'll get an A. If you print it out as a regular (decimal) integer you'll get 65. If you print it out as a hex value, you'll get 41.

Im wondering if there is an easy way to convert the input from the 8 switches into ascii characters.

What sort of Arduino?
The simplest universal way is to read each switch in turn and shift each result into a variable. Should be about 4 lines of code.
Something like this:-

ascii = 0;
for(int i=0; i<8; i++){
ascii = (ascii <<1) | digitalRead(pins[i]);
}

Cheers for the replies. Iv got a basic version working now but for some reason the first time i press the "enter character" button i dont get anything. its only after the second press that a character appears. not sure why.

Heres a pic of the prototype setup and the code

sketch_nov30a.ino (2.11 KB)

Every 8-bit number represents an ASCII code.
0-31 and 127 are control characters, so you'd want to filter those out.

If you're interested in only the letters of the alphabet and punctuation, you're in the base 7-bit ASCII and your high bit will always be 0.

I'd design it a bit differently: have toggle switches for the 8 bits, with LEDs indicating whether they're set to 1 or 0 (either on/off or different colour), then a separate push button to convert the setting to something on screen.

It seems the Arduino has no complete bank of 8 bits available, so a single PORT read is out.

kyotee89:
I have a project to make an 8 bit binary typewriter as an education interactive display for kids.
It will have 8 switches which will be set to represent a single ASCII character, then a button to enter the character, one letter at a time, once the switches have been set. The characters will appear on a screen, shifting left once new characters are added, and a clear button will restart the input.
Im wondering if there is an easy way to convert the input from the 8 switches into ascii characters. whether i compare the straight binary input, or convert to decimal then compare or if there is another option.
Im just starting the code for this now so dont have much to show yet.
Any thoughts would be appreciated.

You should immediately display what ever character is selected, don't wait for the enter button. It makes it more dynamic and interactive. So that, for example, you could toggle the 0 bit switch and it would "waggle" between 'A' and 'B'. Kids like instant feedback.

Or bit 5 to toggle upper/lowercase. Works for all letters, by design.

This thread reminds me of one of my first 8080 based computers with a whopping 1k of memory. http://www.vintage-computer.com/altair8800.shtml

Entering one binary command at a time with panel switches was so much fun back in '76, but it did expose the mystery and simplicity of working with digital computers in base 2.

I hope this gets "done", and written up for easy duplication!...

You should immediately display what ever character is selected

... is exactly right!.... but we need your "button to enter the character", too.

And yhou should have a simple LED to say "that combination of switches does not yield a printable character". (or you could "say" that with a rogue character on the "that switch combination (binary number) is the code for character.... ")

You only need 7 toggle switches, as indicated above, if you put the bits together.... and enough data lines may be an issue here.

The unit would have TWO displays... though they might both be implemented on different parts of one physical device... one to say "Those switch settings are the ones for such and such a character", and one display to accumulate and display a string of characters. (The "typewriter" part of this.)

The effect of the "button to enter the character" would be to transfer the current "Those switches are..." character to the growing string of characters.

You might want to add a "start a new line" button.

Displays: For a one child user, the £24 Hobbytronics TFT serial interfaced screen would be super. Small TFT color text and graphics display

For a "stand" in, say, a museum, where one user "playing" could be a magnet for the next "player", it would be easy and inexpensive to show everything on any VGA monitor you could beg, borrow or steal, striking whatever balance you wanted between cost and feature. To do this, you would use the £24 Hobbytronics (no, I don't work for them!) serial-to-VGA driver. http://www.hobbytronics.co.uk/serial-vga?keyword=serial%20vga

(Sorry both are only avail, as far as I know, in the UK... but both are small, and international postage not exhorbitant or terribly slow... though maybe this isn't the best time in the year to try to use the post!)

I have a project to make an 8 bit binary typewriter as an education interactive display for kids.
It will have 8 switches which will be set to represent a single ASCII character, then a button to enter the character, one letter at a time, once the switches have been set.
The characters will appear on a screen, shifting left once new characters are added, and a clear button will restart the input.
I have the 8 switches converted into a decimal number, which are stored one character at a time into an array. I want to now convert this array from the decimal into the ASCII characters and save as a string or something, which i can then display on the LED matrix i have.

Here is my code

#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>

// Set Width to the number of displays wide you have
const int WIDTH = 1;

// You can change to a smaller font (two lines) by commenting this line,
// and uncommenting the line after it:
const uint8_t *FONT = Arial14;
//const uint8_t *FONT = SystemFont5x7;

char *MESSAGE;

SoftDMD dmd(WIDTH,1);  // DMD controls the entire display
DMD_TextBox box(dmd);  // "box" provides a text box to automatically write to/scroll the display


#include <Button.h>

int sw8 = A0;
int sw7 = A1;
int sw6 = A2;
int sw5 = A3;
int sw4 = A4;
int sw3 = A5;
int sw2 = 3;
int sw1 = 2;



int sw1State;
int sw2State;
int sw3State;
int sw4State;
int sw5State;
int sw6State;
int sw7State;
int sw8State;

int decimal;
int i;
int j;
int character[20];

Button button1(4);
Button button2(5);

int relayPin = 12;

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

  Serial.begin(9600);
  
pinMode(2,INPUT);
pinMode(3,INPUT);

  button1.begin();
  button2.begin();

  dmd.setBrightness(255);
  dmd.selectFont(FONT);
  dmd.begin();

}

void loop() {


sw1State = digitalRead(sw1);
sw2State = digitalRead(sw2);
sw3State = analogRead(sw3);
sw4State = analogRead(sw4);
sw5State = analogRead(sw5);
sw6State = analogRead(sw6);
sw7State = analogRead(sw7);
sw8State = analogRead(sw8);

if (sw1State == HIGH) { decimal += 1; }
if (sw2State == HIGH) { decimal += 2; }
if (sw3State > 1000) { decimal += 4; sw3State = 1; }
else {sw3State = 0;}
if (sw4State > 1000) { decimal += 8; sw4State = 1; }
else {sw4State = 0;}
if (sw5State > 1000) { decimal += 16; sw5State = 1; }
else {sw5State = 0;}
if (sw6State > 1000) { decimal += 32; sw6State = 1; }
else {sw6State = 0;}
if (sw7State > 1000) { decimal += 64; sw7State = 1; }
else {sw7State = 0;}
if (sw8State > 1000) { decimal += 128; sw8State = 1; }
else {sw8State = 0;}

character[i] = decimal;
decimal = 0;

if (button1.pressed()){  
  Serial.print("enter character  ");
i++;
}

if (button2.pressed()) {
  i = 0;
  
  while ( j <= 19) {
    Serial.print("clear  ");
    Serial.println(j);
    character[j] = 0;
    j++;
  }
}

else {j = 0;}

String string1 = String(character[0]);
String string2 = String(character[1]);
String string3 = String(character[2]);
String string4 = String(character[3]);
String string5 = String(character[4]);
String string6 = String(character[5]);
String string7 = String(character[6]);
String string8 = String(character[7]);
String string9 = String(character[8]);
String string10 = String(character[9]);
String string11 = String(character[10]);
String string12 = String(character[11]);
String string13 = String(character[12]);
String string14 = String(character[13]);
String string15 = String(character[14]);
String string16 = String(character[15]);
String string17 = String(character[16]);
String string18 = String(character[17]);
String string19 = String(character[18]);
String string20 = String(character[19]);

String stringSum = String(string1 + string2 + 
string3 + string4 + string5 + string6 + string7 + 
string8 + string9 + string10 + string11 + string12 + 
string13 + string14 + string15 + string16 + string17 + string18 + string19 + string20);

Serial.write(character[0]);
Serial.write(character[1]);
Serial.write(character[2]);
Serial.write(character[3]);
Serial.write(character[4]);
Serial.write(character[5]);
Serial.write(character[6]);
Serial.write(character[7]);
Serial.write(character[8]);
Serial.write(character[9]);
Serial.write(character[10]);
Serial.write(character[11]);
Serial.write(character[12]);
Serial.write(character[13]);
Serial.write(character[14]);
Serial.write(character[15]);
Serial.write(character[16]);
Serial.write(character[17]);
Serial.write(character[18]);
Serial.write(character[19]);

Serial.println(" ");
Serial.print(sw1State);
Serial.print(" ");
Serial.print(sw2State);
Serial.print(" ");
Serial.print(sw3State);
Serial.print(" ");
Serial.print(sw4State);
Serial.print(" ");
Serial.print(sw5State);
Serial.print(" ");
Serial.print(sw6State);
Serial.print(" ");
Serial.print(sw7State);
Serial.print(" ");
Serial.print(sw8State);
Serial.println("  ");
Serial.print(decimal);
Serial.print("  ");
Serial.write(decimal);
Serial.println("  ");

/* box.write(character[1]);
box.write(character[2]);
box.write(character[3]);
box.write(character[4]);
box.write(character[5]);
box.write(character[6]);
box.write(character[7]);
box.write(character[8]);
box.write(character[9]);
box.write(character[10]);
box.write(character[11]);
box.write(character[12]);
box.write(character[13]);
box.write(character[14]);
box.write(character[15]);
box.write(character[16]);
box.write(character[17]);
box.write(character[18]);
box.write(character[19]);
*/

dmd.drawString(0, 0, (stringSum));
delay(2);
}

Currently when i drawString(stringSum) it is displaying as the decimal value (0-255) not as the ascii character.

Any help appreciated

ASCII = decimal + '0';

But of course, this is only for a single digit (one's place digit). For any further digits, you will have to multiply by 10 raised to a power.

If the bit pattern for an ASCII character is entered, it represents an ASCII character. All you have to do is send that value to the display in exactly the same way you send any other ASCII character.

You might need to cast the value as char, or uint8_t in the function call. Check the documentation for your display.

BTW you should be using digitalRead() instead analogRead(). That will work on any analog pin.

sw5State = analogRead(sw5);

Then you won't need this junk:

if (sw3State > 1000) { decimal += 4; sw3State = 1; }

jremington:
If the bit pattern for an ASCII character is entered, it represents an ASCII character. All you have to do is send that value to the display in exactly the same way you send any other ASCII character.

You might need to cast the value as char, or uint8_t in the function call. Check the documentation for your display.

BTW you should be using digitalRead() instead analogRead(). That will work on any analog pin.

sw5State = analogRead(sw5);

Then you won't need this junk:

if (sw3State > 1000) { decimal += 4; sw3State = 1; }

Hey cheers for that

Didn’t we go through all this here Making a binary typewriter - #5 by kyotee89 - Project Guidance - Arduino Forum

Grumpy_Mike:
Didn’t we go through all this here Making a binary typewriter - #5 by kyotee89 - Project Guidance - Arduino Forum

That was my first thread when the project had just started. My problem now is more specific to the code which has been developed since. probably could've added it on to old post though.

Cheers

Cheers tkbyd, i have made it an active change so the character changes on the display as switches are changed, then the next character button locks it in. Good suggestion.

I have the display on a 16 x 32 led matrix at the moment:

I will have two of these together to make it 16 x 64 display so longer names can fit (waiting for back order of other display). I am using the freetronics dmd library for control.

I am using the function "box.write(character[1])"... to write the characters at the moment and it is working well except this "box" function is a scrolling text box. i am trying to stop the scrolling function but no success so far. I can use the function "dmd.drawString(character[1])" but this displays the dec value that is stored in my character array.
How can i either stop the scrolling text using box.write or convert the dec value to ascii character so it will display properly with the drawString function.

Cheers

I have the display on a 16 x 32 led matrix at the moment:

I will have two of these together to make it 16 x 64 display so longer names can fit (waiting for back order of other display). I am using the freetronics dmd library for control.

I am using the function "box.write(character[1])"... to write the characters at the moment and it is working well except this "box" function is a scrolling text box. i am trying to stop the scrolling function but no success so far. I can use the function "dmd.drawString(character[1])" but this displays the dec value that is stored in my character array.
How can i either stop the scrolling text using box.write or convert the dec value to ascii character so it will display properly with the drawString function.

Cheers

Hi,

I have a project to make an 8 bit binary typewriter as an education interactive display for kids. I have two 16 x 32 Freetronics LED matrixes connected.
It has 8 switches which are to represent a single ASCII character, then a button to enter the character, one letter at a time, once the switches have been set.
The current character appears on a screen, changing as the switches are changed and when a button is pushed the character is stored and a new one can be entered.
I have the 8 switches converted into a dec number, which are stored one character at a time into an array. I am currently using the function "box.write(character[1])" to write a character however this results in the characters scrolling across the screen. if i use function "dmd.drawString(character[1])" it displays the dec value not the ascii character. can i either A) stop the box.write function from scrolling or B) drawString but print ascii character instead of binary.
Any help appreciated.

#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>

// Set Width to the number of displays wide you have
const int WIDTH = 1;

// You can change to a smaller font (two lines) by commenting this line,
// and uncommenting the line after it:
const uint8_t *FONT = Arial14;
//const uint8_t *FONT = SystemFont5x7;

char *MESSAGE;

SoftDMD dmd(WIDTH,1);  // DMD controls the entire display
DMD_TextBox box(dmd);  // "box" provides a text box to automatically write to/scroll the display


#include <Button.h>

int sw8 = A0;
int sw7 = A1;
int sw6 = A2;
int sw5 = A3;
int sw4 = A4;
int sw3 = A5;
int sw2 = 3;
int sw1 = 2;



int sw1State;
int sw2State;
int sw3State;
int sw4State;
int sw5State;
int sw6State;
int sw7State;
int sw8State;

int decimal;
int i;
int j;
int character[20];

Button button1(4);
Button button2(5);

int relayPin = 12;

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

  Serial.begin(9600);
  
pinMode(2,INPUT);
pinMode(3,INPUT);

  button1.begin();
  button2.begin();

  dmd.setBrightness(255);
  dmd.selectFont(FONT);
  dmd.begin();

}

void loop() {


sw1State = digitalRead(sw1);
sw2State = digitalRead(sw2);
sw3State = analogRead(sw3);
sw4State = analogRead(sw4);
sw5State = analogRead(sw5);
sw6State = analogRead(sw6);
sw7State = analogRead(sw7);
sw8State = analogRead(sw8);

if (sw1State == HIGH) { decimal += 1; }
if (sw2State == HIGH) { decimal += 2; }
if (sw3State > 1000) { decimal += 4; sw3State = 1; }
else {sw3State = 0;}
if (sw4State > 1000) { decimal += 8; sw4State = 1; }
else {sw4State = 0;}
if (sw5State > 1000) { decimal += 16; sw5State = 1; }
else {sw5State = 0;}
if (sw6State > 1000) { decimal += 32; sw6State = 1; }
else {sw6State = 0;}
if (sw7State > 1000) { decimal += 64; sw7State = 1; }
else {sw7State = 0;}
if (sw8State > 1000) { decimal += 128; sw8State = 1; }
else {sw8State = 0;}

character[i] = decimal;
decimal = 0;

if (button1.pressed()){  
  Serial.print("enter character  ");
i++;
}

if (button2.pressed()) {
  i = 0;
  
  while ( j <= 19) {
    Serial.print("clear  ");
    Serial.println(j);
    character[j] = 0;
    j++;
  }
}

else {j = 0;}

String string1 = String(character[0]);
String string2 = String(character[1]);
String string3 = String(character[2]);
String string4 = String(character[3]);
String string5 = String(character[4]);
String string6 = String(character[5]);
String string7 = String(character[6]);
String string8 = String(character[7]);
String string9 = String(character[8]);
String string10 = String(character[9]);
String string11 = String(character[10]);
String string12 = String(character[11]);
String string13 = String(character[12]);
String string14 = String(character[13]);
String string15 = String(character[14]);
String string16 = String(character[15]);
String string17 = String(character[16]);
String string18 = String(character[17]);
String string19 = String(character[18]);
String string20 = String(character[19]);

String stringSum = String(string1 + string2 + 
string3 + string4 + string5 + string6 + string7 + 
string8 + string9 + string10 + string11 + string12 + 
string13 + string14 + string15 + string16 + string17 + string18 + string19 + string20);

Serial.write(character[0]);
Serial.write(character[1]);
Serial.write(character[2]);
Serial.write(character[3]);
Serial.write(character[4]);
Serial.write(character[5]);
Serial.write(character[6]);
Serial.write(character[7]);
Serial.write(character[8]);
Serial.write(character[9]);
Serial.write(character[10]);
Serial.write(character[11]);
Serial.write(character[12]);
Serial.write(character[13]);
Serial.write(character[14]);
Serial.write(character[15]);
Serial.write(character[16]);
Serial.write(character[17]);
Serial.write(character[18]);
Serial.write(character[19]);

Serial.println(" ");
Serial.print(sw1State);
Serial.print(" ");
Serial.print(sw2State);
Serial.print(" ");
Serial.print(sw3State);
Serial.print(" ");
Serial.print(sw4State);
Serial.print(" ");
Serial.print(sw5State);
Serial.print(" ");
Serial.print(sw6State);
Serial.print(" ");
Serial.print(sw7State);
Serial.print(" ");
Serial.print(sw8State);
Serial.println("  ");
Serial.print(decimal);
Serial.print("  ");
Serial.write(decimal);
Serial.println("  ");

/* box.write(character[1]);
box.write(character[2]);
box.write(character[3]);
box.write(character[4]);
box.write(character[5]);
box.write(character[6]);
box.write(character[7]);
box.write(character[8]);
box.write(character[9]);
box.write(character[10]);
box.write(character[11]);
box.write(character[12]);
box.write(character[13]);
box.write(character[14]);
box.write(character[15]);
box.write(character[16]);
box.write(character[17]);
box.write(character[18]);
box.write(character[19]);
*/

dmd.drawString(0, 0, (stringSum));
delay(2);
}

Any answer will be in the display library code and/or documentation.