This commit is contained in:
2023-12-13 05:49:13 -05:00
parent b5ce8f72e4
commit 762bf28c93
3 changed files with 56 additions and 5 deletions
+3
View File
@@ -12,3 +12,6 @@
platform = espressif32
board = lolin_s2_mini
framework = arduino
build_flags =
-D ARDUINO_USB_MODE=0
-D ARDUINO_USB_CDC_ON_BOOT=1
+38 -5
View File
@@ -1,8 +1,41 @@
#include <Arduino.h>
void setup() {
// put your setup code here, to run once:
#include <USBHIDKeyboard.h>
#include "sweets.h"
#define KEY_COUNT 5
USBHIDKeyboard keyboard;
constexpr u8 keys[] = {'1', '2', '3', 'a', 'b'};
constexpr u8 pins[] = {GPIO_NUM_3, GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_6, GPIO_NUM_7};
bool keyStates[KEY_COUNT] = {false};
val led_pin = GPIO_NUM_15;
void setup()
{
// Set up the GPIO pins
for (val pin : pins) pinMode(pin, INPUT_PULLUP);
pinMode(led_pin, OUTPUT);
// Set up the USB keyboard
keyboard.begin();
Serial.begin();
}
void loop() {
// write your code here
}
void loop()
{
// Check for key presses
for (var i = 0; i < KEY_COUNT; i++)
{
val state = !digitalRead(pins[i]);
if (state != keyStates[i])
{
if (state) keyboard.press(keys[i]);
else keyboard.release(keys[i]);
digitalWrite(led_pin, state);
keyStates[i] = state;
}
}
}
+15
View File
@@ -0,0 +1,15 @@
//
// Created by Azalea on 12/12/23.
//
#ifndef SWEETS_H
#define SWEETS_H
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define val const auto
#define var auto
#endif //SWEETS_H