Devices & Components
Arduino Leonardo with Headers
DFRobot Gravity: Offline Language Learning Voice Recognition Sensor for micro:bit / Arduino / ESP32 - I2C & UART
Jumper wires (generic)
Software & Tools
Arduino IDE
Project description
Code
Arduino Code
cpp
1#include "DFRobot_DF2301Q.h" 2#include "Keyboard.h" 3DFRobot_DF2301Q_I2C DF2301Q; 4void setup() 5{ 6Serial.begin(115200); 7Keyboard.begin(); // Initialize Keyboard functionality 8while (!(DF2301Q.begin())) 9{ 10Serial.println("Communication with device failed, please check connection"); 11delay(3000); 12} 13Serial.println("Begin ok!"); 14DF2301Q.setVolume(6); 15DF2301Q.setMuteMode(0); 16DF2301Q.setWakeTime(15); 17Serial.print("WakeTime = "); 18Serial.println(DF2301Q.getWakeTime()); 19} 20void loop() 21{ 22uint8_t CMDID = DF2301Q.getCMDID(); 23if (CMDID != 0) 24{ 25Serial.print("CMDID = "); 26Serial.println(CMDID); 27switch (CMDID) 28{ 29case 5: 30Serial.println("Performing: Windows + M"); 31Keyboard.press(KEY_LEFT_GUI); // Windows key 32Keyboard.press('m'); 33delay(100); 34Keyboard.releaseAll(); 35break; 36case 6: 37Serial.println("Performing: Escape"); 38Keyboard.press(KEY_ESC); 39delay(100); 40Keyboard.releaseAll(); 41break; 42case 7: 43Serial.println("Performing: Windows + ["); 44Keyboard.press(KEY_LEFT_GUI); 45Keyboard.press('['); 46delay(100); 47Keyboard.releaseAll(); 48break; 49case 8: 50Serial.println("Performing: Windows + B"); 51Keyboard.press(KEY_LEFT_GUI); 52Keyboard.press('b'); 53delay(100); 54Keyboard.releaseAll(); 55break; 56case 9: 57Serial.println("Performing: Windows + N"); 58Keyboard.press(KEY_LEFT_GUI); 59Keyboard.press('n'); 60delay(100); 61Keyboard.releaseAll(); 62break; 63default: 64Serial.println("Unknown CMDID"); 65break; 66} 67} 68delay(300); 69}
Comments
Only logged in users can leave comments