From 86ac02d9ebc3ab9f802f184cce689bba4744009f Mon Sep 17 00:00:00 2001 From: Sven Marc Gehring Date: Tue, 28 Jul 2015 08:44:37 +0200 Subject: [PATCH 1/6] Refactored matrix library code --- Matrix_RKAG.cpp | 434 +++++++++++++++++++++++------------------------- Matrix_RKAG.h | 64 +++---- 2 files changed, 239 insertions(+), 259 deletions(-) diff --git a/Matrix_RKAG.cpp b/Matrix_RKAG.cpp index f09d9f9..bfbed90 100644 --- a/Matrix_RKAG.cpp +++ b/Matrix_RKAG.cpp @@ -1,276 +1,256 @@ /** -* @file Matrix_RKAG.cpp -* @author Benjamin Marty (bmarty@kochag.ch) -* @date 09.03.2014 -* @brief cpp File of Matrix_RKAG Library -* @bug No known bugs. -* @version 1.1.0 -* +* \file Matrix_RKAG.cpp +* \brief RKAG Matrix library source file +* \author Benjamin Marty +* \author Sven Gehring +* \version 1.2.0 */ -// include this library's description file -#include "Matrix_RKAG.h" - #include #include - #include -#include "font.h" +#include "Matrix_RKAG.h" #include "acc_register.h" +#include "font.h" -#define RCK A3 //RCK Pin von SR -#define SRCLR A2 //'' +#define RCK A3 /* define RCK as Arduino Pin A3 */ +#define SRCLR A2 /* define SRCLR as Arduino Pin A2 */ +#define PCF_ADRESS 0x38 /* define port expander address as 0x38 */ +#define PCF_MASKBTN 1 /* indicator if button values (b0 - b2 should be masked in pcf write) */ +#define BTN_THRESHOLD 2 /* button counter threshold for detecting button press */ -#define PCF_ADRESS 0x38 //Portexpander Adresse -//Zwischenspeicher (Array) für die nächste Ãœbertragung auf die Matrix -int data[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -//Pin RCK, SRCLR, SS konfiguieren sobald Instanz gebildet wird -matrix_class::matrix_class() -{ - pinMode(RCK, OUTPUT); //Register Clock high Pegel sensitive - pinMode(SRCLR, OUTPUT); //SRClear low Pegel sensitive - pinMode(SS, OUTPUT); +static int data[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; /* matrix spi buffer */ - digitalWrite(RCK, 0); - digitalWrite(SRCLR, 1); - digitalWrite(SS, 1); + + + +/** \brief Matrix class constructor +* Construct a new instance of the matrix class, initialize pins RCK, SRCLR & SS +* +*/ +rkag_matrix::rkag_matrix() { + pinMode(RCK, OUTPUT); /* register clock, high active */ + pinMode(SRCLR, OUTPUT); /* SRClear, low active */ + pinMode(SS, OUTPUT); + + digitalWrite(RCK, 0); + digitalWrite(SRCLR, 1); + digitalWrite(SS, 1); } -//Schlaufe die auf den Hardware Timer angebunden ist -void matrix_timer() -{ - static int zaehler; - - //SR Speicher Reset - digitalWrite(SRCLR, 1); - digitalWrite(SRCLR, 0); - digitalWrite(SRCLR, 1); - - //Zeile - SPI.transfer(0x80 >> zaehler); - - //Daten aus Matrix Array rüberschiben - SPI.transfer(data[zaehler]); - - //Puls generieren -> Schieberegister auf Output Buffer schalten - digitalWrite(RCK, 0); - digitalWrite(RCK, 1); - digitalWrite(RCK, 0); - - if (zaehler == 7) - { - //Zaehler auf 0 stellen um erneut wieder 8 Bit zu uebetragen - zaehler = 0; - } - else - { - //Zaehler hochzaehlen da noch nicht 8 Bit erreicht - zaehler++; - } + +/** \brief Matrix loop that is bound to the hardware timer +* This method will be bound to the hardware timer and called in every iteration +*/ +void matrix_timer() { + static int counter; + + digitalWrite(SRCLR, 1); /* SR storage reset */ + digitalWrite(SRCLR, 0); + digitalWrite(SRCLR, 1); + + SPI.transfer(0x80 >> counter); /* transfer single row */ + SPI.transfer(data[counter]); /* transfer counter data */ + + digitalWrite(RCK, 0); /* generate puls, set register to output buffer */ + digitalWrite(RCK, 1); + digitalWrite(RCK, 0); + + if (counter == 7) counter = 0; /* reset counter to write another 8 bit */ + else counter++; /* increment counter to calcuate 8 bit */ } -//Initalisierung (Timer konfiguieren, SPI initalisieren) -void matrix_class::init() -{ - Wire.begin(); //I2C Interface starten und Bus als Master betreten - //pcf_write(0x00); //PCF reseten - Timer1.initialize(800); //1000000 = 1 Sekunde - 80000 = 8ms = ca. 15.6Hz Updaterate des kompletten Bild - Timer1.attachInterrupt(matrix_timer); //Funktion matrix_timer bei jedem Timerueberlauf ausführen +/** \brief Initialize matrix class instance +* This will configure the instance bound timer as well as the +* internal SPI connection used to transfer the data. +*/ +void rkag_matrix::init() { + Wire.begin(); /* initialize i2c bus a smaster */ + + Timer1.initialize(800); /* initialize timer with 8ms (~15.6Hz update rate) */ + Timer1.attachInterrupt(matrix_timer); /* bind method 'matrix_timer' to hardware timer */ - SPI.begin(); //SPI Starten - SPI.setClockDivider(SPI_CLOCK_DIV128); //16Mhz/128 = 125kHz - SPI.setBitOrder(LSBFIRST); //MSB zuerst senden + SPI.begin(); /* initialize spi bus */ + SPI.setClockDivider(SPI_CLOCK_DIV128); /* set spi clock divider to 128, 16Mhz/128 = 125kHz */ + SPI.setBitOrder(LSBFIRST); /* set bit order to send LSB first */ } -//Updateroutine für I/O Hardware an der Matrix -int matrix_class::read_io() -{ - char counter_value = 2; - char pcf_state; - - microseconds_now = micros(); //Aktuellen us Wert speichern - pcf_state = pcf_read(); //Aktuellen Wert aus PCF Portexpander speichern - potentiometer_0 = 1023-(analogRead(A0)); //Potentiometer lesen und in potentiometer_0 schreiben - - //Werte der drei Tasten reseten - taste_1 = 0; - taste_2 = 0; - taste_3 = 0; - - //Prüfen ob seit dem letzten mal bereits 5ms vergangen sind. - if((microseconds_now - microseconds_saved) > 5000) - { - //Prüfen ob Taste gedrückt, wenn ja Zähler hochzählen, wenn nicht Zähler auf 0 - if(pcf_state & 0x01) - { - counter_taste_1++; - } - - if(pcf_state & 0x02) - { - counter_taste_2++; - } - - if(pcf_state & 0x04) - { - counter_taste_3++; - } - - //Aktuelle micros speichern für nächsten Durchgang - microseconds_saved = micros(); - } - - //Wenn der Counter höher als counter_value ist & das Bit des entsprechenden Taster Low ist dann taste gedrückt worden - if(counter_taste_1 > counter_value && (!(pcf_state & 0x01))) - { - taste_1 = 1; - counter_taste_1 = 0; - } - - - if(counter_taste_2 > counter_value && (!(pcf_state & 0x02))) - { - taste_2 = 1; - counter_taste_2 = 0; - } - - - if(counter_taste_3 > counter_value && (!(pcf_state & 0x04))) - { - taste_3 = 1; - counter_taste_3 = 0; - } -} -//Matrix Schreibfunktion um Daten auf die Matrix zu schreiben -void matrix_class::write(char byte1, char byte2, char byte3, char byte4, char byte5, char byte6, char byte7, char byte8) -{ - //Vom Nutzer stammende Daten Byte für Byte ins Data Array kopieren - data[0] = byte1; - data[1] = byte2; - data[2] = byte3; - data[3] = byte4; - data[4] = byte5; - data[5] = byte6; - data[6] = byte7; - data[7] = byte8; +/** \brief Internal update routine to update matrix IO +*/ +int rkag_matrix::read_io() { + char pcf_state; /* port expander state buffer */ + + microseconds_now = micros(); /* get current runtime microseconds value */ + pcf_state = pcf_read(); /* get current value from pcf port expander */ + potentiometer_0 = 1023-(analogRead(A0)); /* read potentiometer from analog input */ + + button_1 = button_2 = button_3 = 0x00; /* reset input button values */ + + if ((microseconds_now - microseconds_saved) > 5000) { /* over 5ms delayed? */ + if(pcf_state & 0x01) counter_button_1++; /* get button inputs */ + if(pcf_state & 0x02) counter_button_2++; + if(pcf_state & 0x04) counter_button_3++; + + microseconds_saved = micros(); /* save new loop microsecond value */ + } + + + /* if button counter is higher than the button threshold */ + /* and the input is now 0 (released), the button has been pressed */ + if (counter_button_1 > BTN_THRESHOLD && (!(pcf_state & 0x01))) { + counter_button_1 = 0x00; + button_1 = 0x01; + } + + + if (counter_button_2 > BTN_THRESHOLD && (!(pcf_state & 0x02))) { + counter_button_2 = 0x00; + button_2 = 0x01; + } + + + if (counter_button_3 > BTN_THRESHOLD && (!(pcf_state & 0x04))) { + counter_button_3 = 0x00; + button_3 = 0x01; + } } -//Matrix Schreibfunktion um Daten von einem Array auf die Matrix zu schreiben -void matrix_class::write_array(char matrix[]) -{ - //Vom Nutzer stammende Daten Byte für Byte ins Data Array kopieren - data[0] = matrix[0]; - data[1] = matrix[1]; - data[2] = matrix[2]; - data[3] = matrix[3]; - data[4] = matrix[4]; - data[5] = matrix[5]; - data[6] = matrix[6]; - data[7] = matrix[7]; + +/** \brief Write a full set of characters to the matrix +* Each character stands for a line on the matrix display, starting from the top +* +* \param byte1 Binary value of line 1 led states +* \param byte2 Binary value of line 2 led states +* \param byte3 Binary value of line 3 led states +* \param byte4 Binary value of line 4 led states +* \param byte5 Binary value of line 5 led states +* \param byte6 Binary value of line 6 led states +* \param byte7 Binary value of line 7 led states +* \param byte8 Binary value of line 8 led states +*/ +void rkag_matrix::write (char byte1, char byte2, char byte3, char byte4, + char byte5, char byte6, char byte7, char byte8) { + data[0] = byte1; + data[1] = byte2; + data[2] = byte3; + data[3] = byte4; + data[4] = byte5; + data[5] = byte6; + data[6] = byte7; + data[7] = byte8; } -//Matrix Löschfunktion -void matrix_class::clear(void) -{ - //Alle 8 Byte löschen - for(int x = 0; x < 8; x++) - { - data[x] = 0; - } + +/** \brief Write a character array to the matrix display +* Equals '::write' but takes a full character array as input +* +* \param matrix Array with all line data chars +*/ +void rkag_matrix::write_array(char matrix[]) { + for (int i = 0; i < 8; i++) data[i] = matrix[i]; } -//Matrix Sample/Muster Funktion -void matrix_class::sample(int number) -{ - //Prüfen welches Muster, danach entsprechende Muster in Data Array kopieren - switch(number) - { - case 0: - data[0] = 0b10101010; - data[1] = 0b01010101; - data[2] = 0b10101010; - data[3] = 0b01010101; - data[4] = 0b10101010; - data[5] = 0b01010101; - data[6] = 0b10101010; - data[7] = 0b01010101; - break; - case 1: - data[0] = ~0b10101010; - data[1] = ~0b01010101; - data[2] = ~0b10101010; - data[3] = ~0b01010101; - data[4] = ~0b10101010; - data[5] = ~0b01010101; - data[6] = ~0b10101010; - data[7] = ~0b01010101; - break; - } + +/** \brief Write a character to the matrix display +* +* \param character The character to write +*/ +void rkag_matrix::write_char(char character) { + char buffer[8]; /* buffer to store fron from flash */ + + rkag_matrix::clear(); /* clear matrix screen */ + + for(int i = 0; i < 8; i++) /* read font from flash */ + buffer[i] = pgm_read_byte(&font[character][i]); + + + for (int i = 0; i < 8; i++) { /* write font from buffer to matrix display */ + for (int j = 0; j < 8; j++) { + if (buffer[i] & (0x01 << j)) + data[i] |= (0x80 >> j) << 1; + } + } } -//Matrix Font Funktion -void matrix_class::font_write(int numb) -{ - //Buffer um Font aus Flash in SRAM zwischenzuspeichern - char buffer[8]; - - matrix_class::write(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - - //Font Daten aus Flash Speicher holen und in Matrix Array schreiben - for(int x = 0; x <= 7; x++) - { - buffer[x] = pgm_read_byte(&font[numb][x]); - } - - for(int x = 0; x <= 7; x++) - { - for(int z = 0; z <= 7; z++) - { - if(buffer[x] & (0x01 << z)) - { - data[x] |= (0x80 >> z) << 1; - } - - } - } + +/** \brief Clear the matrix by resetting all lines to zero +* +*/ +void rkag_matrix::clear(void) { + for (int i = 0; i < 8; i++) data[i] = 0x00; } -//PCF Ausgabe Funktion -void matrix_class::pcf_write(int data) -{ - Wire.beginTransmission(PCF_ADRESS); - Wire.write((~(0x07) & data )); //Daten schreiben, hinterste 3 Bit ignorieren da daran die Taster sind. Diese Zeile kommentieren falls untere Zeile auskommentiert wird. +/** \brief Write a matrix sample to the screen +* This will output a simple bit pattern to the screen for testing +* +* \param parttern The id of the pattern that should be drawn +*/ +void rkag_matrix::sample(int pattern) { + switch(pattern) { + case 0: + for (int i = 0; i < 8; i++) + data[i] = ((i % 2) == 0) ? 0b10101010 : 0b01010101; + + break; + case 1: + for (int i = 0; i < 8; i++) + data[i] = ((i % 2) == 0) ? 0b01010101 : 0b10101010; + + break; + default: { + break; + } + } +} - //Wire.write(data); //Diese Zeile auskommentieren falls auch die 3 "gesperrten" Bits am Ende genutzt werden wollen. - Wire.endTransmission(); +/** \brief Write data to the i2c bus +* This will write the given data to the i2c bus +* +* \param data The data value +*/ +void rkag_matrix::pcf_write(int data) { + Wire.beginTransmission(PCF_ADRESS); /* start bus transimission with pcf instance */ + + #if ( PCF_MASKBTN == 1 ) + Wire.write((~(0x07) & data )); /* write pcf data without the last 3 bits (buttons) */ + #else + Wire.write(data); /* write all pcf data */ + #endif + Wire.endTransmission(); /* end bus transmission */ } -//PCF Eingabe Funktion -int matrix_class::pcf_read() -{ - int pcf_buffer; - Wire.beginTransmission(PCF_ADRESS); +/** \brief Read data from the i2c bus +* This will read the input data from the i2c bus +* +* \return int The received data +*/ +int rkag_matrix::pcf_read() { + int pcf_buffer; /* buffer for pcf input value */ - Wire.requestFrom(PCF_ADRESS, 1); + Wire.beginTransmission(PCF_ADRESS); /* start bus transimission with pcf instance */ + Wire.requestFrom(PCF_ADRESS, 1); /* request pcf data from correct address */ - while(Wire.available() == 0); + while(Wire.available() == 0); /* wait until data is received */ - pcf_buffer = Wire.read(); + pcf_buffer = Wire.read(); /* read data into the buffer */ - return pcf_buffer; + return pcf_buffer; /* return buffer value */ } -matrix_class matrix; +/** + * Global instance of the matrix class + */ +rkag_matrix matrix; diff --git a/Matrix_RKAG.h b/Matrix_RKAG.h index 298c883..437e659 100644 --- a/Matrix_RKAG.h +++ b/Matrix_RKAG.h @@ -1,45 +1,45 @@ /** -* @file Matrix_RKAG.h -* @author Benjamin Marty (bmarty@kochag.ch) -* @date 09.03.2014 -* @brief Header File of Matrix_RKAG Library -* @bug No known bugs. -* @version 1.1.0 -* +* \file Matrix_RKAG.cpp +* \brief RKAG Matrix library source file +* \author Benjamin Marty +* \author Sven Gehring +* \version 1.2.0 */ -// ensure this library description is only included once -#ifndef Matrix_RKAG_h -#define Matrix_RKAG_h +#ifndef MATRIX_RKAG_H +#define MATRIX_RKAG_H #include "Arduino.h" #include #include -// library interface description -class matrix_class -{ - // user-accessible "public" interface + +/** \brief RKAG Matrix library class +* This class grants access to all major matrix functionality to +* control the RKAG edu project +*/ +class rkag_matrix { public: - matrix_class(); + rkag_matrix (); - void init(); - int read_io(); + void init (void); + int read_io (void); - void write(char byte1, char byte2, char byte3, char byte4, char byte5, char byte6, char byte7, char byte8); - void write_array(char matrix[]); - void clear(); - void sample(int numb); - void font_write(int numb); + void clear (void); + void sample (int pattern); + void write_char (char character); + void write_array (char matrix[]); + void write (char byte1, char byte2, char byte3, char byte4, + char byte5, char byte6, char byte7, char byte8); - void pcf_write(int data); - int pcf_read(); + void pcf_write (int data); + int pcf_read (void); - int taste_1; - int taste_2; - int taste_3; + int button_1; + int button_2; + int button_3; int potentiometer_0; @@ -47,12 +47,12 @@ class matrix_class unsigned long microseconds_now; unsigned long microseconds_saved; - int counter_taste_1; - int counter_taste_2; - int counter_taste_3; + int counter_button_1; + int counter_button_2; + int counter_button_3; }; -extern matrix_class matrix; +extern rkag_matrix matrix; -#endif +#endif /* MATRIX_RKAG_H */ From 94b77468a9d93d17b0900816380ef0eba960d3dd Mon Sep 17 00:00:00 2001 From: Sven Marc Gehring Date: Tue, 28 Jul 2015 09:07:02 +0200 Subject: [PATCH 2/6] Adjusted README and CHANGELOG to git format --- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ Changelog.txt | 25 ------------------------- README.md | 15 +++++++++++++++ readme.txt | 17 ----------------- 4 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 CHANGELOG.md delete mode 100644 Changelog.txt create mode 100644 README.md delete mode 100644 readme.txt diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e3a691a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,28 @@ +### V1.2.0 (28.07.2015, Sven Gehring) +- Code neu formatiert, fehlerhafte Indents behoben +- Kommentare übersetzt, ergänzt und Funktionsheader hinzugefügt +- Klassenname wurde von `matrix_class` zu `rkag_matrix` geändert +- `matrix.taste_1`...`matrix.taste_3` zu `matrix.button_1`...`matrix.button_3` geändert +- Statischen Tastengrenzwert mit `BTN_THRESHOLD` ersetzt +- Mehrere Methoden mit Schleifen vereinfacht +- `matrix.font_write` mit `matrix.write_char` ersetzt + - Parametertyp von `int` zu `char` geändert, da ein Zeichen geschrieben wird +- `matrix.pcf_write` Maskierung in definition `PCF_MASKBTN` ausgelagert + + + +### V1.1.0 (09.03.2015, Benjamin Marty) +- Es darf keine Instanz mehr im Sketch gebildet werden, wird nun direkt in der Library erledigt! + +- Funktion taste_1...taste_3 entfernt. +- Neue Funktion `matrix.read_io()` um die `matrix.taste_1`...`matrix.taste_3` variablen zu aktualisieren, gleichzeitig wird auch `matrix.potentiometer_0` aktualisiert. +- Neue Funktion `matrix.write_array` um Array direkt auf Matrix ausgeben zu können +- Examples angepasst Library V1.1 + + +### V1.0.1 (24.02.2015, Benjamin Marty) +- Include von Header File in Header File entfernt +- Neue Funktion taste_1, taste_2, taste_3 und potentiometer. Tastenfunktionen geben 0 bzw. 1 zurück, potentiometer einen Wert zwischen 0-1023 + +### V1.0.0 +- Erste Softwareversion \ No newline at end of file diff --git a/Changelog.txt b/Changelog.txt deleted file mode 100644 index af0b19f..0000000 --- a/Changelog.txt +++ /dev/null @@ -1,25 +0,0 @@ -/** -* @file Changelog.txt -* @author Benjamin Marty (bmarty@kochag.ch) -* @date 09.03.2014 -* @brief Changelog File -* @bug No known bugs. -* @version 1.1.0 -* -*/ - -V1.0.0 -- - -V1.0.1 - 24.02.2015 --Include von Header File in Header File entfernt --Neue Funktion taste_1, taste_2, taste_3 und potentiometer. Tastenfunktionen geben 0 bzw. 1 zurück, potentiometer einen Wert zwischen 0-1023 - - -V1.1.0 - 09.03.2015 -!-Es darf keine Instanz mehr im Sketch gebildet werden, wird nun direkt in der Library erledigt! - --Funktion taste_1...taste_3 entfernt. --Neue Funktion matrix.read_io() um die matrix.taste_1...matrix.taste_3 variablen zu aktualisieren, gleichzeitig wird auch matrix.potentiometer_0 aktualisiert. --Neue Funktion matrix.write_array um Array direkt auf Matrix ausgeben zu können --Examples angepasst Library V1.1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e43935 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# RKAG Matrix +This is a complete Library to use the Matrix Project. +Additional information: [koch-ag.github.io](http://koch-ag.github.io/matrix) + + +## Installation +To install this library, just use the Library Import Feature in Arduino + + +## Description +- `font.h` is used to get the Bit Positions of the ASCII Code +- `Matrix_RKAG.cpp` is the main Library File +- `Matrix_RKAG.h` is the header File of the main Library +- `TimerOne.cpp` is a Arduino Library for using the Atmega Timers +- `TimerOne.h` is the header File for the Timer Library diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 6da36f6..0000000 --- a/readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -This is a complete Library to use the Matrix Project. - - -Installation --------------------------------------------------------------------------------- - -To install this library, just use the Library Import Feature in Arduino - - -Description --------------------------------------------------------------------------------- - -font.h is used to get the Bit Positions of the ASCII Code -Matrix_RKAG.cpp is the main Library File -Matrix_RKAG.h is the header File of the main Library -TimerOne.cpp is a Arduino Library for using the Atmega Timers -TimerOne.h is the header File for the Timer Library \ No newline at end of file From 6d3dbdf5f5acb82627cee51091919f47488a7d41 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Aug 2015 09:27:16 +0200 Subject: [PATCH 3/6] Adjusted Example Scrolldemo_key for Library 1.2.0 --- examples/Scrolldemo_key/Scrolldemo_key.ino | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/Scrolldemo_key/Scrolldemo_key.ino b/examples/Scrolldemo_key/Scrolldemo_key.ino index 684dc44..e8b4663 100644 --- a/examples/Scrolldemo_key/Scrolldemo_key.ino +++ b/examples/Scrolldemo_key/Scrolldemo_key.ino @@ -1,9 +1,10 @@ /** * @file Scrolldemo.ino * @author Benjamin Marty (bmarty@kochag.ch) -* @date 2.2.2015 +* @date 11.8.2015 * @brief Main File for the Matrix -* @bug Why so much Ram Usage?! +* @bug Generates Low memory Alert. No Idea why. +* @note Works with Library 1.2.0 * */ @@ -16,7 +17,7 @@ #include "font.h" -//Allgemeine Variabeln für den Scroller +//General Variables for the Scroll Mechanism boolean space[8][180]; char buffer2[8]; char screen[8]; @@ -29,26 +30,26 @@ void writer(int numb, int stell) pos = (stell * 6) - 8; - //Font Daten aus Flash Speicher holen und in Matrix Array schreiben + //Get the Font Data from the Flash storage and write it to the Matrix Array for(int x = 0; x <= 7; x++) { buffer2[x] = pgm_read_byte(&font[numb][x]); } - //Buffer (Zeichenbuffer/Eigentliche Zeichen) in Space schreiben - for(int x = 0; x <= 7; x++) //Zeile wählen + //Write the Buffer to the Space + for(int x = 0; x <= 7; x++) //Choose Row { - for(int c = 1; c <= 8; c++) //Hilfszahl/Spalte wählen + for(int c = 1; c <= 8; c++) //Choose column { - if(buffer2[x] & (0x01 << (c - 1))) //Prüfen ob entsprechendes Bit gesetzt ist (Anhand kopierten Bits aus dem Flash PGM) + if(buffer2[x] & (0x01 << (c - 1))) //Check if Bit is set in Flash { - space[x][(c-1)+pos] = 1; //Bit im Space setzen + space[x][(c-1)+pos] = 1; //Set Bit in Space } else { - if(c > 3) //Hintersten 3 Spalten ignorieren da im normalfall leer und überlappend + if(c > 3) //Ignore last 3 Columns to generate no overlapping { - space[x][(c-1)+pos] = 0; //Bit löschen + space[x][(c-1)+pos] = 0; //Clear Bit } } } @@ -57,10 +58,10 @@ void writer(int numb, int stell) void cutscreen(int offset) { - //Space in einen 8x8 Auschnitt schneiden um diesen danach ausgeben zu können - for(int y = 0; y <= 7; y++) //Zeile wählen + //Cut the Space to a 8x8 Field + for(int y = 0; y <= 7; y++) //Choose Row { - for(int d = 0; d <= 7; d++) //Spalte wählen + for(int d = 0; d <= 7; d++) //Choose Column { if(space[y][d+offset] == 1) //Prüfen ob Bit im Space gesetzt ist und entsprechend auf Screen verfahren. Offset wird übergeben beim Aufruf -> Position { @@ -73,21 +74,21 @@ void cutscreen(int offset) } } - //Die 8 angegebenen geschnittenen Bytes ausgeben + //Write the 8 Bit's to the Matrix matrix.write(screen[0], screen[1], screen[2], screen[3], screen[4], screen[5], screen[6], screen[7]); } void setup() { - //Initalisierung der Matrix HW Komponenten + //Initalize HW matrix.init(); //attachInterrupt(0, swcheck, FALLING); Serial.begin(9600); - //Writer um Buchstaben in den Space zu schreiben + //Loop to write the Data to the Matrix for(int x = 0; x <= 25; x++) { writer(x+65,x+1); @@ -99,16 +100,16 @@ void loop() { matrix.read_io(); - //Offset von 0-63 + //Offset of 0-63 cutscreen(counter); - if(matrix.taste_1) + if(matrix.button_1) { counter++; } - if(matrix.taste_3) + if(matrix.button_3) { counter--; } From de7a5d4e5dc1fb10c90b26bf531f43872f5fbf45 Mon Sep 17 00:00:00 2001 From: Benjamin Marty Date: Tue, 11 Aug 2015 09:43:17 +0200 Subject: [PATCH 4/6] Adjusted example FONT_WRITER_POTI for 1.2.0 and removed a unused file --- examples/FONT_WRITER_POTI/FONT_WRITER_KEY.ino | 41 ------------------- .../FONT_WRITER_POTI/FONT_WRITER_POTI.ino | 6 +-- 2 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 examples/FONT_WRITER_POTI/FONT_WRITER_KEY.ino diff --git a/examples/FONT_WRITER_POTI/FONT_WRITER_KEY.ino b/examples/FONT_WRITER_POTI/FONT_WRITER_KEY.ino deleted file mode 100644 index 79c7d4e..0000000 --- a/examples/FONT_WRITER_POTI/FONT_WRITER_KEY.ino +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @file FONT_WRITER_KEY.ino -* @author Benjamin Marty (bmarty@kochag.ch) -* @date 20.12.2014 -* @brief Main File of FONT_WRITER_KEY Example -* @bug No known bugs. -* -*/ - -#include "Matrix_RKAG.h" - -#include "SPI.h" -#include "Wire.h" - -void setup() -{ - //Initalisierung der Matrix HW Komponenten - matrix.init(); - - //attachInterrupt(0, taster, FALLING); -} - - -void loop() -{ - switch(matrix.key()) - { - case 1: - matrix.font_write(49); - break; - - case 2: - matrix.font_write(50); - break; - - case 3: - matrix.font_write(51); - break; - } -} - diff --git a/examples/FONT_WRITER_POTI/FONT_WRITER_POTI.ino b/examples/FONT_WRITER_POTI/FONT_WRITER_POTI.ino index cfae6b6..9c6a4c8 100644 --- a/examples/FONT_WRITER_POTI/FONT_WRITER_POTI.ino +++ b/examples/FONT_WRITER_POTI/FONT_WRITER_POTI.ino @@ -1,7 +1,7 @@ /** * @file FONT_WRITER_POTI.ino * @author Benjamin Marty (bmarty@kochag.ch) -* @date 20.12.2014 +* @date 11.8.2015 * @brief Main File of FONT_WRITER_POTI Example * @bug No known bugs. * @@ -14,7 +14,7 @@ void setup() { - //Initalisierung der Matrix HW Komponenten + //Initialize HW matrix.init(); } @@ -24,7 +24,7 @@ void loop() { matrix.read_io(); - matrix.font_write(matrix.potentiometer_0/40+65); + matrix.write_char(matrix.potentiometer_0/40+65); delay(20); } From 10ec1d5a93e6825cc361e5aff6ebcc832a8c95d9 Mon Sep 17 00:00:00 2001 From: Benjamin Marty Date: Tue, 11 Aug 2015 09:44:32 +0200 Subject: [PATCH 5/6] Adjusted example FONT_WRITER_KEY for 1.2.0 --- examples/FONT_WRITER_KEY/FONT_WRITER_KEY.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/FONT_WRITER_KEY/FONT_WRITER_KEY.ino b/examples/FONT_WRITER_KEY/FONT_WRITER_KEY.ino index 9a5115a..0c8df66 100644 --- a/examples/FONT_WRITER_KEY/FONT_WRITER_KEY.ino +++ b/examples/FONT_WRITER_KEY/FONT_WRITER_KEY.ino @@ -1,7 +1,7 @@ /** * @file FONT_WRITER_KEY.ino * @author Benjamin Marty (bmarty@kochag.ch) -* @date 20.12.2014 +* @date 11.8.2015 * @brief Main File of FONT_WRITER_KEY Example * @bug No known bugs. * @@ -28,21 +28,21 @@ void loop() if(matrix.taste_1) { //Ascii Zeichen ausgeben - matrix.font_write(49); + matrix.write_char(49); } //Prüfen ob Taste 2 gedrückt if(matrix.taste_2) { //Ascii Zeichen ausgeben - matrix.font_write(50); + matrix.write_char(50); } //Prüfen ob Taste 3 gedrückt if(matrix.taste_3) { //Ascii Zeichen ausgeben - matrix.font_write(51); + matrix.write_char(51); } } From ecf2cf59ba5c5b9e9eb89bdb6c36808ce3dab8ec Mon Sep 17 00:00:00 2001 From: Benjamin Marty Date: Tue, 11 Aug 2015 09:47:28 +0200 Subject: [PATCH 6/6] Adjusted example FONT_WRITER for 1.2.0 --- examples/FONT_WRITER/FONT_WRITER.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/FONT_WRITER/FONT_WRITER.ino b/examples/FONT_WRITER/FONT_WRITER.ino index 2343b0b..cbc7155 100644 --- a/examples/FONT_WRITER/FONT_WRITER.ino +++ b/examples/FONT_WRITER/FONT_WRITER.ino @@ -1,7 +1,7 @@ /** * @file FONT_WRITER.ino * @author Benjamin Marty (bmarty@kochag.ch) -* @date 20.12.2014 +* @date 11.8.2015 * @brief Main File of FONT_WRITER Example * @bug No known bugs. * @@ -29,20 +29,20 @@ void loop() for(int x = 65; x <= 90; x++) { - matrix.font_write(x); + matrix.write_char(x); delay(500); } - matrix.font_write(142); + matrix.write_char(142); delay(500); - matrix.font_write(153); + matrix.write_char(153); delay(500); - matrix.font_write(154); + matrix.write_char(154); delay(500);