Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keyboard.h>
- int btnPins[] = {5,4,3,2,6};
- char btnKeys[] = {'y', 'r', 'a', 'n', 'q'};
- bool state;
- char ctrlKey = KEY_LEFT_GUI;
- void setup() {
- for (int i = 0; i < 5; i++) {
- pinMode(btnPins[i], INPUT_PULLUP);
- Keyboard.begin();
- }
- if (btnPins[4] == LOW) state = true;
- if (btnPins[4] == HIGH) state = false;
- }
- void loop(){
- for (int i = 0; i < 4; i++) {
- if (digitalRead(i) == LOW) {
- PressKey(btnKeys[i]);
- }
- }
- if ((digitalRead(btnPins[4]) == LOW && state == false) || (digitalRead(btnPins[4]) == HIGH && state == true)) {
- PressKey(btnKeys[4]);
- state = !state;
- }
- }
- void PressKey(char key) {
- Keyboard.press(key);
- delay(200);
- Keyboard.release(key);
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement