Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 73253e8

Browse files
committedNov 24, 2022
add : final test
1 parent 158ec4b commit 73253e8

File tree

9 files changed

+183
-11
lines changed

9 files changed

+183
-11
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode
2-
test.ino
2+
test.ino
3+
main.ino

‎README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
### Assignment
1010

11-
| \# | Assignment | Completed |
12-
| :-: | -------------------- | :-------: |
13-
| 1 | Charliplexing | ✔️ |
14-
| 2 | Priority Switch | ✔️ |
15-
| 3 | Number Guess | ✔️ |
16-
| 4 | Pong Game (Project) | ✔️ |
17-
| 5 | Finite State Machine | ✔️ |
18-
| 6 | Network Chat | ✔️ |
19-
| 7 | Mini Clock (Project) | ✔️ |
20-
| 8 | Free Rtos | ✔️ |
11+
| \# | Assignment | Completed |
12+
| :-: | ------------------------------------------------ | :-------: |
13+
| 1 | [Charliplexing](./assignment_1/README.md) | ✔️ |
14+
| 2 | [Priority Switch](./assignment_2/README.md) | ✔️ |
15+
| 3 | [Number Guess](./assignment_3/README.md) | ✔️ |
16+
| 4 | [Pong Game (Project)](./assignment_4/README.md) | ✔️ |
17+
| 5 | [Finite State Machine](./assignment_5/README.md) | ✔️ |
18+
| 6 | [Network Chat](./assignment_6/README.md) | ✔️ |
19+
| 7 | [Mini Clock (Project)](./assignment_7/README.md) | ✔️ |
20+
| 8 | [Free Rtos](./assignment_8/README.md) | ✔️ |
21+
| 9 | [Final Test](./final_test/README.md) | ✔️ |
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎assignment_4/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Pong Game
2+
3+
> [Code](./17_0077_0107.ino)
File renamed without changes.

‎final_test/65010077.ino

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
int LED[5] = {9, 10, 11, 12, 13};
2+
int BTN[5] = {2, 3, 4, 5, 6};
3+
4+
bool reading[5];
5+
bool lastButtonState[5] = {LOW, LOW, LOW, LOW, LOW};
6+
bool buttonState[5] = {LOW, LOW, LOW, LOW, LOW};
7+
unsigned long long int lastDebounceTime[5];
8+
int debounceDelay = 50;
9+
10+
bool ledState[5] = {LOW, LOW, LOW, LOW, LOW};
11+
int num = 0;
12+
bool mem[4] = {0, 0, 0, 0};
13+
int step = 0;
14+
bool copy[4] = {0, 0, 0, 0};
15+
16+
void setup()
17+
{
18+
Serial.begin(9600);
19+
for (int i = 0; i < 5; i++)
20+
{
21+
pinMode(LED[i], OUTPUT);
22+
pinMode(BTN[i], INPUT_PULLUP);
23+
}
24+
}
25+
26+
bool debounce(int i)
27+
{
28+
bool isChange = 0;
29+
reading[i] = !digitalRead(BTN[i]);
30+
if (reading[i] != lastButtonState[i])
31+
{
32+
lastDebounceTime[i] = millis();
33+
}
34+
if ((millis() - lastDebounceTime[i]) > debounceDelay)
35+
{
36+
if (reading[i] != buttonState[i])
37+
{
38+
buttonState[i] = reading[i];
39+
isChange = 1;
40+
}
41+
}
42+
lastButtonState[i] = reading[i];
43+
return isChange;
44+
}
45+
46+
void resetLED()
47+
{
48+
for (int i = 0; i < 5; i++)
49+
{
50+
ledState[i] = LOW;
51+
digitalWrite(LED[i], ledState[i]);
52+
}
53+
}
54+
55+
void resetMem()
56+
{
57+
for (int i = 0; i < 4; i++)
58+
{
59+
mem[i] = 0;
60+
}
61+
}
62+
63+
void loop()
64+
{
65+
for (int i = 0; i < 3; i++)
66+
{
67+
if (debounce(i))
68+
{
69+
if (buttonState[i] == HIGH)
70+
{
71+
ledState[i + 1] = !ledState[i + 1];
72+
digitalWrite(LED[i + 1], ledState[i + 1]);
73+
}
74+
}
75+
}
76+
77+
if (debounce(3))
78+
{
79+
if (buttonState[3] == HIGH)
80+
{
81+
if (step == 0)
82+
{
83+
mem[1] = ledState[1];
84+
mem[2] = ledState[2];
85+
mem[3] = ledState[3];
86+
step++;
87+
Serial.print("Mem : ");
88+
Serial.print(mem[0]);
89+
Serial.print(mem[1]);
90+
Serial.print(mem[2]);
91+
Serial.println(mem[3]);
92+
resetLED();
93+
}
94+
else if (step == 1)
95+
{
96+
for (int i = 0; i < 3; i++)
97+
{
98+
num *= 2;
99+
num += ledState[i + 1];
100+
}
101+
Serial.print("Num : ");
102+
Serial.println(num);
103+
step++;
104+
resetLED();
105+
}
106+
else if (step == 2)
107+
{
108+
109+
for (int i = 0; i < num; i++)
110+
{
111+
for (int i = 0; i < 4; i++)
112+
{
113+
copy[i] = mem[i];
114+
}
115+
mem[0] = copy[1];
116+
mem[1] = copy[2];
117+
mem[2] = copy[3];
118+
mem[3] = copy[0];
119+
Serial.print("Mem : ");
120+
Serial.print(mem[0]);
121+
Serial.print(mem[1]);
122+
Serial.print(mem[2]);
123+
Serial.println(mem[3]);
124+
}
125+
for (int i = 0; i < 4; i++)
126+
{
127+
ledState[i] = mem[i];
128+
digitalWrite(LED[i], ledState[i]);
129+
}
130+
step++;
131+
}
132+
else if (step == 3)
133+
{
134+
resetMem();
135+
resetLED();
136+
step = 0;
137+
num = 0;
138+
}
139+
}
140+
}
141+
}

