Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include <stdio.h>#include <string.h>int main(void) { char str[] = "FF6544"; char hex1[3], hex2[3], hex3[3]; strncpy(hex1, str,2); strncpy(hex2, &str[2],2); strncpy(hex3, &str[4],2); hex1[2] = '\0'; hex2[2] = '\0'; hex3[2] = '\0'; printf("hex1:%s\n",hex1); printf("hex2:%s\n",hex2); printf("hex3:%s\n",hex3); return 0;}
you can do something like this...Code: [Select]#include <stdio.h>#include <string.h>int main(void) { char str[] = "FF6544"; char hex1[3], hex2[3], hex3[3]; strncpy(hex1, str,2); strncpy(hex2, &str[2],2); strncpy(hex3, &str[4],2); hex1[2] = '\0'; hex2[2] = '\0'; hex3[2] = '\0'; printf("hex1:%s\n",hex1); printf("hex2:%s\n",hex2); printf("hex3:%s\n",hex3); return 0;}
hex1:shex2:shex3:s
void SetRGB(red,green,blue);{// do stuff with the contents of red, green, blue}
too little code to look at for reference. Anyways I decided to just do this SetRGB(FF,65,75);
I want to write a bit of code that converts a string of hex-RGB-representation - that thing in website you set to FF6575, or whatever. These : http://www.w3schools.com/CSS/css_colors.asp.I need some way to parse or filter out certain parts of the string. For example I need to separate it into three groups : FF 65 75.
void parsetext(char*) {}int main(void) { parsetext("#A1B2C3"); // Parse result is stored in Red, Blue and Green global variables SetRedComponentOfLed(Red); SetBlueComponentOfLed(Blue); SetGreeenComponentOfLed(Green);}
int parsenextchar(char) {}void GotAnCharFromUART(char thechar) { int parseres = parsenextchar(thechar); // Parses the next char received from UART. If it completed reading an RGB color it will // return an code (letting us know we got a color) and sotres the R, G and B components in global variables if (parseres == 1) { // Got the full RGB code parsed! SetRedComponentOfLed(Red); SetBlueComponentOfLed(Blue); SetGreeenComponentOfLed(Green); }}int main(void) {}