Created
January 4, 2014 05:04
-
-
Save nrdobie/8251990 to your computer and use it in GitHub Desktop.
This file contains 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
#include <SPI.h> | |
void setup() { | |
// We will need to control the Load/CS pin so | |
// make a pin an output, for this example I'll | |
// use pin 7. | |
pinMode(7, OUTPUT); | |
// The Maxim chip need the most siginifcant | |
// bit first. | |
SPI.setBitOrder(MSBFIRST); | |
// Make sure that the chip is turned on | |
maxTransfer(0x0C, 0x01); | |
// We can use the display decode mode to | |
// easily pick the character | |
maxTransfer(0x09, 0xFF); | |
} | |
void loop() { | |
// Loop through each character | |
for (uint8_t i = 0; i < 0x10; ++i) | |
{ | |
// Update the 1st digit | |
maxTransfer(0x01, i); | |
// Display for 500ms | |
delay(500); | |
} | |
} | |
void maxTransfer(uint8_t reg, uint8_t data) | |
{ | |
// Make sure that the Load/CS pin is low | |
digitalWrite(7, LOW); | |
// Open SPI | |
SPI.begin(); | |
// The Maxim chip wants the register's | |
// address first | |
SPI.transfer(reg); | |
// Next send the data | |
SPI.transfer(data); | |
// End SPI | |
SPI.end(); | |
// The Maxim chip loads the data when the | |
// Load/CS pin switches from low to high | |
digitalWrite(7, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment