Created
January 30, 2014 16:39
-
-
Save anonymous/8712796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int dataPin = 2; | |
int clockPin = 3; | |
int csPin = 4; | |
byte chars[] = { | |
B00011000, | |
B00111100, | |
B01100110, | |
B11000011, | |
B00011000, | |
B00111100, | |
B01100110, | |
B11000011 | |
}; | |
byte REG_DECODEMODE = 0x09; | |
byte REG_INTENSITY = 0x0a; | |
byte REG_SCANLIMIT = 0x0b; | |
byte REG_SHUTDOWN = 0x0c; | |
byte REG_DISPLAYTEST = 0x0f; | |
void sendCmd(byte addr, byte data) { | |
digitalWrite(csPin, LOW); | |
shiftOut(dataPin, clockPin, MSBFIRST, addr); | |
shiftOut(dataPin, clockPin, MSBFIRST, data); | |
digitalWrite(csPin, HIGH); | |
} | |
// the setup routine runs once when you press reset | |
void setup() { | |
// set pin modes | |
pinMode(dataPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
pinMode(csPin, OUTPUT); | |
// setup display | |
sendCmd(REG_DISPLAYTEST, 0x00); // turn off display test | |
sendCmd(REG_DECODEMODE, 0x00); // turn off decode mode | |
sendCmd(REG_SHUTDOWN, 0x01); // turn off shutdown mode (1 = off) | |
sendCmd(REG_SCANLIMIT, 0x07); // set scan limit to 8 segments | |
sendCmd(REG_INTENSITY, 0x01); // dial down intensity | |
// clear registers | |
for (byte i = 1; i < 9; i++) { | |
sendCmd(i, 0x00); | |
} | |
} // end setup | |
int offs = 0; | |
// the loop routine runs over and over again forever | |
void loop() { | |
for (byte i = offs, j = 0; i < offs + 8; i++, j++) { | |
sendCmd(j + 1, chars[i % 8]); | |
} | |
offs++; | |
if (offs == 8) offs = 0; | |
delay(50); | |
} // end loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment