//---Counters--- int r, c, h, i, j, k, t; ulong speed; //---Preferences (FLASH Memory)--- #include //https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/ Preferences storedVars; //https://docs.espressif.com/projects/arduino-esp32/en/latest/api/preferences.html //---BLE Keyboard & TTS Feedback--- #define USE_NIMBLE #include //.h file modified as per https://github.com/T-vK/ESP32-BLE-Keyboard/pull/111#issuecomment-954894261 BleKeyboard bleKeyb("RPMLetterboard","PMC2022",99); bool keybON = false; bool bleMode = true; char charCache[51] = {}; // c-string to hold a 50-char string byte charCount = 0; char * pch; //---Cap Sensors--- ulong lastTouch = 0; uint16_t tReg5A = 0; uint16_t tReg5C = 0; uint16_t tReg5D = 0; uint32_t NOTcurrCols, NOToldCols, currCols, oldCols = 0; uint16_t NOTcurrRows, NOToldRows, currRows, oldRows = 0; uint32_t touchedCols, releasedCols, touchedRows, releasedRows; #include "Wire.h" // C:\Users\pedro\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\libraries\Wire\src #include "MPR121.h" MPR121 S0, S1, S2; bool seqOK = true; //---Buzzer--- const byte buzzPin = 12; const byte buzzChan = 0; //channel 15 misfires: don't use //---NeoPixel--- uint32_t yellow, orange, blue, red, green, violet; #include Adafruit_NeoPixel pix(1,0); //---LEDs--- // https://docs.arduino.cc/tutorials/communication/guide-to-shift-out // https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftout/ const byte clockPin = 5; const byte latchPin = 19; const byte dataPin = 21; // shift1 output =xxcdefgh // row number = 123456 (1 = current source activated) const byte rowShiftOne[6] = {B100000,B010000,B001000,B000100,B000010,B000001}; // shift1 output = abxxxxxx // col number = 9A (0 = current drain activated) const byte colShiftOne[10] = {B11,B11,B11,B11,B11,B11,B11,B11,B01,B10}; const byte colShiftOneFat[10] = {B11,B11,B11,B11,B11,B11,B11,B11,B00,B00}; // shift2 output = abcdefgh // col number =67854321 (0 = current drain activated) const byte colShiftTwo[10] = {B11111110,B11111101,B11111011,B11110111,B11101111,B01111111,B10111111,B11011111,B11111111,B11111111}; const byte colShiftTwoFat[10] = {B11111100,B11111100,B11110011,B11110011,B01101111,B01101111,B10011111,B10011111,B11111111,B11111111}; ulong elapsedLED = 0; bool LEDisON = false; int onTimer = 200; //adapt to speed of user but beware also used in progMode as witness byte sym4LED; byte spaceShiftOne, spaceShiftTwo ,enterShiftOne, enterShiftTwo, backsShiftOne, backsShiftTwo; //---Funtcion Switches & Interrupts--- // FORUM solution: https://forum.arduino.cc/t/attachinterrupt-using-array-of-function-pointer/1019684/4 // https://docs.espressif.com/projects/arduino-esp32/en/latest/api/gpio.html?highlight=interrupt#about typedef struct { const uint8_t PIN; bool value; } fSwitch; fSwitch FS[5] = {{27,0},{33,0},{15,0},{32,0},{14,0}}; //function switches in these pins volatile bool sFlag = false; volatile bool buzzFlag = false; volatile bool waitingOnBLE = false; volatile bool oldRead, newRead; volatile uint8_t debCount = 0; bool buzzKeyb = false; bool ledKeyb = false; bool letterKeyb = false; // send letter. Will read letter (immediately) & word (when sending SPACE) bool wordKeyb = false; // send word (no letter). Will read immediately because will also send SPACE bool phraseKeyb = false; // send phrase. Will read immediately //---Battery--- ulong elapsedBatt = 0; int battTimer = 0; float battRead; // String vs string https://forum.arduino.cc/t/difference-between-char-array-and-string/603608/8 // basic https://www.arduinoplatform.com/arduino-programming/understanding-character-strings-in-arduino/ // c++ Lib https://cplusplus.com/reference/cstring/ // https://forum.arduino.cc/t/solved-printing-a-portion-of-a-char-string/159984 //int tempInt = pch - charCache + 1; //dprintln(charCache + tempInt); //strncpy(charTemp,&charCache[pch - charCache + 1],charCount); //dprintln(charTemp); //dprintln(&charCache[pch - charCache + 1]); //---Board Prog Mode, Symbol Tables byte symbolTable = 1; bool progMode = true; byte cSym, vSym; byte rSym = 2; byte offR = 1; byte offC = 0; byte hSym = 6; byte sym2Pix[14][22]; //has to be full 14x22 to allow for possible offsets in Row / Col byte LEDrSym[60]; byte LEDcSym[60]; //60 LEDs char symbol[61] = {}; //*************************************one more for null termination? int lastSymNum = 99; int currSymNum; char currSym, lastSym; //all symbols have same measures, Other layouts w/o LEDS can use all 14 rows these three use 12 rows (1 LED every 2 rows) // All Layouts w/LED: rSym=2, offR=1, offC=0 --> hSym = 6 // cSym = (large 4), (medium 3), (qwerty 2) --> vSym = (5),(7),(10) (plus 1 w/o LED)) //const byte vSym = trunc((22 - offC) / cSym) - (cSym==2); // number of vertical (cols) symbols = vSym //const byte hSym = trunc((14 - offR) / rSym); // number of horizontal (rows) symbols = hSym*/