source: t29-www/physical-computing/bcd-decoder/bcd-decoder.ino @ 1190

Last change on this file since 1190 was 1190, checked in by heribert, 7 years ago

Änderungen in PCR

File size: 2.8 KB
RevLine 
[1190]1
2 
3//Declaration of Arduino pins used as CA3161E (BCD-Decoder) inputs
4
5const int A=4;    // wir ordnen der Variablen A die Zahl 4 zu
6const int B=5;    // wir koennten auch ueberall fuer A,B,C,D die Zahlen 4,5,6,7 verwenden
7const int C=6;
8const int D=7;   
9
10const int TASTE = 8;  // gedrueckt: LOW
11 
12void setup() {
13  pinMode(TASTE, INPUT_PULLUP);
14  pinMode(A, OUTPUT); // 2^0     
15  pinMode(B, OUTPUT);
16  pinMode(C, OUTPUT);
17  pinMode(D, OUTPUT); // 2^3
18
19  Serial.begin(9600);
20 
21}
22 
23int count = 0;     //the variable used to show the number
24 
25void loop() {
26  if (digitalRead(TASTE) == LOW)   //if button is pressed
27    {
28    count++;                    // ausfuehrlich:  c=c+1
29    delay(500);           //the delay prevent from button bouncing
30    if (count == 10)      //we want to count from 0 to 9!
31      count = 0;
32
33/*{  alternativ mit C++ :
34  Setzten der vier oberen PINs des Ports D und beibehalten der Zustände der unteren vier PINs
35  PORTD = (count << 4) & 0xf0 | (PORTD & 0xf)  ;
36  return ;  //diese 2 Zeilen bewirken das Gleiche, wie der Rest unten. Sie sind aber "deaktiviert"
37            //weil wir sie noch nicht verstehen! }
38  */
39
40    if (count == 0) //write 0000   ab hier steht die Umsetzung des BCD Codes
41    {
42      digitalWrite(A, LOW);
43      digitalWrite(B, LOW);
44      digitalWrite(C, LOW);
45      digitalWrite(D, LOW);
46     
47    }
48     
49    if (count == 1) //write 0001
50    {
51      digitalWrite(A, HIGH);
52      digitalWrite(B, LOW);
53      digitalWrite(C, LOW);
54      digitalWrite(D, LOW);
55     
56    }
57     
58    if (count == 2) //write 0010
59    {
60      digitalWrite(A, LOW);
61      digitalWrite(B, HIGH);
62      digitalWrite(C, LOW);
63      digitalWrite(D, LOW);
64       
65    }
66     
67    if (count == 3) //write 0011
68    {
69      digitalWrite(A, HIGH);
70      digitalWrite(B, HIGH);
71      digitalWrite(C, LOW);
72      digitalWrite(D, LOW);
73     
74    }
75     
76    if (count == 4) //write 0100
77    {
78      digitalWrite(A, LOW);
79      digitalWrite(B, LOW);
80      digitalWrite(C, HIGH);
81      digitalWrite(D, LOW);
82    }
83     
84    if (count == 5) //write 0101
85    {
86      digitalWrite(A, HIGH);
87      digitalWrite(B, LOW);
88      digitalWrite(C, HIGH);
89      digitalWrite(D, LOW);
90    }
91     
92    if (count == 6) //write 0110
93    {
94      digitalWrite(A, LOW);
95      digitalWrite(B, HIGH);
96      digitalWrite(C, HIGH);
97      digitalWrite(D, LOW);
98    }
99     
100    if (count == 7) //write 0111
101    {
102      digitalWrite(A, HIGH);
103      digitalWrite(B, HIGH);
104      digitalWrite(C, HIGH);
105      digitalWrite(D, LOW);
106    }
107     
108    if (count == 8) //write 1000
109    {
110      digitalWrite(A, LOW);
111      digitalWrite(B, LOW);
112      digitalWrite(C, LOW);
113      digitalWrite(D, HIGH);
114    }
115     
116    if (count == 9) //write 1001
117    {
118      digitalWrite(A, HIGH);
119      digitalWrite(B, LOW);
120      digitalWrite(C, LOW);
121      digitalWrite(D, HIGH);
122    }
123    }
124   
125}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License