![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Mynput: Game controller for Color Quest.
Dependencies: Adafruit_NeoPixel MMA8451Q PinDetect_KL25Z USBDevice mbed
Fork of idd_fa15_hw3_lauren_bill_tomas by
Diff: main.cpp
- Revision:
- 5:f547509e5583
- Parent:
- 4:0527cd963c14
- Child:
- 6:d5420bcf9ebe
--- a/main.cpp Sat Sep 19 01:11:12 2015 +0000 +++ b/main.cpp Sun Sep 20 00:47:40 2015 +0000 @@ -14,6 +14,8 @@ #define WRIST_LED_COUNT 16 #define CHEST_LED_COUNT 24 #define MMA8451_I2C_ADDRESS (0x1d<<1) +#define COUNTER_MOD 10 +#define X_MOVEMENT_REPEATS 15 #define LEAN_LEFT_THRESH -0.4 #define LEAN_RIGHT_THRESH 0.4 @@ -42,6 +44,7 @@ AnalogIn wrist(A2); PinDetect on_off(D15); bool on = false; +int counter = 0; void on_off_pressed() { @@ -79,9 +82,10 @@ */ void pulse(char color, PololuLedStrip led, int led_count) { + if (counter != 0) { return; }; rgb_color colors[led_count]; // Update the colors array. - for( int j = 0; j < 255; j++) { + for( int j = 0; j < 255; j+=10) { for( uint32_t i = 0; i < led_count; i++ ) { colors[i] = getColor(color, j); } @@ -114,12 +118,15 @@ if ( x > LEAN_RIGHT_THRESH ) { pc.printf("Lean right\n"); - keyboard.putc(RIGHT); + for (int i = 0; i < X_MOVEMENT_REPEATS; i++) { + keyboard.putc(RIGHT); + } } else if (x < LEAN_LEFT_THRESH) { pc.printf("Lean left\n"); - keyboard.putc(LEFT); + for (int i = 0; i < X_MOVEMENT_REPEATS; i++) { + keyboard.putc(LEFT); + } } - if( y < JUMP_THRESH && timer.read_ms() - timer_begin > 300 ) { timer_begin = timer.read_ms(); pc.printf("Jump\n"); @@ -147,6 +154,7 @@ pulse('w', wristLedStrip, WRIST_LED_COUNT); pulse('w', chestLedStrip, CHEST_LED_COUNT); } + counter = (counter + 1)%COUNTER_MOD; } } } \ No newline at end of file