Скачал код с гитхаба, но что то не пошло(CapasitiveSensor,Keyboard)
- Войдите на сайт для отправки комментариев
Чт, 14/11/2019 - 23:27
Скачал код (https://github.com/fb39ca4/kappa-pad)
Следовал инструкции, но кнопки z и x всегда нажаты
Не могу понять в чем проблем, помогите плз
#include <CapacitiveSensor.h> #include <Keyboard.h> #include "capacitiveKey.h" //#define SERIAL_OUTPUT #define DISABLE_PIN 15 void setup() { #ifdef SERIAL_OUTPUT Serial.begin(115200); #endif Keyboard.begin(); pinMode(DISABLE_PIN, INPUT_PULLUP); } CapacitiveKey key0 = CapacitiveKey( 2, //Capacitive Send Pin 7, //Capacitive Sense Pin 6, //LED Pin 6, //Capacitive Treshold 'z', //Keyboard Key 255 //LED Brightness (0-255) ); CapacitiveKey key1 = CapacitiveKey( 4, //Capacitive Send Pin 8, //Capacitive Sense Pin 10, //LED Pin 5, //Capacitive Treshold 'x', //Keyboard Key 255 //LED Brightness (0-255) ); void loop() { bool keyboardActive = digitalRead(DISABLE_PIN); key0.keyUpdate(keyboardActive); key1.keyUpdate(keyboardActive); #ifdef SERIAL_OUTPUT Serial.print(key0.sample); Serial.print(","); Serial.println(key1.sample); #endif }
class CapacitiveKey { public: CapacitiveSensor* sensor; bool keyReleased = true; char key; unsigned int releaseDelay = 20; unsigned int releaseTimer; unsigned int treshold; int led; unsigned int sample; unsigned char ledBrightness; CapacitiveKey(uint8_t sendPin, uint8_t receivePin, int statusLED, unsigned int capacitiveTreshold, char keyboardKey, unsigned char ledBrightness) { sensor = new CapacitiveSensor(sendPin, receivePin); treshold = capacitiveTreshold; key = keyboardKey; led = statusLED; pinMode(led, OUTPUT); } ~CapacitiveKey() { delete sensor; } void keyUpdate(bool keyboardActive) { sample = sensor->capacitiveSensorRaw(1); if (sample > treshold) { if (keyReleased) { analogWrite(led, 255); if (keyboardActive) Keyboard.press(key); keyReleased = false; } releaseTimer = releaseDelay; } else { if (!keyReleased) { if (releaseTimer == 0) { analogWrite(led, 0); Keyboard.release(key); keyReleased = true; } else { releaseTimer--; } } } } };
А что выводит в сериал?