Skip to content

Commit 250109f

Browse files
committed
feat(wokwi-analog-joystick/joystick-uno): joystick test
1 parent 811cff6 commit 250109f

File tree

7 files changed

+118
-0
lines changed

7 files changed

+118
-0
lines changed

.github/workflows/wokwi-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
- name: oled-esp32
2020
path: board-ssd1306/oled-esp32
2121
scenario: ssd1306.test.yaml
22+
- name: joystick-uno
23+
path: wokwi-analog-joystick/joystick-uno
24+
scenario: joystick.test.yaml
2225
- name: dht22-uno
2326
path: wokwi-dht22/dht22-uno
2427
scenario: dht22.test.yaml

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This repository contains a set of test projects for many Wokwi parts. The tests
66

77
- board-ssd1306
88
- [ESP32](./board-ssd1306/oled-esp32/)
9+
- wokwi-analog-joystick
10+
- [Arduino Uno](./wokwi-analog-joystick/joystick-uno/)
911
- wokwi-dht22
1012
- [Arduino Uno](./wokwi-dht22/dht22-uno/)
1113
- [ESP32](./wokwi-dht22/dht22-esp32/)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": 1,
3+
"author": "Uri Shaked",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 120, "left": 20, "attrs": {} },
7+
{
8+
"type": "wokwi-analog-joystick",
9+
"id": "joystick1",
10+
"top": -9.72,
11+
"left": 264.35,
12+
"attrs": {}
13+
}
14+
],
15+
"connections": [
16+
[ "joystick1:HORZ", "uno:A1", "green", [ "v0", "*", "v12" ] ],
17+
[ "joystick1:VERT", "uno:A0", "purple", [ "v0", "*", "v16" ] ],
18+
[ "joystick1:SEL", "uno:2", "blue", [ "v0", "*", "v-12" ] ],
19+
[ "joystick1:GND", "uno:GND.3", "black", [ "v0", "*", "v20" ] ],
20+
[ "joystick1:VCC", "uno:5V", "red", [ "v0", "*", "v24" ] ]
21+
],
22+
"dependencies": {}
23+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 'DHT22 Sensor Test'
2+
version: 1
3+
author: 'Uri Shaked'
4+
5+
steps:
6+
- wait-serial: 'Analog Joystick test'
7+
- set-control:
8+
part-id: joystick1
9+
control: x
10+
value: -1
11+
- delay: 100ms
12+
- wait-serial: 'Horizontal: 0'
13+
- set-control:
14+
part-id: joystick1
15+
control: y
16+
value: 1
17+
- delay: 100ms
18+
- wait-serial: 'Vertical: 1023'
19+
- set-control:
20+
part-id: joystick1
21+
control: x
22+
value: 0.5
23+
- delay: 100ms
24+
- wait-serial: 'Horizontal: 768'
25+
- set-control:
26+
part-id: joystick1
27+
control: pressed
28+
value: 1
29+
- wait-serial: 'Select pressed'
30+
- set-control:
31+
part-id: joystick1
32+
control: pressed
33+
value: 0
34+
- wait-serial: 'Select released'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[env:uno]
2+
platform = atmelavr
3+
board = uno
4+
framework = arduino
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <Arduino.h>
2+
3+
#define VERT_PIN A0
4+
#define HORZ_PIN A1
5+
#define SEL_PIN 2
6+
7+
void setup()
8+
{
9+
Serial.begin(115200);
10+
Serial.println(F("Analog Joystick test"));
11+
pinMode(SEL_PIN, INPUT_PULLUP);
12+
}
13+
14+
int lastVert = 0;
15+
int lastHorz = 0;
16+
bool lastSelPressed = false;
17+
18+
void loop()
19+
{
20+
int vert = analogRead(VERT_PIN);
21+
int horz = analogRead(HORZ_PIN);
22+
bool selPressed = digitalRead(SEL_PIN) == LOW;
23+
if (vert != lastVert)
24+
{
25+
Serial.print(F("Vertical: "));
26+
Serial.println(vert);
27+
lastVert = vert;
28+
}
29+
if (horz != lastHorz)
30+
{
31+
Serial.print(F("Horizontal: "));
32+
Serial.println(horz);
33+
lastHorz = horz;
34+
}
35+
if (selPressed != lastSelPressed)
36+
{
37+
if (selPressed)
38+
{
39+
Serial.println(F("Select pressed"));
40+
}
41+
else
42+
{
43+
Serial.println(F("Select released"));
44+
}
45+
lastSelPressed = selPressed;
46+
}
47+
delay(100);
48+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[wokwi]
2+
version = 1
3+
firmware = '.pio/build/uno/firmware.hex'
4+
elf = '.pio/build/uno/firmware.elf'

0 commit comments

Comments
 (0)