Now with added rickrolling. A program to mess with people. Intended for small boards with built in USB sockets that connect direct to the CPU and can easily be hidden behind a computer (e.g. the mBuino).

Dependencies:   USBDevice mbed

Pretends to be a USB mouse and keyboard and has some predefined functions for various things (do a google image search on a set keyword every 5 minutes, move the mouse in a circle, keep turning the capslock key on etc...)

The default is to rickroll the user. It turns caps lock on, when the user turns it off again the program will turns the volume up to max and load a youtube video of Rick Astley. For the next 45 seconds the mouse will do some circles to make it harder to stop the video. It will then wait 10 minutes and loop back to the start.

As google used to say: Don't be evil. But there is nothing wrong with being a little bit naughty.

Committer:
AndyA
Date:
Thu Dec 10 15:05:58 2015 +0000
Revision:
0:499d030c3e22
Child:
1:f2747e954f10
first version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndyA 0:499d030c3e22 1 #include "mbed.h"
AndyA 0:499d030c3e22 2 #include "USBMouseKeyboard.h"
AndyA 0:499d030c3e22 3
AndyA 0:499d030c3e22 4 // number of search terms
AndyA 0:499d030c3e22 5 const int searchCount = 6;
AndyA 0:499d030c3e22 6 // search terms. Should be url encoded (e.g. space becomes %20)
AndyA 0:499d030c3e22 7 const char *searches[] = {"hot%20cheese",
AndyA 0:499d030c3e22 8 "big%20show",
AndyA 0:499d030c3e22 9 "hot%20cheese",
AndyA 0:499d030c3e22 10 "magic%20mike%20xxl",
AndyA 0:499d030c3e22 11 "hot%20wet%20cheese",
AndyA 0:499d030c3e22 12 "hot%20wet%20-cheese"
AndyA 0:499d030c3e22 13 };
AndyA 0:499d030c3e22 14 // pause between searches in seconds
AndyA 0:499d030c3e22 15 const float delayBetweenSearches = 120;
AndyA 0:499d030c3e22 16
AndyA 0:499d030c3e22 17 // start of the search string
AndyA 0:499d030c3e22 18 const char searchPrefix[] = "https://www.google.co.uk/search?q=";
AndyA 0:499d030c3e22 19
AndyA 0:499d030c3e22 20 // end of the seach string (an image search with safe search switched off)
AndyA 0:499d030c3e22 21 const char searchSuffix[] = "&safe=off&tbm=isch";
AndyA 0:499d030c3e22 22
AndyA 0:499d030c3e22 23
AndyA 0:499d030c3e22 24 // turn off all LEDs (some boards they glow a bit if you don't).
AndyA 0:499d030c3e22 25 // you may need to remove some depending on the board.
AndyA 0:499d030c3e22 26 BusOut LEDs(LED1, LED2, LED3, LED4, LED5, LED6, LED7);
AndyA 0:499d030c3e22 27
AndyA 0:499d030c3e22 28 USBMouseKeyboard keyboard;
AndyA 0:499d030c3e22 29
AndyA 0:499d030c3e22 30 void sendString(const char *str)
AndyA 0:499d030c3e22 31 {
AndyA 0:499d030c3e22 32 while (*str != 0) {
AndyA 0:499d030c3e22 33 keyboard.putc(*str);
AndyA 0:499d030c3e22 34 str++;
AndyA 0:499d030c3e22 35 }
AndyA 0:499d030c3e22 36 }
AndyA 0:499d030c3e22 37
AndyA 0:499d030c3e22 38 void drawCircle(float radius, float time, bool dir=true)
AndyA 0:499d030c3e22 39 {
AndyA 0:499d030c3e22 40
AndyA 0:499d030c3e22 41 const float timeStep = 0.05;
AndyA 0:499d030c3e22 42 float currentx = 0;
AndyA 0:499d030c3e22 43 float currenty = radius;
AndyA 0:499d030c3e22 44 int steps = time/timeStep;
AndyA 0:499d030c3e22 45 float angleDelta = 2*3.14159265359 / steps;
AndyA 0:499d030c3e22 46 float xPos,yPos;
AndyA 0:499d030c3e22 47
AndyA 0:499d030c3e22 48 if (!dir)
AndyA 0:499d030c3e22 49 angleDelta = -angleDelta;
AndyA 0:499d030c3e22 50
AndyA 0:499d030c3e22 51
AndyA 0:499d030c3e22 52 for (int i = 0; i<steps; i++) {
AndyA 0:499d030c3e22 53 xPos = radius*sin(angleDelta*i);
AndyA 0:499d030c3e22 54 yPos = radius*cos(angleDelta*i);
AndyA 0:499d030c3e22 55 int xDelta = ((xPos - currentx) > 0)?(xPos - currentx) + 0.5 : (xPos - currentx) - 0.5 ;
AndyA 0:499d030c3e22 56 int yDelta = ((yPos - currenty) > 0)?(yPos - currenty) + 0.5 : (yPos - currenty) - 0.5 ;
AndyA 0:499d030c3e22 57 keyboard.move(xDelta,yDelta);
AndyA 0:499d030c3e22 58 currentx += xDelta;
AndyA 0:499d030c3e22 59 currenty += yDelta;
AndyA 0:499d030c3e22 60 wait(timeStep);
AndyA 0:499d030c3e22 61 }
AndyA 0:499d030c3e22 62 }
AndyA 0:499d030c3e22 63
AndyA 0:499d030c3e22 64
AndyA 0:499d030c3e22 65 void drawLine(float length, float time, bool horizontal=true, bool direction=true)
AndyA 0:499d030c3e22 66 {
AndyA 0:499d030c3e22 67
AndyA 0:499d030c3e22 68 const float timeStep = 0.05;
AndyA 0:499d030c3e22 69 float currentPos = 0;
AndyA 0:499d030c3e22 70 int steps = time/timeStep;
AndyA 0:499d030c3e22 71 float stepSize = length / steps;
AndyA 0:499d030c3e22 72 float movement;
AndyA 0:499d030c3e22 73
AndyA 0:499d030c3e22 74 if (!direction)
AndyA 0:499d030c3e22 75 stepSize = -stepSize;
AndyA 0:499d030c3e22 76
AndyA 0:499d030c3e22 77 for (int i = 0; i<steps; i++) {
AndyA 0:499d030c3e22 78
AndyA 0:499d030c3e22 79 movement = stepSize*i - currentPos;
AndyA 0:499d030c3e22 80 int moveDelta;
AndyA 0:499d030c3e22 81 if (movement>0)
AndyA 0:499d030c3e22 82 moveDelta = movement+0.5;
AndyA 0:499d030c3e22 83 else
AndyA 0:499d030c3e22 84 moveDelta = movement-0.5;
AndyA 0:499d030c3e22 85
AndyA 0:499d030c3e22 86 if (horizontal)
AndyA 0:499d030c3e22 87 keyboard.move(moveDelta,0);
AndyA 0:499d030c3e22 88 else
AndyA 0:499d030c3e22 89 keyboard.move(0,moveDelta);
AndyA 0:499d030c3e22 90
AndyA 0:499d030c3e22 91 currentPos += moveDelta;
AndyA 0:499d030c3e22 92 wait(timeStep);
AndyA 0:499d030c3e22 93 }
AndyA 0:499d030c3e22 94 }
AndyA 0:499d030c3e22 95
AndyA 0:499d030c3e22 96 void doNextSearch()
AndyA 0:499d030c3e22 97 {
AndyA 0:499d030c3e22 98 static int searchIndex = 0;
AndyA 0:499d030c3e22 99 keyboard.keyCode('r',KEY_LOGO); // windows key an R
AndyA 0:499d030c3e22 100 wait(0.1); // delay to give the run box a chance to come up.
AndyA 0:499d030c3e22 101 sendString(searchPrefix);
AndyA 0:499d030c3e22 102 sendString( searches[searchIndex++] );
AndyA 0:499d030c3e22 103 sendString(searchSuffix);
AndyA 0:499d030c3e22 104 wait(0.05); // delay to give the run box a chance to come up.
AndyA 0:499d030c3e22 105 keyboard.putc(0x0a); // hit enter
AndyA 0:499d030c3e22 106 if (searchIndex == searchCount)
AndyA 0:499d030c3e22 107 searchIndex = 0;
AndyA 0:499d030c3e22 108 }
AndyA 0:499d030c3e22 109
AndyA 0:499d030c3e22 110
AndyA 0:499d030c3e22 111 main()
AndyA 0:499d030c3e22 112 {
AndyA 0:499d030c3e22 113 LEDs = 0;
AndyA 0:499d030c3e22 114 wait(10);
AndyA 0:499d030c3e22 115 while (true) {
AndyA 0:499d030c3e22 116 doNextSearch();
AndyA 0:499d030c3e22 117
AndyA 0:499d030c3e22 118 drawCircle(45,delayBetweenSearches/12);
AndyA 0:499d030c3e22 119 drawCircle(45,delayBetweenSearches/12,false);
AndyA 0:499d030c3e22 120 wait(delayBetweenSearches/4);
AndyA 0:499d030c3e22 121 drawCircle(60,delayBetweenSearches/6,false);
AndyA 0:499d030c3e22 122 drawCircle(80,delayBetweenSearches/6);
AndyA 0:499d030c3e22 123 wait(delayBetweenSearches/4);
AndyA 0:499d030c3e22 124 }
AndyA 0:499d030c3e22 125 }