FlufferBuffer

Activate google home with a button

Sep 18th, 2020 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Emulate Keyboard with an Arduino Micro
  3. 1 button project connected to pin12, button activates a couple of strings and keypresses on a mac
  4. A way to complicated way to play music on Google home by [email protected]
  5. */
  6.  
  7. #include <HID.h>                          
  8. #include <Keyboard.h>
  9.  
  10. const int RedButtonPin = 12;
  11. String varPassword = ("secret");  
  12. String varSpotlight = ("Terminal");    
  13. String varSay1 = ("say ok Google");
  14. String varSay2 = ("say maximal volym"); // Swedish voice command
  15. String varSay3 = ("say spela musik"); // Another swedish voice command (play music)
  16. long counter = 1;
  17.  
  18.  
  19. void setup() {
  20.   pinMode(RedButtonPin, INPUT_PULLUP);
  21.   Keyboard.begin();
  22. }
  23.  
  24. void loop() {
  25.  
  26.   int RedButton = digitalRead(RedButtonPin);
  27.  
  28.     if (RedButton == LOW){
  29. //Wake up computer from sleep
  30.       Keyboard.press(KEY_RETURN);
  31.       Keyboard.releaseAll();
  32.       delay(2000);
  33. //Type in password
  34.       Keyboard.print(varPassword);
  35.       delay(200);
  36.       Keyboard.press(KEY_RETURN);
  37.       Keyboard.releaseAll();
  38.       delay(3000);
  39. //Press left cmd and space to activate Spotlight
  40.       Keyboard.press(KEY_LEFT_GUI);
  41.       Keyboard.print(" ");
  42.       Keyboard.releaseAll();
  43.       delay(1300);
  44. //Enter searchstring into spotlight
  45.       Keyboard.print(varSpotlight);
  46.       delay(1300);
  47.       Keyboard.press(KEY_RETURN);
  48.       Keyboard.releaseAll();
  49.       delay(1000);
  50. //let terminal use speech to active google home
  51.       Keyboard.print(varSay1);
  52.       Keyboard.press(KEY_RETURN);
  53.       Keyboard.releaseAll();
  54.       delay(1500);
  55.       Keyboard.print(varSay2);
  56.       Keyboard.press(KEY_RETURN);
  57.       Keyboard.releaseAll();
  58.       delay(5000);
  59. //Activate second batch of voicecommands
  60.       Keyboard.print(varSay1);
  61.       Keyboard.press(KEY_RETURN);
  62.       Keyboard.releaseAll();
  63.       delay(1300);
  64.       Keyboard.print(varSay3);
  65.       Keyboard.press(KEY_RETURN);
  66.       Keyboard.releaseAll();
  67.       delay(1000);
  68. //Exit terminal,
  69.       Keyboard.print("exit");
  70.       Keyboard.press(KEY_RETURN);
  71.       Keyboard.releaseAll();
  72.       delay(1000);
  73. //Close terminal
  74.       Keyboard.press(KEY_LEFT_GUI);
  75.       Keyboard.print("q");
  76.       Keyboard.releaseAll();
  77.       delay(1000);
  78. //Logout
  79.       Keyboard.press(KEY_LEFT_GUI);
  80.       Keyboard.press(KEY_LEFT_CTRL);
  81.       Keyboard.print("q");
  82.       Keyboard.releaseAll();
  83.       delay(200);
  84.      
  85.      
  86.     }
  87.        
  88.  
  89. }      
  90.  
Add Comment
Please, Sign In to add comment