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