Quick actions

cmd+k|ctrl+k

Navigation

Languages

C_and_CPP / lhz135 / 20191222

Snippet info

Language

C

Visibility

public

Author

kavenc

Created

2019-12-23T08:40:22Z

Updated

2019-12-23T08:41:36Z

#include <stdio.h>

#define MASK(LEN) ((1<<(LEN)) - 1)
#define LROTATE_4(BITS) (((((BITS) << 1) | ((BITS) >> 3))) & MASK(4))

int main(void) {
    const unsigned Bits = 0b0011;
    const int Start = 8;
    const int NumStep = 4;
    const int NumRound = 4;
    
    for (int Round = NumRound, Signal = Bits; Round > 0; 
            --Round, Signal = LROTATE_4(Signal)) {
        int FirstArg = Start;
        int SecondArg = Signal;
        int Step = NumStep;
        for (; Step > 0; --Step, ++FirstArg, SecondArg >>= 1) {
            printf("digitalWrite(%d, %d)\n", FirstArg, SecondArg & 1);
        }
        printf("delay(t)\n\n");
    }
    
    return 0;
}
INFO