Compare commits
2 Commits
02223a7c77
...
0d375f8679
Author | SHA1 | Date |
---|---|---|
CalisJI | 0d375f8679 | |
CalisJI | eb55184825 |
55
README.md
55
README.md
|
@ -27,46 +27,25 @@ ser.write(data_to_send)
|
||||||
ser.close()
|
ser.close()
|
||||||
|
|
||||||
```
|
```
|
||||||
### Receive Data
|
# Data frame format
|
||||||
|
```python
|
||||||
|
# Game Hung Vat
|
||||||
|
x = 60 # X coordinate
|
||||||
|
y = 120 # Y coordinate (no action)
|
||||||
|
z = 1 # action (no action)
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
|
||||||
```c++
|
# Game Stick Man
|
||||||
void loop() {
|
x = 60 # X coordinate
|
||||||
while (Serial.available() > 0) {
|
y = 120 # Y coordinate (no action)
|
||||||
uint8_t byteReceived = Serial.read();
|
z = 1 # 1: right shield; 2 left shield; 0 none sheild
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
|
||||||
if (bufferIndex < bufferSize) {
|
#Game Space Invaders
|
||||||
buffer[bufferIndex++] = byteReceived;
|
|
||||||
} else {
|
|
||||||
// Xử lý tình huống quá tải
|
|
||||||
Serial.println("Buffer overflow");
|
|
||||||
bufferIndex = 0; // Reset buffer index in case of overflow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bufferIndex >= 2 * sizeof(int)) {
|
|
||||||
// Đã nhận đủ kích thước dữ liệu
|
|
||||||
memcpy(&numRows, buffer, sizeof(int));
|
|
||||||
memcpy(&numCols, buffer + sizeof(int), sizeof(int));
|
|
||||||
|
|
||||||
int expectedSize = numRows * numCols * floatSize;
|
x = 60 # X coordinate
|
||||||
|
y = 120 # Y coordinate (no action)
|
||||||
|
z = 1 # 1: fire bullet; 0 none fire
|
||||||
|
data = np.array([[60, 120,1]]).astype(np.float32)
|
||||||
|
|
||||||
if (bufferIndex >= (2 * sizeof(int) + expectedSize)) {
|
|
||||||
Serial.println("Data received:");
|
|
||||||
float data[numRows][numCols];
|
|
||||||
for (int row = 0; row < numRows; ++row) {
|
|
||||||
for (int col = 0; col < numCols; ++col) {
|
|
||||||
int index = (2 * sizeof(int)) + (row * numCols + col) * floatSize;
|
|
||||||
float value;
|
|
||||||
memcpy(&value, &buffer[index], floatSize);
|
|
||||||
data[row][col] = value;
|
|
||||||
Serial.print(value, 4); // In với 4 chữ số thập phân
|
|
||||||
Serial.print(" ");
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset chỉ số chỉ mục sau khi xử lý
|
|
||||||
bufferIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
Loading…
Reference in New Issue