Add Keyboard support
This commit is contained in:
parent
b12d602075
commit
11947c765e
58
stepper.ino
58
stepper.ino
@ -19,14 +19,29 @@
|
|||||||
|
|
||||||
#include <Stepper.h>
|
#include <Stepper.h>
|
||||||
|
|
||||||
|
// Typewriter head
|
||||||
unsigned char charmap[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 24, 0, 64, 67, 74, 16, 72, 73, 51, 65, 14, 63, 1, 50, 57, 53, 54, 55, 56, 58, 59, 60, 61, 62, 31, 43, 0, 68, 0, 27, 0, 38, 19, 22, 30, 28, 23, 32, 42, 40, 36, 46, 34, 17, 44, 41, 35, 48, 25, 26, 37, 29, 33, 15, 49, 39, 21, 0, 0, 0, 45, 0, 82, 94, 88, 89, 86, 93, 3, 83, 4, 95, 84, 9, 87, 81, 92, 91, 6, 8, 90, 5, 2, 7, 85, 13, 79, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 0, 0, 0, 0, 0, 69, 0, 0};
|
unsigned char charmap[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 24, 0, 64, 67, 74, 16, 72, 73, 51, 65, 14, 63, 1, 50, 57, 53, 54, 55, 56, 58, 59, 60, 61, 62, 31, 43, 0, 68, 0, 27, 0, 38, 19, 22, 30, 28, 23, 32, 42, 40, 36, 46, 34, 17, 44, 41, 35, 48, 25, 26, 37, 29, 33, 15, 49, 39, 21, 0, 0, 0, 45, 0, 82, 94, 88, 89, 86, 93, 3, 83, 4, 95, 84, 9, 87, 81, 92, 91, 6, 8, 90, 5, 2, 7, 85, 13, 79, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 0, 0, 0, 0, 0, 69, 0, 0};
|
||||||
|
|
||||||
|
// Keyboard
|
||||||
|
uint8_t keyMap[9][8] {
|
||||||
|
/*0*/ {'5', '\x80'/*backarrw*/, '4', '=', '`', '9', '1', '8'},
|
||||||
|
/*1*/ {0, 0, 'y', '[', 'w', 'p', 'e', 'u'},
|
||||||
|
/*2*/ {'6', '\x81'/*forwarrw*/, '3', '-', 0, '0', '2', '7'},
|
||||||
|
/*3*/ {'a', 0, 'k', '\n', 'f', '\x82'/*caps*/, 'g', 'l'},
|
||||||
|
/*4*/ {'\t', '\x83'/*backsps*/, 't', ']', 'q', 'o', 'r', 'i'},
|
||||||
|
/*5*/ {'s', 0, 'j', '\'', 'd', 0, 'h', ';'},
|
||||||
|
/*6*/ {'c', '\x86'/*r_down_ctrl*/, 'm', 0, 'n', 'x', 0, '/'},
|
||||||
|
/*7*/ {'v', 0, ',', '\x84'/*l_shift*/, 'b', 'z', '\\', '.'},
|
||||||
|
/*8*/ {' ', '\x85'/*l_up_ctrl*/, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
uint8_t lastKey[9] = { 0 };
|
||||||
|
|
||||||
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
|
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
|
||||||
// for your motor
|
// for your motor
|
||||||
|
|
||||||
// initialize the stepper library on pins 8 through 11:
|
// initialize the stepper library on pins 8 through 11:
|
||||||
Stepper columnStepper(stepsPerRevolution, 8, 9, 10, 11);
|
Stepper columnStepper(stepsPerRevolution, 8, 9, 10, 11);
|
||||||
Stepper charWheelStepper(stepsPerRevolution, 7, 6, 5, 4);
|
Stepper charWheelStepper(96, 7, 6, 5, 4);
|
||||||
|
|
||||||
int charWidth = 11; // how many steps between char prints
|
int charWidth = 11; // how many steps between char prints
|
||||||
|
|
||||||
@ -34,11 +49,11 @@ int currentPos = 0;
|
|||||||
int currentChar = 0;
|
int currentChar = 0;
|
||||||
int limitPin = 12;
|
int limitPin = 12;
|
||||||
int headMotorLimitPin = 13;
|
int headMotorLimitPin = 13;
|
||||||
int hammerPin = 22;
|
int hammerPin = 14;
|
||||||
|
|
||||||
int Motor1A = 2;
|
int Motor1A = 2;
|
||||||
int Motor1B = 3;
|
int Motor1B = 3;
|
||||||
int Motor2A = 23;
|
int Motor2A = 15;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// initialize the serial port:
|
// initialize the serial port:
|
||||||
@ -57,13 +72,22 @@ void setup() {
|
|||||||
|
|
||||||
pinMode(hammerPin, OUTPUT);
|
pinMode(hammerPin, OUTPUT);
|
||||||
digitalWrite(hammerPin, LOW);
|
digitalWrite(hammerPin, LOW);
|
||||||
|
|
||||||
|
// Keyboard
|
||||||
|
for (int i = 22; i < 30; i++) {
|
||||||
|
pinMode(i, INPUT);
|
||||||
|
digitalWrite(i, HIGH);
|
||||||
|
}
|
||||||
|
for (int i = 30; i < 40; i++) {
|
||||||
|
pinMode(i, INPUT);
|
||||||
|
digitalWrite(i, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
columnStepper.setSpeed(90);
|
columnStepper.setSpeed(90);
|
||||||
charWheelStepper.setSpeed(90);
|
charWheelStepper.setSpeed(90);
|
||||||
Serial.println("Finding home");
|
//Serial.println("Finding home");
|
||||||
findHome();
|
findHome();
|
||||||
Serial.println("Home found!");
|
//Serial.println("Home found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -91,6 +115,7 @@ void loop() {
|
|||||||
if (millis() - lastCharTime > 1000) {
|
if (millis() - lastCharTime > 1000) {
|
||||||
releaseSteppers();
|
releaseSteppers();
|
||||||
}
|
}
|
||||||
|
readKey();
|
||||||
}
|
}
|
||||||
while(1) {
|
while(1) {
|
||||||
lineFeed();
|
lineFeed();
|
||||||
@ -162,7 +187,6 @@ void hammer() {
|
|||||||
digitalWrite(hammerPin, HIGH);
|
digitalWrite(hammerPin, HIGH);
|
||||||
delay(13);
|
delay(13);
|
||||||
digitalWrite(hammerPin, LOW);
|
digitalWrite(hammerPin, LOW);
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void freshTape() {
|
void freshTape() {
|
||||||
@ -244,3 +268,23 @@ void releaseSteppers(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t readKey() {
|
||||||
|
for (int i = 30; i < 39; i++) {
|
||||||
|
byte row = i -30;
|
||||||
|
pinMode(i, OUTPUT);
|
||||||
|
digitalWrite(i, LOW);
|
||||||
|
delay(5);
|
||||||
|
uint8_t input = PINA;
|
||||||
|
pinMode(i, INPUT);
|
||||||
|
digitalWrite(1, LOW);
|
||||||
|
|
||||||
|
for (int col = 0; col < 8; col++) {
|
||||||
|
bool set = !((input >> col) & 1);
|
||||||
|
bool last = !((lastKey[row] >> col) & 1);
|
||||||
|
if (set && !last) {
|
||||||
|
Serial.write(keyMap[row][7-col]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastKey[row] = input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user