summaryrefslogtreecommitdiff
path: root/keyboards/handwired/onekey/keymaps/adc/keymap.c
blob: f9302a42b247544e8eb9178ab53a802b423df7a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include QMK_KEYBOARD_H
#include "analog.h"
#include <stdio.h>

enum custom_keycodes {
    ADC_SAMPLE = SAFE_RANGE,
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    LAYOUT_ortho_1x1(ADC_SAMPLE)
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case ADC_SAMPLE:
            if (record->event.pressed) {
                int16_t val = analogReadPin(ADC_PIN);

                char buffer[50];
                sprintf(buffer, "ADC:%u\n", val);
#ifdef CONSOLE_ENABLE
                    printf(buffer);
#else
                    send_string(buffer);
#endif
            }
            break;
    }
    return false;
};

// adc_mux pinToMux(pin_t pin) {
//     return TO_MUX(ADC_CHANNEL_IN1, 0);
// };