Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Dot Matrix Screen

28. September 2012

Mit zwei 5 x 7 Dot Matrixen wurde ein einfaches Display zur Ausgabe von Text erstellt. Mit Hilfe von 4 Shiftregister werden die zwei Mal 35 LEDs angesteuert. Die Texteingabe erfolgt über den Computer via Processing. Die Eingabe wird über den Seriellenport an den Arduino Chip geschickt und vom Ardiono verarbeitet. Sobald Arduino die Aufgabe abeschlossen hat, sendet es an Processing eine Statusänderung und ermöglicht so die nächste Eingabe. Alle Buchstaben, Zahlen und Zeichen wurden in einzelnen Funktionen definiert. Ein Zeichen besteht aus mehreren Anweisungen, die jewils einen Punkt auf der Dotmatrix ansteuern. Somit leuchtet immer nur ein Punkt auf der Matrix. Durch die schnelle Abfolge ist das jedoch nicht mehr erkennbar. Diese Methode bietet zwar den Vorteil, dass Animationen sehr einfach umgesetzt werden können. Dafür ist es sehr Leistungsintensiv und bringt das System bei zwei Matrixen an die Grenzen. Video
#define BUFFER_SIZE 140 // actual size of the buffer for integer values: (numberOfValsToRead*6)+(numberOfValsToRead-1)
 
char incommingBuffer[BUFFER_SIZE]; // buffer to store incomming values
char incomming; // primary buffer to store single incommning bytes
int incommingCounter = 0; // counter for counting the positions inside the buffer



int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

long currentMillis = 0;
long previousMillis = 0;
int interval = 150;

String output = "*";
String serialInput = "";
//int serialLoopSet = "";
int stringLenght = output.length();
int stringPixel = stringLenght * 6;

int count = 14;

 
 
void setup() {
  
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  //Serial.println(stringPixel);
  
}


