68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
const int latchPin = 8; //ST_CP or RCLK
|
|
const int clockPin = 12; //SH_CP or SRCLK
|
|
const int dataPin = 11; //DS or SER
|
|
|
|
byte seven_seg_digits[10][7] = {
|
|
{ 1,1,1,1,1,1,0 }, // = 0
|
|
{ 0,1,1,0,0,0,0 }, // = 1
|
|
{ 1,1,0,1,1,0,1 }, // = 2
|
|
{ 1,1,1,1,0,0,1 }, // = 3
|
|
{ 0,1,1,0,0,1,1 }, // = 4
|
|
{ 1,0,1,1,0,1,1 }, // = 5
|
|
{ 1,0,1,1,1,1,1 }, // = 6
|
|
{ 1,1,1,0,0,0,0 }, // = 7
|
|
{ 1,1,1,1,1,1,1 }, // = 8
|
|
{ 1,1,1,0,0,1,1 } // = 9
|
|
};
|
|
|
|
int digits[10] = {
|
|
126, 48, 109, 121, 51, 91, 95, 112, 127,
|
|
}
|
|
|
|
|
|
void writeNumber(int character) {
|
|
/* The shift register shifts out bits to the ADO lines. In binary:
|
|
* 1110 = Sensor on Q0(QA) ~(2^0) = ~1 = 1110 in binary
|
|
* 1101 = Sensor on Q1(QB) ~(2^1) = ~2 = 1101 in binary
|
|
* '~' = not
|
|
*/
|
|
//int data = (int) 1 << (sensorNumber - 1); // Shift register serial data input.
|
|
|
|
digitalWrite(latchPin, LOW); // Hold low for as long as you are transmitting data.
|
|
shiftOutBits(dataPin, clockPin, character); // Shift out the bits into the shift register; negate data. (0001 = 1000)
|
|
digitalWrite(latchPin, HIGH); // Ends transmission of data.
|
|
}
|
|
|
|
void shiftOutBits(int myDataPin, int myClockPin, int number) {
|
|
// This shifts 8 bits out MSB first.
|
|
|
|
// Setup Varaibles
|
|
int pinState;
|
|
|
|
pinMode(myClockPin, OUTPUT);
|
|
pinMode(myDataPin, OUTPUT);
|
|
|
|
// Clear everything out in case to prepare shift register.
|
|
digitalWrite(myDataPin, 0);
|
|
digitalWrite(myClockPin, 0);
|
|
|
|
// For each bit in the byte myDataOut.
|
|
for (int i = 7; i >= 0; i--) {
|
|
digitalWrite(myClockPin, 0);
|
|
|
|
pinState = 1 - seven_seg_digits[number][i];
|
|
digitalWrite(myDataPin, pinState); // Sets the pin to HIGH or LOW depending on pinState.
|
|
digitalWrite(myClockPin, 1); // Register shifts on HIGH of myClockPin.
|
|
digitalWrite(myDataPin, 0); // Stop sending on myDataPin.
|
|
}
|
|
digitalWrite(myClockPin, 0); // Stop shifting.
|
|
}
|
|
|
|
void setup() {
|
|
writeNumber(5);
|
|
}
|
|
|
|
void loop() {
|
|
return;
|
|
}
|