Another question on terminating charactoers
I have been given a programme for a motorcycle blue tooth controller so that I can control my tablet without touching the screen by the use of a blue tooth button set.
I have created the unit and am trying to programme it.
I seem to be successful until and error is thrown up stating:
exit status 1
Compilation error: missing terminating > character
Checking through answers on the forum I seem to have all of the prerequisites not to get this error.
Could someone tell me where I am wrong?
My code (its 527 lines) ....
`// RALLY RAMPAGE BLUETOOTH BIKE HANDLEBAR NAVIGATION CONTROLLER
// www.rallyrampage.com
// Version: 2.5.1 (Stable BLE and LED Status Update)
// Updated: 2024-10-14
// Ownership: Rally Rampage
// Published by: Rally Rampage
// Target Hardware: ESP32 Wroom Development Board
// UNIQUE FEATURES
// Five apps commands including Terra Pirata Roadbook Reader
// Remembers the last app when lost power
// reconnects on power up again
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#include <Preferences.h>
#include <WiFi.h> // For getting the MAC address
#if SOFTWARE_SERIAL_AVAILABLE
#include <SoftwareSerial.h>
#endif
// Declare function prototype for generating a serial number
String generateSerialNumber();
// Create a BLE Keyboard instance
BleKeyboard bleKeyboard;
// Create a Preference instance for saving settings
Preferences preferences;
// Define variables
const String RR_Version = "V2.5.1";
const int button1state = LOW;
const int button2state = LOW;
const int button3state = LOW;
const int button4state = LOW;
const int button5state = LOW;
// Define the pins for the LEDs
const int ledBLUE = 23; // Blue LED pin
const int ledRED = 22; // Red LED pin
// Define the pins for the pushbuttons
const int button1 = 19; // Button 1 pin
const int button2 = 18; // Button 2 pin
const int button3 = 17; // Button 3 pin
const int button4 = 16; // Button 4 pin
const int button5 = 4; // Button 5 pin
// Define the pin for the mode switch button.
const int modeSelect = 21;
// Default value for the selected app. Change this if you want a different default app.
// 0: No softapp yet
// 1: Locus Maps
// 2: Rally Navigator
// 3: OsMand
// 4: Piste Roadbook Reader
// 5: Terra Pirata
int softApp = 0; //Locus set as default when starting unit
int softAppSaveValue; // temp softApp value for EEPROM
// Define the delay time in ms between button presses and between toggle switches.
const int buttonWait = 250; // Button delay time
const int toggleWait = 20; // Toggle switch delay time
const int ledFlashDelay = 150;
const int ColorBlack = 0;
const int ColorBlue = 1;
const int ColorRed = 2;
// Function to blink the blue LED
void blinkBlueLed() {
digitalWrite(ledBLUE, LOW);
delay(150);
digitalWrite(ledBLUE, HIGH);
}
// Function to generate a serial number based on the last 3 bytes of the MAC address
// Function to generate a 6-digit serial number based on the last 3 bytes of the MAC address
String generateSerialNumber() {
uint8_t baseMac[6];
esp_read_mac(baseMac, ESP_MAC_WIFI_STA); // Read the MAC address
// Extract the last 3 bytes of the MAC address and convert them to a 6-character string
char serialNumber[7]; // 6 hex digits + null terminator
sprintf(serialNumber, "%02X%02X%02X", baseMac[3], baseMac[4], baseMac[5]);
return String(serialNumber); // Return the 6-character serial number
}
// Function to get the unique chip ID as a serial number
/*String getChipID() {
// The chip ID is based on the last 24 bits of the MAC address
uint32_t chipId = 0;
for(int i=0; i<17; i+=8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xFF) << i;
}
return String(chipId);
}*/
// Forward declarations
void flashLedIndicator(int FlashCount, int FlashDelay, int FlashColor);
void storeSoftApp(int softAppVal);
////////////////////////////////////////////////////////////////////////////////////////////////
// This function is called once when your program starts. It's used to initialize variables,
// input and output pin modes, and other libraries needed by your sketch.
////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
Serial.println("Starting Rampage Controller ...");
// Load previous softApp selection from preferences
preferences.begin("my-app", false); // Open preferences
softAppSaveValue = preferences.getUInt("counter", 0); // Retrieve saved value
preferences.end(); // Close preferences
// Set the softApp to the saved value
if (softAppSaveValue > 5) {
softApp = 0; // Reset to 0 if the value exceeds the number of apps
} else {
softApp = softAppSaveValue; // Otherwise, set to the saved value
}
// PRINT STARTUP STATUS
Serial.print("Rampage Controller Version: ");
Serial.println(RR_Version);
Serial.print("You are in softApp: ");
Serial.println(softApp);
// Generate BLE name with version and chip ID
String bleName = "Rampage_" + generateSerialNumber();
Serial.print("BLE Name: ");
Serial.println(bleName); // Print to check the full name
// Initialize BLE with the generated name
bleKeyboard = BleKeyboard(bleName.c_str());
bleKeyboard.begin();
Serial.println("BLE Keyboard started and advertising...");
Serial.print("BLE Advertising with name: ");
Serial.println(bleName);
// Set up button pins as input with built-in pullup resistors
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
// Set up LED pins as output
pinMode(ledBLUE, OUTPUT);
pinMode(ledRED, OUTPUT);
// Set up mode select switch pin as input with built-in pullup resistor.
pinMode(modeSelect, INPUT_PULLUP);
// Indicate ready state by setting the blue LED on
digitalWrite(ledBLUE, HIGH);
digitalWrite(ledRED, LOW);
}
////////////////////////////////////////////////////////////////////////////////////////////////
// THIS IS THE LOOP SECTION OF THE CODE THAT KEEPS LOOPING AND RUNNING
////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
//////////////////////////////////////////////////////////////
// START SOFT APP SELECT LOOP
//////////////////////////////////////////////////////////////
// The digitalRead(modeSelect) function checks if the mode select button has been pressed (LOW means button press)
if (digitalRead(modeSelect) == LOW) {
// Turn on the red LED (HIGH) and turn off the blue LED (LOW)
flashLedIndicator(0,0,ColorRed); //Set Red Led
// Check if button 1 has been pressed
if (digitalRead(button1) == button1state) {
// If button 1 has been pressed, set the softApp variable to 1
softApp = 1;
storeSoftApp(softApp);
// Output a message to the serial console
Serial.println("While in Mode Select you have selected softApp 1: Locus Maps.");
// Send a message via Bluetooth to the connected device
if (bleKeyboard.isConnected()) {
bleKeyboard.println("App 1: Locus"); }
// Call function to flash LED according to softApp # selected
flashLedIndicator(1,ledFlashDelay,ColorBlue);
}
// End of select softapp 1
// Check if button 2 has been pressed
// The sequence of operations is the same as for button 1, but softApp is set to 2
if (digitalRead(button2) == button2state) {
softApp = 2;
storeSoftApp(softApp);
Serial.println("While in Mode Select you have selected softApp 2: Rally Navigator.");
// Send a message via Bluetooth to the connected device
if (bleKeyboard.isConnected()) {
bleKeyboard.println("App 2: Rally"); }
// Call function to flash LED according to softApp # selected
flashLedIndicator(2,ledFlashDelay,ColorBlue);
}
// End of select softapp 2
// Check if button 3 has been pressed
// The sequence of operations is the same as for button 1 and 2, but softApp is set to 3
if (digitalRead(button3) == button3state) {
softApp = 3;
storeSoftApp(softApp);
Serial.println("While in Mode Select you have selected softApp 3: OsMand.");
// Send a message via Bluetooth to the connected device
if (bleKeyboard.isConnected()) {
bleKeyboard.println("App 3: OsMand"); }
// Call function to flash LED according to softApp # selected
flashLedIndicator(3,ledFlashDelay,ColorBlue);
}
// End of select softapp 3
// Check if button 4 has been pressed
// The sequence of operations is the same as for button 1, 2, and 3, but softApp is set to 4
if (digitalRead(button4) == button4state) {
softApp = 4;
storeSoftApp(softApp);
Serial.println("While in Mode Select you have selected softApp 4: Piste Roadbook Reader.");
// Send a message via Bluetooth to the connected device
if (bleKeyboard.isConnected()) {
bleKeyboard.println("App 4: Piste"); }
// Call function to flash LED according to softApp # selected
flashLedIndicator(4,ledFlashDelay,ColorBlue);
}
// End of select softapp 4
// Check if button 5 has been pressed
if (digitalRead(button5) == button5state) {
softApp = 5;
storeSoftApp(softApp);
Serial.println("While in Mode Select you have selected softApp 5: Terra Pirata.");
// Send a message via Bluetooth to the connected device
if (bleKeyboard.isConnected()) {
bleKeyboard.println("App 5: Terra Pirata"); }
// Call function to flash LED according to softApp # selected
flashLedIndicator(5,ledFlashDelay,ColorBlue);
}
// End of select softapp 5
}
///////////////////////////////////////////////////////////////////////////////////////
// END SOFT APP SELECT LOOP
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
// START SOFT APP RUN LOOP
///////////////////////////////////////////////////////////////////////////////////////
if (digitalRead(modeSelect) == HIGH) {
flashLedIndicator(0,0,ColorBlue); // Set Blue Led
delay(ledFlashDelay);
if (!bleKeyboard.isConnected()) {
flashLedIndicator(1,ledFlashDelay,ColorRed); }
if (softApp == 0) { // App 0 No softApp value yet
Serial.println("You are in softApp: ZERO");
flashLedIndicator(1,ledFlashDelay,ColorRed);
} // End softapp 0
if (softApp == 1) {
// App 1 Locus Maps : Button 1 : Zoom In : Vol +
// App 1 Locus Maps : Button 2 : Zoom Out : Vol -
// App 1 Locus Maps : Button 3 : Map Up : 'r'
// App 1 Locus Maps : Button 4 : Centre Map : 'c'
// App 1 Locus Maps : Button 5 : Display on/off : 'd'
flashLedIndicator(0,0,ColorBlue);
// PUSH BUTTONS
if (digitalRead(button1) == button1state) {
Serial.println("Button 1 - Locus - Volume Up");
// Sending the command for zooming in : Volume Up
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_VOLUME_UP); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button2) == button2state) {
Serial.println("Button 2 - Locus - Volume Down");
// Sending the command for zooming out : Volume Down
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_VOLUME_DOWN); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button3) == button3state) {
Serial.println("Button 3 - Locus - 'r' key");
// Sending the command for map up : the 'r' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('r'); } // Key r
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button4) == button4state) {
Serial.println("Button 4 - Locus - 'c' key");
// Sending the command for Map Centre : 'c' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('c'); } // key c
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button5) == button5state) {
Serial.println("Button 5 - Locus - 'd' key");
// Sending the command for Display : 'd' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('d'); } // key d
flashLedIndicator(1,10,ColorBlack);
}
} // End softapp 1
if (softApp == 2) {
// App 2 Rally Navigator : Button 1 : Trip UP : Vol +
// App 2 Rally Navigator : Button 2 : Trip Down : Vol -
// App 2 Rally Navigator : Button 4 : Scroll UP : Media Next
// App 2 Rally Navigator : Button 5 : Scroll Down : Media Previous
flashLedIndicator(0,0,ColorBlue);
// PUSH BUTTONS
if (digitalRead(button1) == button1state) {
Serial.println("Button 1 - Rally - Volume Up");
// Sending the command for Trip UP : Volume Up
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_VOLUME_UP); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button2) == button2state) {
Serial.println("Button 2 - Rally - Volume Down");
// Sending the command for Trip Down : Volume Down
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_VOLUME_DOWN); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button4) == button4state) {
Serial.println("Button 4 - Rally - Next Media");
// Sending the command for Scroll UP : Next Media
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_NEXT_TRACK); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button5) == button5state) {
Serial.println("Button 5 - Rally - Prev Media");
// Sending the command for Scroll Down : Prev Media
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_PREVIOUS_TRACK); }
flashLedIndicator(1,10,ColorBlack);
}
} // End softapp 2
if (softApp == 3) {
// App 3 OsMand : Button 1 : Pan UP : Dpad_Up
// App 3 OsMand : Button 2 : Pan Down : Dpad_Down
// App 3 OsMand : Button 3 : Centre : 'c'
// App 3 OsMand : Button 4 : Pan Left : Dpad_Left
// App 3 OsMand : Button 5 : Pan Right : Dpad_Right
flashLedIndicator(0,0,ColorBlue);
// PUSH BUTTONS
if (digitalRead(button1) == button1state) {
Serial.println("Button 1 - OsMand - Dpad_Up");
// Sending the command for Pan UP : Dpad_Up
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_UP_ARROW); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button2) == button2state) {
Serial.println("Button 2 - OsMand - Dpad_Down");
// Sending the command for Pan Down : Dpad_Down
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_DOWN_ARROW); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button3) == button3state) {
Serial.println("Button 3 - OsMand - Keycode_C");
// Sending the command for Centre : Keycode_C
if (bleKeyboard.isConnected()) {
bleKeyboard.write('c'); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button4) == button4state) {
Serial.println("Button 4 - OsMand - Dpad_Left");
// Sending the command for Pan Left : Dpad_Left
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_LEFT_ARROW); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button5) == button5state) {
Serial.println("Button 5 - OsMand - Dpad_Right");
// Sending the command for Pan Right : Dpad_Right
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_RIGHT_ARROW); }
flashLedIndicator(1,10,ColorBlack);
}
} // End softapp 3
if (softApp == 4) {
// App 4 Piste : Button 1 : Rb Scroll Fwd : w
// App 4 Piste : Button 2 : Rb Scroll Rev : x
// App 4 Piste : Button 3 : Trip + : a
// App 4 Piste : Button 4 : Trip - : d
// App 4 Piste : Button 5 : Medial Play/Pause : q
flashLedIndicator(0,0,ColorBlue);
// PUSH BUTTONS
if (digitalRead(button1) == button1state) {
Serial.println("Button 1 - Piste - 'w' key");
// Sending the command for Rb Scroll Fwd : 'w' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('w'); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button2) == button2state) {
Serial.println("Button 2 - Piste - 'x' key");
// Sending the command for Rb Scroll Rev : 'x' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('x'); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button3) == button3state) {
Serial.println("Button 3 - Piste - 'a' key");
// Sending the command for Trip + : 'a' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('a'); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button4) == button4state) {
Serial.println("Button 4 - Piste - 'd' key");
// Sending the command for Trip - : 'd' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('d'); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button5) == button5state) {
Serial.println("Button 5 - Piste - 'q' key");
// Sending the command for Medial Play/Pause : 'q' key
if (bleKeyboard.isConnected()) {
bleKeyboard.write('q'); }
flashLedIndicator(1,10,ColorBlack);
}
} // End softapp 4
if (softApp == 5) {
// App 5 Rally Navigator : Button 1 : Fwd scroll : Media Next
// App 5 Rally Navigator : Button 2 : Rev scroll : Media Previous
// App 5 Rally Navigator : Button 3 : Trip + : Vol -
// App 5 Rally Navigator : Button 4 : Trip - : Vol +
// App 5 Rally Navigator : Button 5 : Lock screen : x
flashLedIndicator(0,0,ColorBlue);
// PUSH BUTTONS
if (digitalRead(button1) == button1state) {
Serial.println("Button 1 - media next scroll forward");
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_NEXT_TRACK); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button2) == button2state) {
Serial.println("Button 2 - media previous scroll down");
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_PREVIOUS_TRACK); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button3) == button3state) {
Serial.println("Button 3 - Volume - trip +");
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_VOLUME_DOWN); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button4) == button4state) {
Serial.println("Button 4 - Volume + Trip -");
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_VOLUME_UP); }
flashLedIndicator(1,10,ColorBlack);
}
if (digitalRead(button5) == button5state) {
Serial.println("Button 5 - Lock screen");
if (bleKeyboard.isConnected()) {
bleKeyboard.write(KEY_MEDIA_LOCK_SCREEN); }
flashLedIndicator(1,10,ColorBlack);
}
} // End softapp 5
} // End of HIGH state button loop
} // End of loop code
void flashLedIndicator(int FlashCount, int FlashDelay, int FlashColor) {
if (FlashCount == 0) {
if (FlashColor == ColorBlue) {
digitalWrite(ledBLUE, HIGH); // Turn on the blue LED
digitalWrite(ledRED, LOW); } // Turn off the red LED
if (FlashColor == ColorRed) {
digitalWrite(ledBLUE, LOW); // Turn off the blue LED
digitalWrite(ledRED, HIGH); } // Turn on the red LED
if (FlashColor == ColorBlack) {
digitalWrite(ledBLUE, LOW); // Turn off the blue LED
digitalWrite(ledRED, LOW); } // Turn off the red LED
}
else {
int ledBlueState = digitalRead(ledBLUE);
int ledRedState = digitalRead(ledRED);
digitalWrite(ledBLUE, LOW);
digitalWrite(ledRED, LOW);
delay (FlashDelay);
for (int i = 1; i <= FlashCount; i++) {
if (FlashColor == ColorBlue) digitalWrite(ledBLUE, HIGH);
if (FlashColor == ColorRed) digitalWrite(ledRED, HIGH);
delay(FlashDelay);
digitalWrite(ledBLUE, LOW);
digitalWrite(ledRED, LOW);
delay(FlashDelay);
}
digitalWrite(ledBLUE, ledBlueState);
digitalWrite(ledRED, ledRedState);
}
}
void storeSoftApp(int softAppVal) {
preferences.begin("my-app", false);
preferences.putUInt("counter", softAppVal); // Use softAppVal instead of counter
preferences.end();
}
`