Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint16_t speedMotor = 8349;
- uint16_t speedFirstByte=0;
- uint8_t speedSecondByte=0;
- void setup()
- {
- Serial.begin(9600);
- Serial.print ("DEC = ");
- Serial.println(speedMotor,DEC);
- Serial.print ("HEX = ");
- Serial.println(speedMotor,HEX);
- Serial.print ("BIN = ");
- Serial.print("\t\t");
- Serial.println(speedMotor,BIN);
- //выделяем первый байт, накладываем маску, обнуляем последние 8 бит
- speedFirstByte = speedMotor & 0b1111111100000000;
- Serial.print ("speedFirstByte=");
- Serial.print("\t");
- Serial.println(speedFirstByte,BIN);
- speedFirstByte = speedFirstByte >> 8;
- Serial.print("speedFirstByte BINARY = ");
- Serial.println(speedFirstByte,BIN);
- Serial.print ("speedFirstByte HEX = ");
- Serial.println(speedFirstByte,HEX);
- //выделяем второй байт, накладываем маску, обнуляем первые 8 бит
- speedSecondByte = speedMotor & 0b0000000011111111;
- Serial.print("speedSecondByte BINARY = ");
- Serial.println(speedSecondByte,BIN);
- Serial.print ("speedSecondByte HEX = ");
- Serial.println(speedSecondByte,HEX);
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment