-
Notifications
You must be signed in to change notification settings - Fork 1
/
Larson_Scanner.ino
49 lines (38 loc) · 1.15 KB
/
Larson_Scanner.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This is a code for building a Larson Scanner using
// arduino , Shift Register and led interface
// link to simulator
// https://www.tinkercad.com/things/3wV3efTJyqz-larsonscanner
// Pins
const int data_pin =2;
const int clock_pin = 3;
const int latch_pin = 4;
void setup() {
pinMode(data_pin ,OUTPUT);
pinMode(clock_pin, OUTPUT);
pinMode(latch_pin , OUTPUT);
}
void loop() {
// B = binary number
byte x =B10000000;
byte y =B00000001;
for(int i =0;i<8;i++){
shiftDisplay(x);
x = x >>1; // bitwise right shift x on every iteration
delay(100);
}
for(int i =0;i<8;i++){
shiftDisplay(y);
y = y << 1; // bitwise left shift x on every iteration
delay(100);
}
}
// for transfer to take place 1st latch is initiated to low indictes a signal is about to come
// on completion of transfer turn latch pin to HIGH
void shiftDisplay(byte data){
digitalWrite(latch_pin, LOW);
// shiftout is a built-In function that sends a single byte serially n a pin.
// LSBFIRST = Least Significant Bit First
// MSBFIRST =Most Significant Bit First
shiftOut(data_pin, clock_pin,LSBFIRST , data);
digitalWrite(latch_pin, HIGH);
}