Skip to content

Commit 0c9478b

Browse files
committed
Use analogWrite together with a polyfill lib
1 parent aa058a9 commit 0c9478b

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ In order to reload a program, use the `0000` instruction to halt the VM and rest
2828

2929
Tested on ESP32 Arduino (WROOM32).
3030

31+
Prerequisites:
32+
33+
- Install analogWrite polyfill
34+
3135
References:
3236

3337
- http://en.wikipedia.org/wiki/CHIP-8

bin/example.bin

0 Bytes
Binary file not shown.

bin/example.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
#include <analogWrite.h>
2+
13
void setup() {
24
pinMode(LED_BUILTIN, OUTPUT);
35
}
46

57
void loop() {
6-
digitalWrite(LED_BUILTIN, HIGH);
8+
analogWrite(LED_BUILTIN, 255);
79
delay(1000);
8-
digitalWrite(LED_BUILTIN, LOW);
10+
analogWrite(LED_BUILTIN, 0);
911
delay(1000);
1012
}

bin/example.hex

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
6002 ; V[0] = 2 (LED_BUILTIN for ESP WROOM32)
22
E2A1 ; pinMode(V[0], 2); (OUTPUT for ESP WROOM32)
33

4-
6101 ; V[1] = 1
5-
E0A3 ; digitalWrite(5, 1);
4+
61FF ; V[1] = 255
5+
E0A3 ; analogWrite(2, 255);
66

77
62FA ; V[2] = 250
88
72FA ; V[2] += 250
@@ -11,7 +11,7 @@ E0A3 ; digitalWrite(5, 1);
1111
E0A0 ; delay(1000);
1212

1313
6100 ; V[1] = 0
14-
E0A3 ; digitalWrite(5, 0);
14+
E0A3 ; analogWrite(2, 0);
1515

1616
E0A0 ; delay(1000);
1717

opcodes.ino

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ along with evm-esp32. If not, see <http://www.gnu.org/licenses/>.
1616
1717
*/
1818
#include "include/opcodes.h"
19+
#include <analogWrite.h>
1920

2021
void parse_opcode(struct vm *VM, uint16_t opcode)
2122
{
@@ -44,7 +45,7 @@ void parse_opcode(struct vm *VM, uint16_t opcode)
4445
break;
4546
case 0xE0A3:
4647
/* Write to pin (first register) a value (second register) */
47-
digitalWrite(VM->registers.v[0], VM->registers.v[1]);
48+
analogWrite(VM->registers.v[0], VM->registers.v[1]);
4849
return;
4950
break;
5051
default:

0 commit comments

Comments
 (0)