]> git.piffa.net Git - sketchbook_andrea/blob - shift_register/shift_register_8bit/shift_register_8bit.ino
Common esempi
[sketchbook_andrea] / shift_register / shift_register_8bit / shift_register_8bit.ino
1 //**************************************************************//
2 // Name : shiftOutCode, Hello World
3 // Author : Carlyn Maw,Tom Igoe, David A. Mellis
4 // Date : 25 Oct, 2006
5 // Modified: 23 Mar 2010
6 // Version : 2.0
7 // Notes : Code for using a 74HC595 Shift Register
8 //
9 // : to count from 0 to 255
10 //****************************************************************
11
12
13 //Pin connected to ST_CP of 74HC595
14 int latchPin = 8;
15 //Pin connected to SH_CP of 74HC595
16 int clockPin = 12;
17 ////Pin connected to DS of 74HC595
18 int dataPin = 11;
19 void setup() {
20   //set pins to output so you can control the shift register
21   pinMode(latchPin, OUTPUT);
22
23 pinMode(clockPin, OUTPUT);
24 pinMode(dataPin, OUTPUT);
25 }
26 void loop() {
27   // count from 0 to 255 and display the number
28   // on the LEDs
29   for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
30     // take the latchPin low so
31     // the LEDs don’t change while you’re sending in bits:
32     digitalWrite(latchPin, LOW);
33     // shift out the bits:
34     shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
35     //take the latch pin high so the LEDs will light up:
36     digitalWrite(latchPin, HIGH);
37     // pause before next value:
38     delay(500);
39   }
40 }
41
42
43