These user-defined functions were created to fulfill the project requirements while emphasising code reusability:
- main(): The main() function orchestrates the entire process, ensuring the program flow is maintained and each method is called in sequence to achieve the desired outcome. Starting only when the user is ready, prompting the user for their hexadecimal number, generating the numerical data and then controlling the Finch robot.
- promptReady(): This method prompts the user to enter 'start' to begin the program or 'exit' to quit. It serves as an initial and restart checkpoint to determine whether the user wants to proceed or terminate the program.
- promptInput(): This method asks the user to enter a hexadecimal number. It captures user input, ensuring the program receives the necessary data to process and convert.
- checkSize(): This method checks if the entered hexadecimal number is of size 2. Ensures the input meets the required length, which is crucial for accurate processing and conversion.
- checkBoundary(): This method checks if the hexadecimal digits are within the valid range (0-9, A-F). Validates the input, ensuring it falls within the allowable hexadecimal range to prevent errors during conversion.
- generateBinary(): This method converts the hexadecimal input into its binary representation. Converts hexadecimal to binary, which is a crucial step in the sequence of conversions to reach the final results.
- hexValue(): This method converts a single hexadecimal character into its decimal value.
- powerOf(): This method computes 2 raised to the power of the given integer. Used in binary to decimal conversion, making it essential for accurate calculation of decimal values.
- intToBinary(): This method converts a decimal value to its binary string representation. Integral part of the conversion process, ensuring each user digit is accurately represented in binary form.
binaryToDenary(): This method provides the decimal value of the binary string, which is used in further calculations. This denary value is used when calculating the intensity of LED colours of the Finch Robot.
denaryToOctal(): This method transforms the decimal value into octal, continuing the sequence of required conversions. This octal value is used to determine the speed of the Finch Robot.
- calculateSpeed(): This method calculates the speed for the Finch robot based on the octal value. Determines an appropriate speed value within specified limits for the robot's movement.
- generateRed(): This method generates the red component of the LED colour based on the decimal value. Sets the red colour intensity for the Finch robot's LED, contributing to visual feedback.
- generateGreen(): This method generates the green component of the LED colour based on the decimal value. Sets the green colour intensity for the Finch robot's LED, contributing to visual feedback.
- generateBlue(): This method generates the blue component of the LED colour by averaging the red and green values. Completes the RGB colour settings for the Finch robot's LED, contributing to visual feedback.
- moveFinch(): Executes the main actions of the Finch robot, setting the LED colour and moving forward or backward based on the binary input. This method brings all the computations to life by interacting with the physical robot.