Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setByte() function #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/LedControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ void LedControl::setChar(int addr, int digit, char value, boolean dp) {
spiTransfer(addr, digit+1,v);
}

void LedControl::setByte(int addr, int digit, byte value, boolean dp) {
int offset;
byte index,v;

offset=addr*8;
v = value;
if(dp)
v|=B10000000;
status[offset+digit]=v;
spiTransfer(addr, digit+1,v);
}

void LedControl::spiTransfer(int addr, volatile byte opcode, volatile byte data) {
//Create an array with the data to shift out
int offset=addr*2;
Expand Down
24 changes: 24 additions & 0 deletions src/LedControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ class LedControl {
* dp sets the decimal point.
*/
void setChar(int addr, int digit, char value, boolean dp);

/*
* Display a specified byte on a 7-Segment Display.
* Specify a byte in the format: B_______
* where the blanks are either 1's or 0's corresponding to the on-off state of each of the segments A-G.
*
* Diagram of the 7-segments:
* --A--
* | |
* F B
* | |
* --G--
* | |
* E C
* | |
* --D--
*
* Params:
* addr address of the display
* digit the position of the digit on the display (0..7)
* value the value to be displayed, with each bit corresponding to a segment A-G
* dp sets the decimal point.
*/
void setByte(int addr, int digit, byte value, boolean dp);
};

#endif //LedControl.h
Expand Down