Eme Fibonacci Well-Known Member Licensed User Longtime User Oct 21, 2016 #1 please, How to convert this code in C for B4R? B4X: void putByte(byte data) { byte i = 8; byte mask; while(i > 0) { mask = 0x01 << (i - 1); // get bitmask digitalWrite( clock, LOW); // tick if (data & mask){ // choose bit digitalWrite(dataIn, HIGH);// send 1 }else{ digitalWrite(dataIn, LOW); // send 0 } digitalWrite(clock, HIGH); // tock --i; // move to lesser bit } } Thank you.
please, How to convert this code in C for B4R? B4X: void putByte(byte data) { byte i = 8; byte mask; while(i > 0) { mask = 0x01 << (i - 1); // get bitmask digitalWrite( clock, LOW); // tick if (data & mask){ // choose bit digitalWrite(dataIn, HIGH);// send 1 }else{ digitalWrite(dataIn, LOW); // send 0 } digitalWrite(clock, HIGH); // tock --i; // move to lesser bit } } Thank you.
Erel B4X founder Staff member Licensed User Longtime User Oct 23, 2016 #2 B4X: For i = 7 To 0 Step -1 Clock.DigitalWrite (False) Dim value As Boolean If Bit.Get(Data, i) = 1 Then value = True Else Value = False Pin.DigitalWrite (value) Clock.DigitalWrite (True) Next Upvote 0
B4X: For i = 7 To 0 Step -1 Clock.DigitalWrite (False) Dim value As Boolean If Bit.Get(Data, i) = 1 Then value = True Else Value = False Pin.DigitalWrite (value) Clock.DigitalWrite (True) Next