void readSerial() {
  
  while(Serial.available()) {
    
    incomming = Serial.read(); // read single incommning bytes
 
    if(incomming != '\r') { //if no carriage return is received proceed in reading the serial port
      incommingBuffer[incommingCounter++] = incomming; // go on the next position in the buffer
    } else { //read until a carriage ('\r') is received
    
      incommingBuffer[incommingCounter] = '\0'; // set the last byte to NULL to sign it for the string operators
 
      char *a = strtok(incommingBuffer, ";"); // split the string after delimiters into tokens
      //char *b = strtok(NULL, ",.;"); // ...
      //char *c = strtok(NULL, ",.;"); // ...
      //char *d = strtok(NULL, ",.;"); // add another line if needed
 
      //firstValue = atoi(a); // convert the strings into integers
      //secondValue = atoi(b); // ...
      //thirdValue = atoi(c); // ...
      //fourthValue = atoi(d); // add another line if needed
    
      serialInput = a;
       
      incommingCounter = 0; // reset the counter
      memset(incommingBuffer, 0, BUFFER_SIZE); //overwrite the incommingBuffer
    }
    
  }
  
}

 
void loop() {
  
  if (output.length() == 0) {
    
    readSerial();
    output = serialInput;
    serialInput = "";
    
    /*
    Serial.print("SENT: ");
    Serial.print(output);
    Serial.print(',');
    Serial.println(); */
    
    stringLenght = output.length();
    stringPixel = stringLenght * 6;
    
  } else {
    
    currentMillis = millis();
    
    int offset = 0;
    for (int i = 0; i < output.length(); i++) {
  
      switch (output[i]) {
        case 'A':
          A(count + offset, 0);
          break;
        case 'B':
          B(count + offset, 0);
          break;
        case 'C':
          C(count + offset, 0);
          break;
        case 'D':
          D(count + offset, 0);
          break;
        case 'E':
          E(count + offset, 0);
          break;
        case 'F':
          Fx(count + offset, 0);
          break;
        case 'G':
          G(count + offset, 0);
          break;
        case 'H':
          H(count + offset, 0);
          break;
        case 'I':
          I(count + offset, 0);
          offset--;
          break;
        case 'J':
          J(count + offset, 0);
          break;
        case 'K':
          K(count + offset, 0);
          break;
        case 'L':
          L(count + offset, 0);
          offset--;
          break;
        case 'M':
          M(count + offset, 0);
          offset++;
          break;
        case 'N':
          N(count + offset, 0);
          break;
        case 'O':
          O(count + offset, 0);
          break;
        case 'P':
          P(count + offset, 0);
          break;
        case 'Q':
          Q(count + offset, 0);
          break;
        case 'R':
          R(count + offset, 0);
          break;
        case 'S':
          S(count + offset, 0);
          break;
        case 'T':
          T(count + offset, 0);
          break;
        case 'U':
          U(count + offset, 0);
          break;
        case 'V':
          V(count + offset, 0);
          break;
        case 'W':
          W(count + offset, 0);
          offset++;
          break;
        case 'X':
          X(count + offset, 0);
          offset++;
          break;
        case 'Y':
          Y(count + offset, 0);
          offset++;
          break;
        case 'Z':
          Z(count + offset, 0);
          break;
        case 'Ä':
          ae(count + offset, 0);
          offset++;
          break;
        case 'Ö':
          oe(count + offset, 0);
          offset++;
          break;
        case 'Ü':
          ue(count + offset, 0);
          break;
        case '1':
          Num1(count + offset, 0);
          offset--;
          break;
        case '2':
          Num2(count + offset, 0);
          break;
        case '3':
          Num3(count + offset, 0);
          offset--;
          break;
        case '4':
          Num4(count + offset, 0);
          offset--;
          break;
        case '5':
          Num5(count + offset, 0);
          offset--;
          break;
        case '6':
          Num6(count + offset, 0);
          break;
        case '7':
          Num7(count + offset, 0);
          break;
        case '8':
          Num8(count + offset, 0);
          break;
        case '9':
          Num9(count + offset, 0);
          break;
        case '0':
          Num0(count + offset, 0);
          offset--;
          break;
        case ' ':
          space(count + offset, 0);
          offset--;
          break;
        case '.':
          period(count + offset, 0);
          offset-=3;
          break;
        case '!':
          exclamation(count + offset, 0);
          offset-=3;
          break;
        case '?':
          Questionmark(count + offset, 0);
          offset-=1;
          break;
        case ':':
          Colon(count + offset, 0);
          offset-=3;
          break;
        case ',':
          Comma(count + offset, 0);
          offset-=2;
          break;
        case '*':
          asteriks(count + offset, 0);
          offset+=2;
          break;
        case '%':
          petterson(count + offset, 0);
          offset+=2;
          break;
        default:
          Unkn(count + offset, 0);
          offset+=1;
          break;
      }
      
      offset = offset + 5;
      
    }
      
    if (currentMillis - previousMillis > interval) {
      
      previousMillis = currentMillis;
      count--;
      
      if (count <= stringPixel * -1) {
        count = 14;
        
          output = "";
        
        Serial.print("1");
        Serial.print(',');
        Serial.println();
  
      }
      
    }
    
  }
  
}
 
 
void registerWrite(int _verticalPin, int _horizontalPin) {
  
  _verticalPin--;
  _horizontalPin--;
  
  //_verticalPin = 4 - _verticalPin;
  _horizontalPin = 13 - _horizontalPin;
  
  if (_horizontalPin >= 0 && _horizontalPin <= 14) {
  
    byte bitsToSend1 = 255;
    byte bitsToSend2 = 0;
    
    //Serial.println(_horizontalPin);
    
    digitalWrite(latchPin, LOW);
    
    if (_horizontalPin < 7) {
            
      bitWrite(bitsToSend2, _horizontalPin, HIGH);
      shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
    
      bitWrite(bitsToSend1, _verticalPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
      
      shiftOut(dataPin, clockPin, MSBFIRST, 0);
      shiftOut(dataPin, clockPin, MSBFIRST, 0);
      
    } else {
      
      shiftOut(dataPin, clockPin, MSBFIRST, 0);
      shiftOut(dataPin, clockPin, MSBFIRST, 0);
      
      bitWrite(bitsToSend2, _horizontalPin - 7, HIGH);
      shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend2);
    
      bitWrite(bitsToSend1, _verticalPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend1);
      
    }
    
    digitalWrite(latchPin, HIGH);
    
  } 
}


