-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca25362
commit f606667
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Day sixteen: | ||
|
||
Let's play a game! Yesterday you transformed your Barduino in a keyboard, now let's use it to play a game. Program yoou board to be able to use the arrow keys with th touchsensors (or use the code below) and play a game like [snake.io](snake.io) with it. | ||
|
||
!!! danger "Arduino Tips" | ||
Like yesterday, if you use our code, you have to change the *USB Mode: USB-OTG (Tiny USB)* setting under *Tools* in Arduino. | ||
![arduino usb otg](../../images/OTGMode.png) | ||
Using this mode, you have to use *Boot Mode* to program the board (Press *Boot 00* button while reseting). When programming the board may change the *Port* number, so to programmed back you may need to change the port. | ||
|
||
## Possible solution! | ||
|
||
### Arduino code | ||
|
||
```c++ | ||
#include "USB.h" | ||
#include "USBHIDKeyboard.h" | ||
USBHIDKeyboard Keyboard; | ||
|
||
unsigned long values[] = {0,0,0,0}; | ||
int direction[] = {KEY_UP_ARROW,KEY_RIGHT_ARROW,KEY_DOWN_ARROW,KEY_LEFT_ARROW}; | ||
|
||
int dir = 4; | ||
|
||
unsigned long threshold = 40000; | ||
|
||
void setup() { | ||
Keyboard.begin(); | ||
USB.begin(); | ||
} | ||
|
||
void loop() { | ||
unsigned long max = 0; | ||
int max_i; | ||
for (int i = 0; i < 4; i++) { | ||
values[i] = touchRead(i + 4); | ||
if (values[i] > max) { | ||
max = values[i]; | ||
max_i = i; | ||
} | ||
} | ||
//Serial.println(""); | ||
if (max>threshold && dir!=max_i) { | ||
dir = max_i; | ||
Keyboard.releaseAll(); | ||
Keyboard.press(direction[dir]); | ||
} else if (max <= threshold) { | ||
dir = 4; | ||
Keyboard.releaseAll(); | ||
} | ||
} | ||
``` | ||
|
||
## Hero shot | ||
|
||
<video controls autoplay loop style="display: block; margin: auto;"> | ||
<source src="../../../video/day16.mp4" type="video/mp4"> | ||
</video> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters