Golang and Arduino

Small arduino and golang programs

arduino parse hex colors to numbers


void setup() {
    Serial.begin(9600);

    // get data from Serial.readStringUntil('\n'); to memory
    String data="FFFFFFFF 00FFFFFF 0000FFFF 000000FF";
    // store length of data
    int iend = data.length() - 1; 
    // current begin index
    int index=0;
    // next index
    int next_index;
    do{
        next_index=data.indexOf(' ',index);

        String hexcode=data.substring(index, next_index);

        index=next_index+1;

        unsigned long bigNumber = (unsigned long)strtoul(hexcode.c_str(), 0, 16);

        // add number to array

        Serial.println(bigNumber);

     }while((next_index!=-1)&&(next_index<iend));
}

void loop() {

}