Created
April 11, 2020 19:36
-
-
Save handeyeco/b93cd0d14e483ce7dd032f30d16873fc 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 digit1 = 2; | |
int digit2 = 3; | |
int digit3 = 4; | |
int digit4 = 5; | |
int clock = 10; | |
int latch = 11; | |
int data = 12; | |
//initialize the digital pin as an outout | |
void setup() { | |
pinMode(latch, OUTPUT); | |
pinMode(clock, OUTPUT); | |
pinMode(data, OUTPUT); | |
pinMode(digit1, OUTPUT); | |
pinMode(digit2, OUTPUT); | |
pinMode(digit3, OUTPUT); | |
pinMode(digit4, OUTPUT); | |
} | |
void display(int digit, int num) | |
{ | |
digitalWrite(digit1, LOW); | |
digitalWrite(digit2, LOW); | |
digitalWrite(digit3, LOW); | |
digitalWrite(digit4, LOW); | |
digitalWrite(latch, HIGH); | |
shiftOut(data, clock, MSBFIRST, num); | |
digitalWrite(latch, LOW); | |
switch(digit) { | |
case 1: digitalWrite(digit1, HIGH); break; | |
case 2: digitalWrite(digit2, HIGH); break; | |
case 3: digitalWrite(digit3, HIGH); break; | |
case 4: digitalWrite(digit4, HIGH); break; | |
} | |
digitalWrite(latch, HIGH); | |
shiftOut(data, clock, MSBFIRST, 0); | |
digitalWrite(latch, LOW); | |
} | |
void loop() { | |
display(1, B01000000); | |
display(2, B00100000); | |
display(3, B00010000); | |
display(4, B00001000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment