8.Arduino learning notebook--Digital dice experiment


8.Arduino learning notebook--Digital dice experiment


             Juvtmall ( a company supply PCB PrototypingPCBA service and sell kinds of components, modules and so on) ( Catduino has the same function of Arduino)


Through the previous experiments of digital tube experiments and buttons that control leds, you should have learned the basic use of two devices. This time, use the nixie tube and button to make a simple digital dice.
The basic principle of the digital dice is that the nixie tube is quick to circulate between 1-8. When pressed, the nixie tube is fixed on the current number and dont bounce.
Take a look at the wiring diagram:






Through the previous experiments of digital tube experiments and buttons that control leds, you should have learned the basic use of two devices. This time, use the digital tube and button to make a simple digital dice.
The basic principle of the digital dice is that the digital tube is quick to circulate between 1-8. When pressed, the digital tube is fixed on the current number and dont bounce.
Take a look at the wiring diagram:
Arduino code
1. //Set the digital IO pin that controls each segment
2. int a=7;
3. int b=6;
4. int c=5;
5. int d=11;
6. int e=10;
7. int f=8;
8. int g=9;
9. int dp=4;
10. 
11. //display digital 1
12. void digital_1(void)
13. {
14.   unsigned char j;
15.   digitalWrite(c,LOW);//Give the digit 5 pins low level and light up the c segment
16.   digitalWrite(b,LOW);//light up the b segment
17.   for(j=7;j<=11;j++)//extinguish the rest segment
18. digitalWrite(j,HIGH);
19.       digitalWrite(dp,HIGH);//extinguish the decimal point DP segment
20. }
21. //display digital 2
22. void digital_2(void)
23. {
24.   unsigned char j;
25.   digitalWrite(b,LOW);
26.   digitalWrite(a,LOW);
27.   for(j=9;j<=11;j++)
28.     digitalWrite(j,LOW);
29.   digitalWrite(dp,HIGH);
30.   digitalWrite(c,HIGH);
31.   digitalWrite(f,HIGH);
32. }
33. //display digital 3
34. void digital_3(void)
35. {
36.   unsigned char j;
37.   digitalWrite(g,LOW);
38.   digitalWrite(d,LOW);
39.   for(j=5;j<=7;j++)
40.     digitalWrite(j,LOW);
41.   digitalWrite(dp,HIGH);
42.   digitalWrite(f,HIGH);
43.   digitalWrite(e,HIGH);
44. }
45. //display digital 4
46. void digital_4(void)
47. {
48.   digitalWrite(c,LOW);
49.   digitalWrite(b,LOW);
50.   digitalWrite(f,LOW);
51.   digitalWrite(g,LOW);
52.   digitalWrite(dp,HIGH);
53.   digitalWrite(a,HIGH);
54.   digitalWrite(e,HIGH);
55.   digitalWrite(d,HIGH);
56. }
57. //display digital 5
58. void digital_5(void)
59. {
60.   unsigned char j;
61.   for(j=7;j<=9;j++)
62.     digitalWrite(j,LOW);
63.   digitalWrite(c,LOW);
64.   digitalWrite(d,LOW);
65.   digitalWrite(dp,HIGH);
66.   digitalWrite(b,HIGH);
67.   digitalWrite(e,HIGH);
68. }
69. //display digital 6
70. void digital_6(void)
71. {
72.   unsigned char j;
73.   for(j=7;j<=11;j++)
74.     digitalWrite(j,LOW);
75.   digitalWrite(c,LOW);
76.   digitalWrite(dp,HIGH);
77.   digitalWrite(b,HIGH);
78. }
79. //display digital 7
80. void digital_7(void)
81. {
82.   unsigned char j;
83.   for(j=5;j<=7;j++)
84.     digitalWrite(j,LOW);
85.   digitalWrite(dp,HIGH);
86.   for(j=8;j<=11;j++)
87.     digitalWrite(j,HIGH);
88. }
89. //display digital 8
90. void digital_8(void)
91. {
92.   unsigned char j;
93.   for(j=5;j<=11;j++)
94.     digitalWrite(j,LOW);
95.   digitalWrite(dp,HIGH);
96. }
97. void setup()
98. {
99.     int i;
100.     for(i=4;i<=11;i++)
101.     {
102.     pinMode(i,OUTPUT);//set port 4~11 as output mode.    }
103. }
104. }
105. void loop()
106. {
107.    while(1)
108.    {
109.        digital_1();//display digital 1
110.        while(analogRead(0)>1000);//If you read the value of the analog port 0 is 1000, which indicates that the button was pressed.
111.        delay(100);//delay 100ms
112.         digital_2();
113.         while(analogRead(0)>1000);
114.        delay(100);
115.         digital_3();
116.         while(analogRead(0)>1000);
117.        delay(100);
118.         digital_4();
119.         while(analogRead(0)>1000);
120.        delay(100);
121.         digital_5();
122.         while(analogRead(0)>1000);
123.        delay(100);
124.         digital_6();
125.         while(analogRead(0)>1000);
126.        delay(100);
127.         digital_7();
128.         while(analogRead(0)>1000);
129.        delay(100);
130.         digital_8();
131.         while(analogRead(0)>1000);
132.        delay(100);
133.    }
134. }




The other blog


评论

此博客中的热门博文

21. Arduino learning notebook-- Experiment of controlling steering engine

20.Arduino learning notebook--Use Arduino Duemilanove to download the bootloader to other chips

19.Arduino learning notebook--Atmega8 makes the minimum arduino system