Created
September 23, 2021 08:38
-
-
Save t3mp-0xCC/f7cf0cba6c8dd61e71969d0a85009d91 to your computer and use it in GitHub Desktop.
discord_auto_mute.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <BleKeyboard.h> | |
BleKeyboard bleKeyboard; | |
const int TRIGGER = 2; | |
const int ECHO = 4; | |
bool mute_on = false; | |
bool mute_off = true; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(TRIGGER, OUTPUT); //Trig: output | |
pinMode(ECHO, INPUT); //Echo: input | |
bleKeyboard.begin(); | |
Serial.println("Setup Done !!"); | |
} | |
void loop() | |
{ | |
long duration, distance; | |
digitalWrite(TRIGGER, LOW); | |
delayMicroseconds(2); | |
digitalWrite(TRIGGER, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(TRIGGER, LOW); | |
//Echo | |
duration = pulseIn(ECHO, HIGH); //return : time (us) | |
distance = duration / 29 / 2; | |
Serial.print(distance); | |
Serial.print("cm"); | |
Serial.println(); | |
delay(100); | |
if(distance > 100 && bleKeyboard.isConnected() && mute_off){ | |
mute_on = true; | |
mute_off = false; | |
Serial.println("AFK"); | |
// send Ctrl + Shift + m | |
bleKeyboard.press(KEY_LEFT_CTRL); | |
bleKeyboard.press(KEY_LEFT_SHIFT); | |
bleKeyboard.print("m"); | |
delay(30); | |
bleKeyboard.releaseAll(); | |
} | |
if(distance <= 100 && bleKeyboard.isConnected() && mute_on){ | |
mute_on = false; | |
mute_off = true; | |
Serial.println("AFK"); | |
// send Ctrl + Shift + m | |
bleKeyboard.press(KEY_LEFT_CTRL); | |
bleKeyboard.press(KEY_LEFT_SHIFT); | |
bleKeyboard.print("m"); | |
delay(30); | |
bleKeyboard.releaseAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment