GHI Electronics
/
Official_USBPrank
The preloaded firmware shipped on the USB Prank.
Diff: main.cpp
- Revision:
- 0:01e3d602e31f
- Child:
- 1:2449ac218b24
diff -r 000000000000 -r 01e3d602e31f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Sep 13 03:28:16 2014 +0000 @@ -0,0 +1,81 @@ +#include "mbed.h" +#include "USBMouse.h" +#include <stdlib.h> +#include <math.h> + +#define DELAY_TO_NEXT_RADIUS (rand() % 5 + 1) +#define DELAY_TO_RESTART (rand() % 30 + 1) + +USBMouse mouse; + +main() +{ + static const float DELAY_TO_START = 25.0; + float DELAY_TO_NEXT_POINT = 0.001; + static const int16_t RADIUS_INC = 2; + static const int16_t ANGLE_INC = 2; + static const int8_t NUM_CIRCLE_SIZES = 4; + + int16_t x = 0; + int16_t y = 0; + int16_t angle = 0; + int16_t radius = 5; // if radius is too large, OS dependent, Windows 8 it isn't visible + int16_t recenter_radius_correction = 0; + + + int8_t circle_count; + + int nextPointFrequency; + + // Start-up Code + for (circle_count = 1; circle_count <= 5; circle_count++) + { + while (angle <= 360) + { + x = cos((double)angle*3.14/180.0)*5; + y = sin((double)angle*3.14/180.0)*5; + mouse.move(x, y); + angle += ANGLE_INC; + wait(.001); + } // draw circle + + wait(.25); + x = y = angle = 0; + } // end circle_count + + wait(DELAY_TO_START); + + while (true) + { + for (circle_count = 1; circle_count <= NUM_CIRCLE_SIZES; circle_count++) + { + while (angle <= 360) + { + x = cos((double)angle*3.14/180.0)*radius; + y = sin((double)angle*3.14/180.0)*radius; + mouse.move(x, y); + recenter_radius_correction -= x; + angle += ANGLE_INC; + wait(DELAY_TO_NEXT_POINT); + } // draw circle + + nextPointFrequency = rand() % 1000 + 1; + + if(nextPointFrequency < 100) + nextPointFrequency = 100; + + DELAY_TO_NEXT_POINT = 1/(float)nextPointFrequency; + + wait(DELAY_TO_NEXT_RADIUS); + x = y = angle = 0; + radius += RADIUS_INC; + // FIX: Change ANGLE_INCREMENT and DELAY_TO_NEXT_POINT so circle drawn relative resolution and time + mouse.move(recenter_radius_correction,0); + recenter_radius_correction = 0; + } // end circle_count + + radius = 5; + + wait(DELAY_TO_RESTART); + } +} \ No newline at end of file