void A(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 4+x);
  
}

void B(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void C(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void D(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void E(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);

  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  
}

void Fx(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  
  registerWrite(y+5, 1+x);
  
}

void G(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void H(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 4+x);
  
}

void I(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 2+x);
  
  registerWrite(y+3, 2+x);
  
  registerWrite(y+4, 2+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void J(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);

  registerWrite(y+2, 4+x);

  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void K(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 4+x);
  
}

void L(int x, int y) {
  
  registerWrite(y+1, 1+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 1+x);
  
  registerWrite(y+4, 1+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void M(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 4+x);
  registerWrite(y+2, 5+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 5+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 5+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 5+x);
  
}

void N(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 4+x);
  
}

void O(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void P(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  
  registerWrite(y+5, 1+x);
  
}

void Q(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  
}

void R(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 4+x);
  
}

void S(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);

  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void T(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  registerWrite(y+1, 5+x);

  registerWrite(y+2, 3+x);

  registerWrite(y+3, 3+x);

  registerWrite(y+4, 3+x);

  registerWrite(y+5, 3+x);
  
}

void U(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void V(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void W(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 5+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 5+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 4+x);
  registerWrite(y+4, 5+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 5+x);
  
}

void X(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 5+x);
  
}

void Y(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 5+x);
  
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 3+x);
  
}

void Z(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 2+x);
  
  registerWrite(y+4, 1+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  
}

void ae(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 4+x);
  
}

void oe(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void ue(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 4+x);
  
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void Num1(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  
  registerWrite(y+2, 2+x);
  
  registerWrite(y+3, 2+x);
  
  registerWrite(y+4, 2+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void Num2(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 2+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  
}

void Num3(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 2+x);
  
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  
}

void Num4(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 3+x);
  
}

void Num5(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  
}

void Num6(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void Num7(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 2+x);
  
  registerWrite(y+5, 2+x);
  
}

void Num8(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void Num9(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  
}

void Num0(int x, int y) {
  
  registerWrite(y+1, 2+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 3+x);
  
  registerWrite(y+5, 2+x);
  
}

void space(int x, int y) {
  
}

void period(int x, int y) {
  registerWrite(y+5, 1+x);
}

void exclamation(int x, int y) {
  
  registerWrite(y+1, 1+x);
  
  registerWrite(y+2, 1+x);
  
  registerWrite(y+3, 1+x);
  
    
  registerWrite(y+5, 1+x);
  
}

void asteriks(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 3+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 3+x);
  
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 5+x);
  
}

void Questionmark(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);

  registerWrite(y+2, 3+x);
  
  registerWrite(y+3, 2+x);

  
  registerWrite(y+5, 2+x);
  
}

void petterson(int x, int y) {
  
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  registerWrite(y+1, 5+x);
  registerWrite(y+1, 6+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 3+x);
  registerWrite(y+2, 5+x);
  registerWrite(y+2, 7+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 7+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 4+x);
  registerWrite(y+4, 6+x);
  registerWrite(y+4, 7+x);
  
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  registerWrite(y+5, 5+x);
  registerWrite(y+5, 6+x);
  
}

void Unkn(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 5+x);
  
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 5+x);
  
}

void Comma(int x, int y) {
  
  registerWrite(y+4, 2+x);
  
  registerWrite(y+5, 1+x);
  
}

void Colon(int x, int y) {
  
  registerWrite(y+3, 1+x);
  
  registerWrite(y+5, 1+x);
  
}