‎final_test/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Final Test
2+
3+
> [Code](./65010077.ino)
4+
5+
### Requirement
6+
7+
- กำหนดให้มีสวิตซ์จำนวน 4 ตัว และ LED จำนวน 4 ดวง
8+
- ต้องต่อตัวต้านทานให้ถูกต้อง มิฉะนั้นจะไม่ตรวจ
9+
- ให้สวิตซ์ 3 ตัว แทยตัวเลข Input กำหนดให้ กดหมายถึง 1 และ ไม่กด หมายถึง 0
10+
- สวิตซ์ตัวที่ 4 ทำหน้าที่กดเพื่อรับข้อมูล
11+
- เมื่อเริ่มทำงาน ให้ LED ทุกดวงดับหมด และรอรับข้อมูล 3 บิต ชุดที่ 1 (โดยการกดสวิตซ์ 3 ตัวแรก ค้างไว้และกดสวิตซ์ที่ 4 เพื่อรับ) จากนั้นให้นำผลของการป้อนข้อมูลมาแสดงผลที่ LED 3 ดวงขวาสุด
12+
- จากนั้นรอรับข้อมูล 3 บิต ชุดที่ 2 (โดยการกดสวิตซ์ 3 ตัวแรก ค้างไว้และกดสวิตซ์ที่ 4 เพื่อรับ) จากนั้นให้นำผลของการป้อนข้อมูลมาแสดงผลที่ LED 3 ดวงขวาสุด
13+
- เมื่อกดสวิตซ์ที่ 4 อีกครั้งให้นำเลขฐาน 2 ชุดที่ 1 มาทำการเติมบิต 0 เข้าไปข้างหน้า และทำการ Rotate แบบ Circular ไปทางซ้าย เป็นจำนวนเท่ากับจำนวนครั้งในข้อมูลชุดที่ 2 จากนั้นแสดงผลลัพธ์เป็นเลขฐาน 2 จำนวน 4 บิต ที่ LED ทั้ง 4 ดวง
14+
- เมื่อกดสวิตซ์ตัวที่ 4 อีกครั้ง ให้เริ่มทำงานใหม่
15+
16+
### Example
17+
```
18+
ตัวเลขชุดที่ 1 = 101
19+
ตัวเลขชุดที่ 12 = 011
20+
เพิ่มบิต 0 เข้าไปหน้าตัวเลขชุดที่ 1 = 0101
21+
ทำการ Rotate แบบ Circular จำนวน 3 ครั้ง
22+
- ครั้งที่ 1 = 1010
23+
- ครั้งที่ 2 = 0101
24+
- ครั้งที่ 3 = 1010
25+
จากนั้นให้นำตัวเลข 1010 มาแสดงที่ LED
26+
```

0 commit comments

Comments
 (0)
This repository has been archived.