Adding a little math to convert an integer RPM into MSB and LSB...
Code:
void setup() {
Serial.begin(8192);
}
void loop() {
if (Serial.availableForWrite() > 5) {
int rpm = 3200;
byte msb = floor(rpm / 256);
byte lsb = rpm % 256;
byte b[5] = {0x0A, 0x58, 0x40, msb, lsb};
unsigned int x = 0, sum = 0;
for (x = 0; x < sizeof(b); x++) sum += b[x];
byte cs = ( 256 - ( sum % 256 ) );
Serial.write(b, 5);
Serial.write(cs);
}
}
Now if that works, I will add a potentiometer and read that for input to convert to an rpm reading, and I should be able to control my tachometer in real time!
Bookmarks