void Bsp5(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  registerWrite(y+1, 5+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 3+x);
  registerWrite(y+2, 4+x);
  registerWrite(y+2, 5+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 4+x);
  registerWrite(y+3, 5+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  registerWrite(y+4, 5+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  registerWrite(y+5, 5+x);
  
}

void Bsp(int x, int y) {
  
  registerWrite(y+1, 1+x);
  registerWrite(y+1, 2+x);
  registerWrite(y+1, 3+x);
  registerWrite(y+1, 4+x);
  
  registerWrite(y+2, 1+x);
  registerWrite(y+2, 2+x);
  registerWrite(y+2, 3+x);
  registerWrite(y+2, 4+x);
  
  registerWrite(y+3, 1+x);
  registerWrite(y+3, 2+x);
  registerWrite(y+3, 3+x);
  registerWrite(y+3, 4+x);
  
  registerWrite(y+4, 1+x);
  registerWrite(y+4, 2+x);
  registerWrite(y+4, 3+x);
  registerWrite(y+4, 4+x);
  
  registerWrite(y+5, 1+x);
  registerWrite(y+5, 2+x);
  registerWrite(y+5, 3+x);
  registerWrite(y+5, 4+x);
  
}
import controlP5.*;
ControlP5 cp5;

import processing.serial.*;
Serial serialPort;

String textSend = "";
int serialStatus = 0;

long currentMillis = 0;
long previousMillis = 0;
int interval = 500;
int stat = 0;

int themColor1 = color(1, 108, 158);
int themColor2 = color(2, 52, 77);


void setup() {
  
  size(700, 400);
  PFont font = createFont("arial", 20);
  
  cp5 = new ControlP5(this);
                   
  cp5.addTextfield("text")
     .setPosition(175, 150)
     .setSize(250, 50)
     .setFont(createFont("arial", 20))
     .setAutoClear(false)
     ;
       
  cp5.addBang("send")
     .setPosition(435, 150)
     .setSize(90,50)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;    
  
  cp5.setAutoDraw(false);
  
  textFont(font);
  
  serialPort = new Serial(this, "/dev/tty.usbserial-A700ewkB", 9600);
  
}


void draw() {
  
  currentMillis = millis();
  
  background(50);
  fill(200);
  
  if(serialStatus == 1)
  
    cp5.draw();
    
  else {
    
    progressBar(305, 160, stat);
      
  }
  
  if (currentMillis - previousMillis > interval) {
      
      previousMillis = currentMillis;
      if (stat == 1) {
        stat = 0;
      } else {
        stat = 1;
      }
    
  }
    
}


public void send() {
  
  textSend = cp5.get(Textfield.class,"text").getText();
  
  serialStatus = 0;
  cp5.get(Textfield.class,"text").clear();
  
  textSend = textSend.replace(';', '.');
  textSend = textSend.toUpperCase();
  
  serialPort.write(textSend);
  serialPort.write(";");
  serialPort.write("\r");
  
}


void serialEvent(Serial serialPort) {

  if (serialPort.available() > 0) {
  
    String completeString = serialPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
    if (completeString != null) { // If there is valid data insode the String
    
      trim(completeString); // Remove whitespace characters at the beginning and end of the string
      String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
      serialStatus = int(seperateValues[0]);
      //println(completeString);
      
      if (serialStatus == 1) {
        //println("Plopp!");
        serialStatus = 1;
      }
      
    }
    
  }
  
}


void progressBar(int _x, int _y, int _stat) {
  
  PFont font = createFont("arial", 20);
  
  int _segmentWidth = 15;
  int _segmentHeight = 15;
  
  noStroke();
  
  for (int i = 0; i < 2; i++) {
    
    if (_stat == 1) {
      fill(themColor1);
      _stat = 0;
    } else {
      fill(themColor2);
      _stat = 1;
    }
    
    rect(_x + i * _segmentWidth, _y, _segmentWidth, _segmentHeight);
    
  }
  
  fill(255);
  textFont(font, 8);
  text("VERARBEITUNG", _x, _y + _segmentHeight + 10);
  
}


void keyPressed() {
  
  if(serialStatus == 1) {
    if (key == ENTER)
      send();
  }

}