Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Library of common functions to all the tasks.
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <stdint.h>
- /*Color definitions*/
- #define R 0xF800 //RED
- #define G 0x07E0 //GREEN
- #define B 0x001F //BLUE
- #define W 0xFFFF //WHITE
- #define Y 0xFFE0 //YELLOW
- #define M 0xF81F //MAGENTA
- #define C 0x07FF //CYAN
- /**
- * @brief Capitalises a string.
- * @param char *temp: string to capitalise
- * @return void
- */
- void ToUp(char *temp)
- {
- char *name;
- name = strtok(temp, ":");
- // Convert to upper case
- char *s = name;
- while (*s)
- {
- *s = toupper((unsigned char)*s);
- s++;
- }
- }
- /**
- * @brief Prompt to change the colour of the LED
- * @return HEX of the colour to use
- */
- uint16_t changeColour()
- {
- char colour[2];
- printf("Enter a colour: (R, G, B, W, Y, M, C) ");
- scanf("%s", colour); // Update colour to user choice
- ToUp(colour);
- if (colour[0] == 'R')
- {
- printf("Colour changed to Red\n");
- return R;
- }
- else if (colour[0] == 'G')
- {
- printf("Colour changed to Green\n");
- return G;
- }
- else if (colour[0] == 'B')
- {
- printf("Colour changed to Blue\n");
- return B;
- }
- else if (colour[0] == 'W')
- {
- printf("Colour changed to White\n");
- return W;
- }
- else if (colour[0] == 'Y')
- {
- printf("Colour changed to Yellow\n");
- return Y;
- }
- else if (colour[0] == 'M')
- {
- printf("Colour changed Magenta\n");
- return M;
- }
- else if (colour[0] == 'C')
- {
- printf("Colour changed to Cyan\n");
- return C;
- }
- else
- {
- printf("Input invalid. Reverted to default, Cyan\n");
- return C;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement