SHARE
TWEET

V4TasksLib

MarShar Mar 26th, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Library of common functions to all the tasks.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10.  
  11. /*Color definitions*/
  12. #define R 0xF800 //RED
  13. #define G 0x07E0 //GREEN
  14. #define B 0x001F //BLUE
  15. #define W 0xFFFF //WHITE
  16. #define Y 0xFFE0 //YELLOW
  17. #define M 0xF81F //MAGENTA
  18. #define C 0x07FF //CYAN
  19.  
  20. /**
  21.  * @brief Capitalises a string.
  22.  * @param char *temp: string to capitalise
  23.  * @return void
  24. */
  25. void ToUp(char *temp)
  26. {
  27.     char *name;
  28.     name = strtok(temp, ":");
  29.  
  30.     // Convert to upper case
  31.     char *s = name;
  32.     while (*s)
  33.     {
  34.         *s = toupper((unsigned char)*s);
  35.         s++;
  36.     }
  37. }
  38.  
  39. /**
  40.  * @brief Prompt to change the colour of the LED
  41.  * @return HEX of the colour to use
  42. */
  43. uint16_t changeColour()
  44. {
  45.     char colour[2];
  46.     printf("Enter a colour: (R, G, B, W, Y, M, C) ");
  47.     scanf("%s", colour); // Update colour to user choice
  48.     ToUp(colour);
  49.     if (colour[0] == 'R')
  50.     {
  51.         printf("Colour changed to Red\n");
  52.         return R;
  53.     }
  54.     else if (colour[0] == 'G')
  55.     {
  56.         printf("Colour changed to Green\n");
  57.         return G;
  58.     }
  59.     else if (colour[0] == 'B')
  60.     {
  61.         printf("Colour changed to Blue\n");
  62.         return B;
  63.     }
  64.     else if (colour[0] == 'W')
  65.     {
  66.         printf("Colour changed to White\n");
  67.         return W;
  68.     }
  69.     else if (colour[0] == 'Y')
  70.     {
  71.         printf("Colour changed to Yellow\n");
  72.         return Y;
  73.     }
  74.     else if (colour[0] == 'M')
  75.     {
  76.         printf("Colour changed Magenta\n");
  77.         return M;
  78.     }
  79.     else if (colour[0] == 'C')
  80.     {
  81.         printf("Colour changed to Cyan\n");
  82.         return C;
  83.     }
  84.     else
  85.     {
  86.         printf("Input invalid. Reverted to default, Cyan\n");
  87.         return C;
  88.     }
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top