c – Convert int to byte for GPIO

بدون دیدگاه


I’m trying to convert a int to a 4 bit array, so that I can output them using the GPIOs of a raspberry pi. I’m programming in C. My current function is:

char *binaryToAbits(unsigned int input, char *result)
{
    if(input>1)
        result=binaryToAbits(input>>1,result);
    *result='0'+(input & 0x01);
    return result+1;
}

writeStationIdentifier()
{
    G_StationID = *(UA_Boolean*)data->data;
    char G_StationID_BIN[] = {0,0,0,0};
    *binaryToAbits(G_StationID,G_StationID_BIN)='';

    if(G_StationID==0 || G_StationID>15)
    {
        G_StationID_BIN[0] = 0;
        G_StationID_BIN[1] = 0;
        G_StationID_BIN[2] = 0;
        G_StationID_BIN[3] = 0;
    }

    digitalWrite(ID_PIN_OUTPUT_BIT_1,G_StationID_BIN[0]);
    digitalWrite(ID_PIN_OUTPUT_BIT_2,G_StationID_BIN[1]);
    digitalWrite(ID_PIN_OUTPUT_BIT_3,G_StationID_BIN[2]);
    digitalWrite(ID_PIN_OUTPUT_BIT_4,G_StationID_BIN[3]);
}

The problem is that the signal for the array isn’t calculated correctly.



لینک منبع

برچسب‌ها: ,,,
  • نویسنده
    A-brand
  • تعداد بازدید
    17 views
0دیدگاه فرستاده شده است.
شما هم دیدگاه خود را بنویسید