//Arduino 1.8.3 //STM32F103C, 64k flash //upload method: serial (A9 to RX, A10 to TX) //To upload set Boot0 jumper to 1 (the one further away from reset btn) and press reset (stm will boot from flash wich contains uart to flash uploader) //upload via arduino IDE //To boot program after restart set Boot0 jumper to 0 //#define DEBUG //pins die nicht gehn als output: /* PA15 * PB3 * PB4 * PA12 */ #define SCAN_0 PA1 #define SCAN_1 PA2 #define SCAN_2 PA3 #define SCAN_3 PA4 #define SCAN_4 PA5 #define SCAN_5 PA6 #define SCAN_6 PA7 #define SCAN_7 PB0 #define SCAN_8 PB1 #define IN_A PB13 //geht #define IN_B PB14 //geht #define IN_C PB15 //geht #define IN_D PB5 //geht #define IN_E PB6 //geht #define IN_F PB7 //geht #define IN_G PB8 //geht #define IN_H PB9 //geht #define PIN_LED PC13 #define PIN_COIL_SENSE PB11 #define LEDON LOW #define LEDOFF HIGH #define NUM_SCANPINS 9 int scanaddress[]={SCAN_0,SCAN_1,SCAN_2,SCAN_3,SCAN_4,SCAN_5,SCAN_6,SCAN_7,SCAN_8}; int inaddress[]={IN_A,IN_B,IN_C,IN_D,IN_E,IN_F,IN_G,IN_H}; byte keymatrix[128][NUM_SCANPINS]={ //0 1 2 3 4 5 6 7 8 {255,255,255,255,255,255,255,255,255}, //0 = [NULL] {255,255,255,255,255,255,255,255,255}, //1 = [START OF HEADING] {255,255,255,255,255,255,255,255,255}, //2 = [START OF TEXT] {255,255,255,255,255,255,255,255,255}, //3 = [END OF TEXT] {255,255,255,255,255,255,255,255,255}, //4 = [END OF TRANSMISSION] {255,255,255,255,255,255,255,255,255}, //5 = [ENQUIRY] {255,255,255,255,255,255,255,255,255}, //6 = [ACKNOWLEDGE] {255,255,255,255,255,255,255,255,255}, //7 = [BELL] {255,6,255,255,255,255,255,255,255}, //8 = [BACKSPACE] {255,255,255,255,255,255,255,255,255}, //9 = [HORIZONTAL TAB] {255,2,255,255,255,255,255,255,255}, //10 = [LINE FEED] {255,255,255,255,255,255,255,255,255}, //11 = [VERTICAL TAB] {255,255,255,255,255,255,255,255,255}, //12 = [FORM FEED] {255,2,255,255,255,255,255,255,255}, //13 = [CARRIAGE RETURN] {255,255,255,255,255,255,255,255,255}, //14 = [SHIFT OUT] {255,255,255,255,255,255,255,255,255}, //15 = [SHIFT IN] {255,255,255,255,255,255,255,255,255}, //16 = [DATA LINK ESCAPE] {255,255,255,255,255,255,255,255,255}, //17 = [DEVICE CONTROL 1] {255,255,255,255,255,255,255,255,255}, //18 = [DEVICE CONTROL 2] {255,255,255,255,255,255,255,255,255}, //19 = [DEVICE CONTROL 3] {255,255,255,255,255,255,255,255,255}, //20 = [DEVICE CONTROL 4] {255,255,255,255,255,255,255,255,255}, //21 = [NEGATIVE ACKNOWLEDGE] {255,255,255,255,255,255,255,255,255}, //22 = [SYNCHRONOUS IDLE] {255,255,255,255,255,255,255,255,255}, //23 = [END OF TRANS. BLOCK] {255,255,255,255,255,255,255,255,255}, //24 = [CANCEL] {255,255,255,255,255,255,255,255,255}, //25 = [END OF MEDIUM] {255,255,255,255,255,255,255,255,255}, //26 = [SUBSTITUTE] {255,255,255,255,255,255,255,255,255}, //27 = SCAPE] {255,255,255,255,255,255,255,255,255}, //28 = [FILE SEPARATOR] {255,255,255,255,255,255,255,255,255}, //29 = [GROUP SEPARATOR] {255,255,255,255,255,255,255,255,255}, //30 = [RECORD SEPARATOR] {255,255,255,255,255,255,255,255,255}, //31 = [UNIT SEPARATOR] {255,7,255,255,255,255,255,255,255}, //32 = [SPACE] //H7 H=1 = 7 {7,255,255,255,255,255,255,6,255}, //33 = ! {7,255,255,255,255,255,255,255,5}, //34 = " {255,255,255,255,255,255,255,5,255}, //35 = # {7,255,255,255,255,255,255,255,4}, //36 = $ {7,255,255,255,255,255,255,3,255}, //37 = % {7,255,255,255,255,255,255,255,3}, //38 = & {7,255,255,255,255,255,255,5,255}, //39 = ' {7,255,255,255,255,255,255,255,0}, //40 = ( {7,255,255,255,255,255,255,1,255}, //41 = ) {7,255,255,255,255,255,255,255,7}, //42 = * {255,255,255,255,255,255,255,255,7}, //43 = + {255,255,255,255,7,255,255,255,255}, //44 = , {255,255,255,7,255,255,255,255,255}, //45 = - {255,255,255,255,255,7,255,255,255}, //46 = . {7,255,255,255,255,255,255,0,255}, //47 = / {255,255,255,255,255,255,255,255,1}, //48 = 0 {255,255,255,255,255,255,255,6,255}, //49 = 1 {255,255,255,255,255,255,255,255,5}, //50 = 2 {255,255,255,255,255,255,255,4,255}, //51 = 3 {255,255,255,255,255,255,255,255,4}, //52 = 4 {255,255,255,255,255,255,255,3,255}, //53 = 5 {255,255,255,255,255,255,255,255,3}, //54 = 6 {255,255,255,255,255,255,255,0,255}, //55 = 7 {255,255,255,255,255,255,255,255,0}, //56 = 8 {255,255,255,255,255,255,255,1,255}, //57 = 9 {7,255,255,255,255,7,255,255,255}, //58 = : {7,255,255,255,7,255,255,255,255}, //59 = ; {255,255,255,255,255,255,255,255,255}, //60 = < {7,255,255,255,255,255,255,255,1}, //61 = = {255,255,255,255,255,255,255,255,255}, //62 = > {7,255,255,255,255,255,255,2,255}, //63 = ? {255,255,255,255,255,255,255,255,255}, //64 = @ {7,255,255,255,255,2,255,255,255}, //65 = A {7,255,255,255,6,255,255,255,255}, //66 = B {7,255,255,255,5,255,255,255,255}, //67 = C {7,255,255,255,255,3,255,255,255}, //68 = D {7,255,255,255,255,255,5,255,255}, //69 = E {7,255,255,255,255,5,255,255,255}, //70 = F {7,255,255,255,255,4,255,255,255}, //71 = G {7,255,255,255,255,6,255,255,255}, //72 = H {7,255,255,6,255,255,255,255,255}, //73 = I {7,255,255,255,255,0,255,255,255}, //74 = J {7,255,255,255,255,255,0,255,255}, //75 = K {7,255,255,255,255,255,1,255,255}, //76 = L {7,255,255,255,0,255,255,255,255}, //77 = M {7,255,255,255,2,255,255,255,255}, //78 = N {7,255,255,255,255,255,2,255,255}, //79 = O {7,255,255,2,255,255,255,255,255}, //80 = P {7,255,255,255,255,255,3,255,255}, //81 = Q {7,255,255,5,255,255,255,255,255}, //82 = R {7,255,255,255,255,1,255,255,255}, //83 = S {7,255,255,255,255,255,4,255,255}, //84 = T {7,255,255,255,255,255,6,255,255}, //85 = U {7,255,255,255,4,255,255,255,255}, //86 = V {7,255,255,3,255,255,255,255,255}, //87 = W {7,255,255,255,3,255,255,255,255}, //88 = X {7,255,255,255,1,255,255,255,255}, //89 = Y {7,255,255,4,255,255,255,255,255}, //90 = Z {255,255,255,255,255,255,255,255,255}, //91 = [ {255,255,255,255,255,255,255,255,255}, //92 = '\' {255,255,255,255,255,255,255,255,255}, //93 = ] {255,255,255,255,255,255,255,255,255}, //94 = ^ {7,255,255,7,255,255,255,255,255}, //95 = _ {7,255,255,255,255,255,255,255,2}, //96 = ` {255,255,255,255,255,2,255,255,255}, //97 = a {255,255,255,255,6,255,255,255,255}, //98 = b {255,255,255,255,5,255,255,255,255}, //99 = c {255,255,255,255,255,3,255,255,255}, //100 = d {255,255,255,255,255,255,5,255,255}, //101 = e {255,255,255,255,255,5,255,255,255}, //102 = f {255,255,255,255,255,4,255,255,255}, //103 = g {255,255,255,255,255,6,255,255,255}, //104 = h {255,255,255,6,255,255,255,255,255}, //105 = i {255,255,255,255,255,0,255,255,255}, //106 = j {255,255,255,255,255,255,0,255,255}, //107 = k {255,255,255,255,255,255,1,255,255}, //108 = l {255,255,255,255,0,255,255,255,255}, //109 = m {255,255,255,255,2,255,255,255,255}, //110 = n {255,255,255,255,255,255,2,255,255}, //111 = o {255,255,255,2,255,255,255,255,255}, //112 = p {255,255,255,255,255,255,3,255,255}, //113 = q {255,255,255,5,255,255,255,255,255}, //114 = r {255,255,255,255,255,1,255,255,255}, //115 = s {255,255,255,255,255,255,4,255,255}, //116 = t {255,255,255,255,255,255,6,255,255}, //117 = u {255,255,255,255,4,255,255,255,255}, //118 = v {255,255,255,3,255,255,255,255,255}, //119 = w {255,255,255,255,3,255,255,255,255}, //120 = x {255,255,255,255,1,255,255,255,255}, //121 = y {255,255,255,4,255,255,255,255,255}, //122 = z {255,255,255,255,255,255,255,255,255}, //123 = { {255,5,255,255,255,255,6,255,255}, //124 = | CODE+u {255,255,255,255,255,255,255,255,255}, //125 = } {255,255,255,255,255,255,255,255,255}, //126 = ~ {255,255,255,255,255,255,255,255,255} //127 = [DEL} }; byte keymatrix195[256][NUM_SCANPINS]= {//matrix for 2 byte characters starting with 195 {255,255,255,255,255,255,255,255,255}, // 195,0 = {255,255,255,255,255,255,255,255,255}, // 195,1 = {255,255,255,255,255,255,255,255,255}, // 195,2 = {255,255,255,255,255,255,255,255,255}, // 195,3 = {255,255,255,255,255,255,255,255,255}, // 195,4 = {255,255,255,255,255,255,255,255,255}, // 195,5 = {255,255,255,255,255,255,255,255,255}, // 195,6 = {255,255,255,255,255,255,255,255,255}, // 195,7 = {255,255,255,255,255,255,255,255,255}, // 195,8 = {255,255,255,255,255,255,255,255,255}, // 195,9 = {255,255,255,255,255,255,255,255,255}, // 195,10 = {255,255,255,255,255,255,255,255,255}, // 195,11 = {255,255,255,255,255,255,255,255,255}, // 195,12 = {255,255,255,255,255,255,255,255,255}, // 195,13 = {255,255,255,255,255,255,255,255,255}, // 195,14 = {255,255,255,255,255,255,255,255,255}, // 195,15 = {255,255,255,255,255,255,255,255,255}, // 195,16 = {255,255,255,255,255,255,255,255,255}, // 195,17 = {255,255,255,255,255,255,255,255,255}, // 195,18 = {255,255,255,255,255,255,255,255,255}, // 195,19 = {255,255,255,255,255,255,255,255,255}, // 195,20 = {255,255,255,255,255,255,255,255,255}, // 195,21 = {255,255,255,255,255,255,255,255,255}, // 195,22 = {255,255,255,255,255,255,255,255,255}, // 195,23 = {255,255,255,255,255,255,255,255,255}, // 195,24 = {255,255,255,255,255,255,255,255,255}, // 195,25 = {255,255,255,255,255,255,255,255,255}, // 195,26 = {255,255,255,255,255,255,255,255,255}, // 195,27 = {255,255,255,255,255,255,255,255,255}, // 195,28 = {255,255,255,255,255,255,255,255,255}, // 195,29 = {255,255,255,255,255,255,255,255,255}, // 195,30 = {255,255,255,255,255,255,255,255,255}, // 195,31 = {255,255,255,255,255,255,255,255,255}, // 195,32 = {255,255,255,255,255,255,255,255,255}, // 195,33 = {255,255,255,255,255,255,255,255,255}, // 195,34 = {255,255,255,255,255,255,255,255,255}, // 195,35 = {255,255,255,255,255,255,255,255,255}, // 195,36 = {255,255,255,255,255,255,255,255,255}, // 195,37 = {255,255,255,255,255,255,255,255,255}, // 195,38 = {255,255,255,255,255,255,255,255,255}, // 195,39 = {255,255,255,255,255,255,255,255,255}, // 195,40 = {255,255,255,255,255,255,255,255,255}, // 195,41 = {255,255,255,255,255,255,255,255,255}, // 195,42 = {255,255,255,255,255,255,255,255,255}, // 195,43 = {255,255,255,255,255,255,255,255,255}, // 195,44 = {255,255,255,255,255,255,255,255,255}, // 195,45 = {255,255,255,255,255,255,255,255,255}, // 195,46 = {255,255,255,255,255,255,255,255,255}, // 195,47 = {255,255,255,255,255,255,255,255,255}, // 195,48 = {255,255,255,255,255,255,255,255,255}, // 195,49 = {255,255,255,255,255,255,255,255,255}, // 195,50 = {255,255,255,255,255,255,255,255,255}, // 195,51 = {255,255,255,255,255,255,255,255,255}, // 195,52 = {255,255,255,255,255,255,255,255,255}, // 195,53 = {255,255,255,255,255,255,255,255,255}, // 195,54 = {255,255,255,255,255,255,255,255,255}, // 195,55 = {255,255,255,255,255,255,255,255,255}, // 195,56 = {255,255,255,255,255,255,255,255,255}, // 195,57 = {255,255,255,255,255,255,255,255,255}, // 195,58 = {255,255,255,255,255,255,255,255,255}, // 195,59 = {255,255,255,255,255,255,255,255,255}, // 195,60 = {255,255,255,255,255,255,255,255,255}, // 195,61 = {255,255,255,255,255,255,255,255,255}, // 195,62 = {255,255,255,255,255,255,255,255,255}, // 195,63 = {255,255,255,255,255,255,255,255,255}, // 195,64 = {255,255,255,255,255,255,255,255,255}, // 195,65 = {255,255,255,255,255,255,255,255,255}, // 195,66 = {255,255,255,255,255,255,255,255,255}, // 195,67 = {255,255,255,255,255,255,255,255,255}, // 195,68 = {255,255,255,255,255,255,255,255,255}, // 195,69 = {255,255,255,255,255,255,255,255,255}, // 195,70 = {255,255,255,255,255,255,255,255,255}, // 195,71 = {255,255,255,255,255,255,255,255,255}, // 195,72 = {255,255,255,255,255,255,255,255,255}, // 195,73 = {255,255,255,255,255,255,255,255,255}, // 195,74 = {255,255,255,255,255,255,255,255,255}, // 195,75 = {255,255,255,255,255,255,255,255,255}, // 195,76 = {255,255,255,255,255,255,255,255,255}, // 195,77 = {255,255,255,255,255,255,255,255,255}, // 195,78 = {255,255,255,255,255,255,255,255,255}, // 195,79 = {255,255,255,255,255,255,255,255,255}, // 195,80 = {255,255,255,255,255,255,255,255,255}, // 195,81 = {255,255,255,255,255,255,255,255,255}, // 195,82 = {255,255,255,255,255,255,255,255,255}, // 195,83 = {255,255,255,255,255,255,255,255,255}, // 195,84 = {255,255,255,255,255,255,255,255,255}, // 195,85 = {255,255,255,255,255,255,255,255,255}, // 195,86 = {255,255,255,255,255,255,255,255,255}, // 195,87 = {255,255,255,255,255,255,255,255,255}, // 195,88 = {255,255,255,255,255,255,255,255,255}, // 195,89 = {255,255,255,255,255,255,255,255,255}, // 195,90 = {255,255,255,255,255,255,255,255,255}, // 195,91 = {255,255,255,255,255,255,255,255,255}, // 195,92 = {255,255,255,255,255,255,255,255,255}, // 195,93 = {255,255,255,255,255,255,255,255,255}, // 195,94 = {255,255,255,255,255,255,255,255,255}, // 195,95 = {255,255,255,255,255,255,255,255,255}, // 195,96 = {255,255,255,255,255,255,255,255,255}, // 195,97 = {255,255,255,255,255,255,255,255,255}, // 195,98 = {255,255,255,255,255,255,255,255,255}, // 195,99 = {255,255,255,255,255,255,255,255,255}, // 195,100 = {255,255,255,255,255,255,255,255,255}, // 195,101 = {255,255,255,255,255,255,255,255,255}, // 195,102 = {255,255,255,255,255,255,255,255,255}, // 195,103 = {255,255,255,255,255,255,255,255,255}, // 195,104 = {255,255,255,255,255,255,255,255,255}, // 195,105 = {255,255,255,255,255,255,255,255,255}, // 195,106 = {255,255,255,255,255,255,255,255,255}, // 195,107 = {255,255,255,255,255,255,255,255,255}, // 195,108 = {255,255,255,255,255,255,255,255,255}, // 195,109 = {255,255,255,255,255,255,255,255,255}, // 195,110 = {255,255,255,255,255,255,255,255,255}, // 195,111 = {255,255,255,255,255,255,255,255,255}, // 195,112 = {255,255,255,255,255,255,255,255,255}, // 195,113 = {255,255,255,255,255,255,255,255,255}, // 195,114 = {255,255,255,255,255,255,255,255,255}, // 195,115 = {255,255,255,255,255,255,255,255,255}, // 195,116 = {255,255,255,255,255,255,255,255,255}, // 195,117 = {255,255,255,255,255,255,255,255,255}, // 195,118 = {255,255,255,255,255,255,255,255,255}, // 195,119 = {255,255,255,255,255,255,255,255,255}, // 195,120 = {255,255,255,255,255,255,255,255,255}, // 195,121 = {255,255,255,255,255,255,255,255,255}, // 195,122 = {255,255,255,255,255,255,255,255,255}, // 195,123 = {255,255,255,255,255,255,255,255,255}, // 195,124 = {255,255,255,255,255,255,255,255,255}, // 195,125 = {255,255,255,255,255,255,255,255,255}, // 195,126 = {255,255,255,255,255,255,255,255,255}, // 195,127 = {255,255,255,255,255,255,255,255,255}, // 195,128 = {255,255,255,255,255,255,255,255,255}, // 195,129 = {255,255,255,255,255,255,255,255,255}, // 195,130 = {255,255,255,255,255,255,255,255,255}, // 195,131 = {7,255,255,255,255,255,255,7,255}, // 195,132 = Ä {255,255,255,255,255,255,255,255,255}, // 195,133 = {255,255,255,255,255,255,255,255,255}, // 195,134 = {255,255,255,255,255,255,255,255,255}, // 195,135 = {255,255,255,255,255,255,255,255,255}, // 195,136 = {255,255,255,255,255,255,255,255,255}, // 195,137 = {255,255,255,255,255,255,255,255,255}, // 195,138 = {255,255,255,255,255,255,255,255,255}, // 195,139 = {255,255,255,255,255,255,255,255,255}, // 195,140 = {255,255,255,255,255,255,255,255,255}, // 195,141 = {255,255,255,255,255,255,255,255,255}, // 195,142 = {255,255,255,255,255,255,255,255,255}, // 195,143 = {255,255,255,255,255,255,255,255,255}, // 195,144 = {255,255,255,255,255,255,255,255,255}, // 195,145 = {255,255,255,255,255,255,255,255,255}, // 195,146 = {255,255,255,255,255,255,255,255,255}, // 195,147 = {255,255,255,255,255,255,255,255,255}, // 195,148 = {255,255,255,255,255,255,255,255,255}, // 195,149 = {7,255,255,255,255,255,7,255,255}, // 195,150 = Ö {255,255,255,255,255,255,255,255,255}, // 195,151 = {255,255,255,255,255,255,255,255,255}, // 195,152 = {255,255,255,255,255,255,255,255,255}, // 195,153 = {255,255,255,255,255,255,255,255,255}, // 195,154 = {255,255,255,255,255,255,255,255,255}, // 195,155 = {7,255,255,255,255,255,255,255,6}, // 195,156 = Ü {255,255,255,255,255,255,255,255,255}, // 195,157 = {255,255,255,255,255,255,255,255,255}, // 195,158 = {255,255,255,255,255,255,255,2,255}, // 195,159 = ß {255,255,255,255,255,255,255,255,255}, // 195,160 = {255,255,255,255,255,255,255,255,255}, // 195,161 = {255,255,255,255,255,255,255,255,255}, // 195,162 = {255,255,255,255,255,255,255,255,255}, // 195,163 = {255,255,255,255,255,255,255,7,255}, // 195,164 = ä {255,255,255,255,255,255,255,255,255}, // 195,165 = {255,255,255,255,255,255,255,255,255}, // 195,166 = {255,255,255,255,255,255,255,255,255}, // 195,167 = {255,255,255,255,255,255,255,255,255}, // 195,168 = {255,255,255,255,255,255,255,255,255}, // 195,169 = {255,255,255,255,255,255,255,255,255}, // 195,170 = {255,255,255,255,255,255,255,255,255}, // 195,171 = {255,255,255,255,255,255,255,255,255}, // 195,172 = {255,255,255,255,255,255,255,255,255}, // 195,173 = {255,255,255,255,255,255,255,255,255}, // 195,174 = {255,255,255,255,255,255,255,255,255}, // 195,175 = {255,255,255,255,255,255,255,255,255}, // 195,176 = {255,255,255,255,255,255,255,255,255}, // 195,177 = {255,255,255,255,255,255,255,255,255}, // 195,178 = {255,255,255,255,255,255,255,255,255}, // 195,179 = {255,255,255,255,255,255,255,255,255}, // 195,180 = {255,255,255,255,255,255,255,255,255}, // 195,181 = {255,255,255,255,255,255,7,255,255}, // 195,182 = ö {255,255,255,255,255,255,255,255,255}, // 195,183 = {255,255,255,255,255,255,255,255,255}, // 195,184 = {255,255,255,255,255,255,255,255,255}, // 195,185 = {255,255,255,255,255,255,255,255,255}, // 195,186 = {255,255,255,255,255,255,255,255,255}, // 195,187 = {255,255,255,255,255,255,255,255,6}, // 195,188 = ü {255,255,255,255,255,255,255,255,255}, // 195,189 = {255,255,255,255,255,255,255,255,255}, // 195,190 = {255,255,255,255,255,255,255,255,255}, // 195,191 = {255,255,255,255,255,255,255,255,255}, // 195,192 = {255,255,255,255,255,255,255,255,255}, // 195,193 = {255,255,255,255,255,255,255,255,255}, // 195,194 = {255,255,255,255,255,255,255,255,255}, // 195,195 = {255,255,255,255,255,255,255,255,255}, // 195,196 = {255,255,255,255,255,255,255,255,255}, // 195,197 = {255,255,255,255,255,255,255,255,255}, // 195,198 = {255,255,255,255,255,255,255,255,255}, // 195,199 = {255,255,255,255,255,255,255,255,255}, // 195,200 = {255,255,255,255,255,255,255,255,255}, // 195,201 = {255,255,255,255,255,255,255,255,255}, // 195,202 = {255,255,255,255,255,255,255,255,255}, // 195,203 = {255,255,255,255,255,255,255,255,255}, // 195,204 = {255,255,255,255,255,255,255,255,255}, // 195,205 = {255,255,255,255,255,255,255,255,255}, // 195,206 = {255,255,255,255,255,255,255,255,255}, // 195,207 = {255,255,255,255,255,255,255,255,255}, // 195,208 = {255,255,255,255,255,255,255,255,255}, // 195,209 = {255,255,255,255,255,255,255,255,255}, // 195,210 = {255,255,255,255,255,255,255,255,255}, // 195,211 = {255,255,255,255,255,255,255,255,255}, // 195,212 = {255,255,255,255,255,255,255,255,255}, // 195,213 = {255,255,255,255,255,255,255,255,255}, // 195,214 = {255,255,255,255,255,255,255,255,255}, // 195,215 = {255,255,255,255,255,255,255,255,255}, // 195,216 = {255,255,255,255,255,255,255,255,255}, // 195,217 = {255,255,255,255,255,255,255,255,255}, // 195,218 = {255,255,255,255,255,255,255,255,255}, // 195,219 = {255,255,255,255,255,255,255,255,255}, // 195,220 = {255,255,255,255,255,255,255,255,255}, // 195,221 = {255,255,255,255,255,255,255,255,255}, // 195,222 = {255,255,255,255,255,255,255,255,255}, // 195,223 = {255,255,255,255,255,255,255,255,255}, // 195,224 = {255,255,255,255,255,255,255,255,255}, // 195,225 = {255,255,255,255,255,255,255,255,255}, // 195,226 = {255,255,255,255,255,255,255,255,255}, // 195,227 = {255,255,255,255,255,255,255,255,255}, // 195,228 = {255,255,255,255,255,255,255,255,255}, // 195,229 = {255,255,255,255,255,255,255,255,255}, // 195,230 = {255,255,255,255,255,255,255,255,255}, // 195,231 = {255,255,255,255,255,255,255,255,255}, // 195,232 = {255,255,255,255,255,255,255,255,255}, // 195,233 = {255,255,255,255,255,255,255,255,255}, // 195,234 = {255,255,255,255,255,255,255,255,255}, // 195,235 = {255,255,255,255,255,255,255,255,255}, // 195,236 = {255,255,255,255,255,255,255,255,255}, // 195,237 = {255,255,255,255,255,255,255,255,255}, // 195,238 = {255,255,255,255,255,255,255,255,255}, // 195,239 = {255,255,255,255,255,255,255,255,255}, // 195,240 = {255,255,255,255,255,255,255,255,255}, // 195,241 = {255,255,255,255,255,255,255,255,255}, // 195,242 = {255,255,255,255,255,255,255,255,255}, // 195,243 = {255,255,255,255,255,255,255,255,255}, // 195,244 = {255,255,255,255,255,255,255,255,255}, // 195,245 = {255,255,255,255,255,255,255,255,255}, // 195,246 = {255,255,255,255,255,255,255,255,255}, // 195,247 = {255,255,255,255,255,255,255,255,255}, // 195,248 = {255,255,255,255,255,255,255,255,255}, // 195,249 = {255,255,255,255,255,255,255,255,255}, // 195,250 = {255,255,255,255,255,255,255,255,255}, // 195,251 = {255,255,255,255,255,255,255,255,255}, // 195,252 = {255,255,255,255,255,255,255,255,255}, // 195,253 = {255,255,255,255,255,255,255,255,255}, // 195,254 = {255,255,255,255,255,255,255,255,255} // 195,255 = }; #define TEXTBUFFERSIZE 8192 byte textbuffer[TEXTBUFFERSIZE]; //ca 60-65 Zeilen pro DinA4, a 65 characters (10 Pica), 78 characters (12 Elite) or 97 characters (15 Mikron) uint16_t bufferpos_write=0; uint16_t bufferpos_read=0; #define DELAY_KEYPRESS 100 //delay in ms between keypresses long last_keypress=0; volatile uint16_t count_bufferedchars=0; //keeps track of buffered characters on the typewriter #define MAX_TYPEWRITER_BUFFERCOUNT 2 #define MAXIMUM_COILWAIT 5000 //if no interrupt from coil received decrease buffer count after this time (in ms) void setup() { Serial.begin(9600); pinMode(SCAN_0,INPUT_PULLUP); pinMode(SCAN_1,INPUT_PULLUP); pinMode(SCAN_2,INPUT_PULLUP); pinMode(SCAN_3,INPUT_PULLUP); pinMode(SCAN_4,INPUT_PULLUP); pinMode(SCAN_5,INPUT_PULLUP); pinMode(SCAN_6,INPUT_PULLUP); pinMode(SCAN_7,INPUT_PULLUP); pinMode(SCAN_8,INPUT_PULLUP); pinMode(IN_A,OUTPUT); pinMode(IN_B,OUTPUT); pinMode(IN_C,OUTPUT); pinMode(IN_D,OUTPUT); pinMode(IN_E,OUTPUT); pinMode(IN_F,OUTPUT); pinMode(IN_G,OUTPUT); pinMode(IN_H,OUTPUT); digitalWrite(IN_A,LOW); digitalWrite(IN_B,LOW); digitalWrite(IN_C,LOW); digitalWrite(IN_D,LOW); digitalWrite(IN_E,LOW); digitalWrite(IN_F,LOW); digitalWrite(IN_G,LOW); digitalWrite(IN_H,LOW); pinMode(PIN_COIL_SENSE, INPUT_PULLUP); attachInterrupt(PIN_COIL_SENSE, coilInterrupt, RISING); //pin pulled low if coil powered pinMode(PIN_LED,OUTPUT); digitalWrite(PIN_LED,LEDON); delay(500); digitalWrite(PIN_LED,LEDOFF); //Serial.println("Brother AX-240 Serialmod"); } void loop() { checkSerial(); //check serial buffer and write to textbuffer if (millis()>last_keypress+DELAY_KEYPRESS){ if (count_bufferedchars0 && millis()>last_keypress+MAXIMUM_COILWAIT){ //coil response timeout count_bufferedchars--; //decrease buffer count last_keypress=millis(); } } if (count_bufferedchars>=MAX_TYPEWRITER_BUFFERCOUNT){ digitalWrite(PIN_LED,LEDON); //led on -> wait for buffer to empty }else{ digitalWrite(PIN_LED,LEDOFF); //led off -> buffer isnt full } } void checkSerial(){ while(Serial.available()){ if (Serial.available()>0){ char c=Serial.read(); bufferpos_write++; bufferpos_write%=TEXTBUFFERSIZE; textbuffer[bufferpos_write]=c; //bufferpos_write points to last written char position } } } bool textAvailable(){ if (bufferpos_write!=bufferpos_read){ return true; } return false; } bool checkTextbuffer(){ bool returnvalue=false; //while(Serial.available()){ //if (Serial.available()>0){ if (textAvailable()) { //buffer contains unread chars bufferpos_read++;//bufferpos_read points to last read char position bufferpos_read%=TEXTBUFFERSIZE; char c = textbuffer[bufferpos_read]; #ifdef DEBUG Serial.print((uint8_t)c); //echo Serial.print("="); //echo Serial.println(c); //echo #endif if (c==195 || c==194) { //umlaut #ifdef DEBUG Serial.print("Uml:"); #endif while (!textAvailable()){ checkSerial(); } //wait for next byte and checkSerial in between bufferpos_read++;//bufferpos_read points to last read char position bufferpos_read%=TEXTBUFFERSIZE; char c2=textbuffer[bufferpos_read]; #ifdef DEBUG Serial.println((uint8_t)c2); //echo #endif sendChar(c,c2); //2 byte character returnvalue=true; }else{ sendChar(c,0); //normal 1 byte character returnvalue=true; } } //} return returnvalue; //true= character send, false=buffer was empty } void sendChar(char c,char c2) { //c2 =0 for 1 byte characters uint8_t keypress[NUM_SCANPINS]={255,255,255,255,255,255,255,255,255}; //keypress contains id of input pin. 255=not pressed, A=0, B=1 ... //check if key is implemented (not all 255,255,255,..) bool keyimplemented=false; for (uint8_t i=0;i=32 && c<127) || c==10 || c==13 ) ) { //1 byte char #ifdef DEBUG Serial.println("1 byte char"); #endif for (uint8_t i=0;i=32){ //not recognized character (everything else) and not a control command keypress[1]=7; // [SPACE] //print space to keep text aligned } unsigned int scanaddr; unsigned int inaddr; //Update count buffered chars if ((c>32 && c<127) ) { //pressed key uses hammer. (32 is space) if (keyimplemented){ //keymatrix was implemented for c (not 255,255...) count_bufferedchars++; //character send to typewriter. Increase character buffer count } } //digitalWrite(PIN_LED,LEDON); #define HOLDCYCLES 3 for (uint8_t hold=0;hold transistor pulls input of printer to ground //} } } } //digitalWrite(PIN_LED,LEDOFF); } void coilInterrupt(){ if (count_bufferedchars>0){ count_bufferedchars--; } }