Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MAX6955.cpp
- Committer:
- Kentaro Okuda
- Date:
- 2018-08-11
- Revision:
- 2:f6c4ed9cbf0e
- Parent:
- 1:8936ddb97551
- Child:
- 3:fbcb79f6e0a8
File content as of revision 2:f6c4ed9cbf0e:
/**
* @file MAX6955.cpp
*/
#include "MAX6955.h"
MAX6955::MAX6955(PinName sda, PinName scl, char driver): i2c_(sda, scl), driver_(driver){}
static void prepareString(char* buffer, char* i2cData) {
for (int i = 0; i < 8; i++) {
if (buffer[i] < 32 || buffer[i] > 126) { // make sure its printable
i2cData[i+1] = 32; // if not, replace it with "space"
} else {
i2cData[i+1] = buffer[i];
}
}
}
int MAX6955::write(char command, char data) {
char i2cData[2];
i2cData[0] = command;
i2cData[1] = data;
int result = i2c_.write(driver_, i2cData, 2);
wait(0.07);
return result;
}
int MAX6955::writeS(char* buffer) {
char i2cData[9];
i2cData[0] = 0x20; // first digit
prepareString(buffer, i2cData);
int result = i2c_.write(driver_, (char *) i2cData, 9);
wait(0.07);
return result;
}
int MAX6955::init(void) {
int result = 0;
result = result + write(reg_decodeMode, 0x00);
result = result + write(reg_scanLimit, 0x07);
result = result + write(reg_configuration, 0x21);
result = result + write(reg_globalIntensity, 0x08);
result = result + write(reg_digitType, 0xFF);
result = result + write(reg_displayTest, 0x00);
return result;
}