Glove with light ring which plays http://www.raiden-x.net/

Dependencies:   Adafruit_NeoPixel MMA8451Q USBDevice mbed

Fork of Raiden by Christian Le

Committer:
christianle
Date:
Mon Sep 21 02:15:17 2015 +0000
Revision:
9:07e3e2f6d6a9
Parent:
8:de23747efc37
Child:
10:ca3a7890d146
Init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 2:41db78380a6e 1 #include "mbed.h"
chris 2:41db78380a6e 2 #include "MMA8451Q.h"
christianle 9:07e3e2f6d6a9 3 //#include "USBKeyboard.h"
christianle 9:07e3e2f6d6a9 4 //#include "USBHID.h"
christianle 9:07e3e2f6d6a9 5
chris 2:41db78380a6e 6
chris 2:41db78380a6e 7 #define MMA8451_I2C_ADDRESS (0x1d<<1)
christianle 8:de23747efc37 8 #define THRESHOLD 0.1
christianle 8:de23747efc37 9
christianle 9:07e3e2f6d6a9 10 #define LED_COUNT 24
christianle 9:07e3e2f6d6a9 11 #define DATA_PIN D6
christianle 9:07e3e2f6d6a9 12
christianle 8:de23747efc37 13 typedef struct {
christianle 8:de23747efc37 14 unsigned char usage;
christianle 8:de23747efc37 15 unsigned char modifier;
christianle 8:de23747efc37 16 } KEYMAP;
christianle 8:de23747efc37 17
christianle 9:07e3e2f6d6a9 18 uint8_t r = 255;
christianle 9:07e3e2f6d6a9 19 uint8_t g = 255;
christianle 9:07e3e2f6d6a9 20 uint8_t b = 255;
christianle 8:de23747efc37 21
christianle 9:07e3e2f6d6a9 22 //#define KEYMAP_SIZE (152)
christianle 9:07e3e2f6d6a9 23 //const KEYMAP keymap[KEYMAP_SIZE] = {
christianle 9:07e3e2f6d6a9 24 // {0, 0}, /* NUL */
christianle 9:07e3e2f6d6a9 25 // {0, 0}, /* SOH */
christianle 9:07e3e2f6d6a9 26 // {0, 0}, /* STX */
christianle 9:07e3e2f6d6a9 27 // {0, 0}, /* ETX */
christianle 9:07e3e2f6d6a9 28 // {0, 0}, /* EOT */
christianle 9:07e3e2f6d6a9 29 // {0, 0}, /* ENQ */
christianle 9:07e3e2f6d6a9 30 // {0, 0}, /* ACK */
christianle 9:07e3e2f6d6a9 31 // {0, 0}, /* BEL */
christianle 9:07e3e2f6d6a9 32 // {0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */
christianle 9:07e3e2f6d6a9 33 // {0x2b, 0}, /* TAB */ /* Keyboard Tab */
christianle 9:07e3e2f6d6a9 34 // {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
christianle 9:07e3e2f6d6a9 35 // {0, 0}, /* VT */
christianle 9:07e3e2f6d6a9 36 // {0, 0}, /* FF */
christianle 9:07e3e2f6d6a9 37 // {0, 0}, /* CR */
christianle 9:07e3e2f6d6a9 38 // {0, 0}, /* SO */
christianle 9:07e3e2f6d6a9 39 // {0, 0}, /* SI */
christianle 9:07e3e2f6d6a9 40 // {0, 0}, /* DEL */
christianle 9:07e3e2f6d6a9 41 // {0, 0}, /* DC1 */
christianle 9:07e3e2f6d6a9 42 // {0, 0}, /* DC2 */
christianle 9:07e3e2f6d6a9 43 // {0, 0}, /* DC3 */
christianle 9:07e3e2f6d6a9 44 // {0, 0}, /* DC4 */
christianle 9:07e3e2f6d6a9 45 // {0, 0}, /* NAK */
christianle 9:07e3e2f6d6a9 46 // {0, 0}, /* SYN */
christianle 9:07e3e2f6d6a9 47 // {0, 0}, /* ETB */
christianle 9:07e3e2f6d6a9 48 // {0, 0}, /* CAN */
christianle 9:07e3e2f6d6a9 49 // {0, 0}, /* EM */
christianle 9:07e3e2f6d6a9 50 // {0, 0}, /* SUB */
christianle 9:07e3e2f6d6a9 51 // {0, 0}, /* ESC */
christianle 9:07e3e2f6d6a9 52 // {0, 0}, /* FS */
christianle 9:07e3e2f6d6a9 53 // {0, 0}, /* GS */
christianle 9:07e3e2f6d6a9 54 // {0, 0}, /* RS */
christianle 9:07e3e2f6d6a9 55 // {0, 0}, /* US */
christianle 9:07e3e2f6d6a9 56 // {0x2c, 0}, /* */
christianle 9:07e3e2f6d6a9 57 // {0x1e, KEY_SHIFT}, /* ! */
christianle 9:07e3e2f6d6a9 58 // {0x34, KEY_SHIFT}, /* " */
christianle 9:07e3e2f6d6a9 59 // {0x20, KEY_SHIFT}, /* # */
christianle 9:07e3e2f6d6a9 60 // {0x21, KEY_SHIFT}, /* $ */
christianle 9:07e3e2f6d6a9 61 // {0x22, KEY_SHIFT}, /* % */
christianle 9:07e3e2f6d6a9 62 // {0x24, KEY_SHIFT}, /* & */
christianle 9:07e3e2f6d6a9 63 // {0x34, 0}, /* ' */
christianle 9:07e3e2f6d6a9 64 // {0x26, KEY_SHIFT}, /* ( */
christianle 9:07e3e2f6d6a9 65 // {0x27, KEY_SHIFT}, /* ) */
christianle 9:07e3e2f6d6a9 66 // {0x25, KEY_SHIFT}, /* * */
christianle 9:07e3e2f6d6a9 67 // {0x2e, KEY_SHIFT}, /* + */
christianle 9:07e3e2f6d6a9 68 // {0x36, 0}, /* , */
christianle 9:07e3e2f6d6a9 69 // {0x2d, 0}, /* - */
christianle 9:07e3e2f6d6a9 70 // {0x37, 0}, /* . */
christianle 9:07e3e2f6d6a9 71 // {0x38, 0}, /* / */
christianle 9:07e3e2f6d6a9 72 // {0x27, 0}, /* 0 */
christianle 9:07e3e2f6d6a9 73 // {0x1e, 0}, /* 1 */
christianle 9:07e3e2f6d6a9 74 // {0x1f, 0}, /* 2 */
christianle 9:07e3e2f6d6a9 75 // {0x20, 0}, /* 3 */
christianle 9:07e3e2f6d6a9 76 // {0x21, 0}, /* 4 */
christianle 9:07e3e2f6d6a9 77 // {0x22, 0}, /* 5 */
christianle 9:07e3e2f6d6a9 78 // {0x23, 0}, /* 6 */
christianle 9:07e3e2f6d6a9 79 // {0x24, 0}, /* 7 */
christianle 9:07e3e2f6d6a9 80 // {0x25, 0}, /* 8 */
christianle 9:07e3e2f6d6a9 81 // {0x26, 0}, /* 9 */
christianle 9:07e3e2f6d6a9 82 // {0x33, KEY_SHIFT}, /* : */
christianle 9:07e3e2f6d6a9 83 // {0x33, 0}, /* ; */
christianle 9:07e3e2f6d6a9 84 // {0x36, KEY_SHIFT}, /* < */
christianle 9:07e3e2f6d6a9 85 // {0x2e, 0}, /* = */
christianle 9:07e3e2f6d6a9 86 // {0x37, KEY_SHIFT}, /* > */
christianle 9:07e3e2f6d6a9 87 // {0x38, KEY_SHIFT}, /* ? */
christianle 9:07e3e2f6d6a9 88 // {0x1f, KEY_SHIFT}, /* @ */
christianle 9:07e3e2f6d6a9 89 // {0x04, KEY_SHIFT}, /* A */
christianle 9:07e3e2f6d6a9 90 // {0x05, KEY_SHIFT}, /* B */
christianle 9:07e3e2f6d6a9 91 // {0x06, KEY_SHIFT}, /* C */
christianle 9:07e3e2f6d6a9 92 // {0x07, KEY_SHIFT}, /* D */
christianle 9:07e3e2f6d6a9 93 // {0x08, KEY_SHIFT}, /* E */
christianle 9:07e3e2f6d6a9 94 // {0x09, KEY_SHIFT}, /* F */
christianle 9:07e3e2f6d6a9 95 // {0x0a, KEY_SHIFT}, /* G */
christianle 9:07e3e2f6d6a9 96 // {0x0b, KEY_SHIFT}, /* H */
christianle 9:07e3e2f6d6a9 97 // {0x0c, KEY_SHIFT}, /* I */
christianle 9:07e3e2f6d6a9 98 // {0x0d, KEY_SHIFT}, /* J */
christianle 9:07e3e2f6d6a9 99 // {0x0e, KEY_SHIFT}, /* K */
christianle 9:07e3e2f6d6a9 100 // {0x0f, KEY_SHIFT}, /* L */
christianle 9:07e3e2f6d6a9 101 // {0x10, KEY_SHIFT}, /* M */
christianle 9:07e3e2f6d6a9 102 // {0x11, KEY_SHIFT}, /* N */
christianle 9:07e3e2f6d6a9 103 // {0x12, KEY_SHIFT}, /* O */
christianle 9:07e3e2f6d6a9 104 // {0x13, KEY_SHIFT}, /* P */
christianle 9:07e3e2f6d6a9 105 // {0x14, KEY_SHIFT}, /* Q */
christianle 9:07e3e2f6d6a9 106 // {0x15, KEY_SHIFT}, /* R */
christianle 9:07e3e2f6d6a9 107 // {0x16, KEY_SHIFT}, /* S */
christianle 9:07e3e2f6d6a9 108 // {0x17, KEY_SHIFT}, /* T */
christianle 9:07e3e2f6d6a9 109 // {0x18, KEY_SHIFT}, /* U */
christianle 9:07e3e2f6d6a9 110 // {0x19, KEY_SHIFT}, /* V */
christianle 9:07e3e2f6d6a9 111 // {0x1a, KEY_SHIFT}, /* W */
christianle 9:07e3e2f6d6a9 112 // {0x1b, KEY_SHIFT}, /* X */
christianle 9:07e3e2f6d6a9 113 // {0x1c, KEY_SHIFT}, /* Y */
christianle 9:07e3e2f6d6a9 114 // {0x1d, KEY_SHIFT}, /* Z */
christianle 9:07e3e2f6d6a9 115 // {0x2f, 0}, /* [ */
christianle 9:07e3e2f6d6a9 116 // {0x31, 0}, /* \ */
christianle 9:07e3e2f6d6a9 117 // {0x30, 0}, /* ] */
christianle 9:07e3e2f6d6a9 118 // {0x23, KEY_SHIFT}, /* ^ */
christianle 9:07e3e2f6d6a9 119 // {0x2d, KEY_SHIFT}, /* _ */
christianle 9:07e3e2f6d6a9 120 // {0x35, 0}, /* ` */
christianle 9:07e3e2f6d6a9 121 // {0x04, 0}, /* a */
christianle 9:07e3e2f6d6a9 122 // {0x05, 0}, /* b */
christianle 9:07e3e2f6d6a9 123 // {0x06, 0}, /* c */
christianle 9:07e3e2f6d6a9 124 // {0x07, 0}, /* d */
christianle 9:07e3e2f6d6a9 125 // {0x08, 0}, /* e */
christianle 9:07e3e2f6d6a9 126 // {0x09, 0}, /* f */
christianle 9:07e3e2f6d6a9 127 // {0x0a, 0}, /* g */
christianle 9:07e3e2f6d6a9 128 // {0x0b, 0}, /* h */
christianle 9:07e3e2f6d6a9 129 // {0x0c, 0}, /* i */
christianle 9:07e3e2f6d6a9 130 // {0x0d, 0}, /* j */
christianle 9:07e3e2f6d6a9 131 // {0x0e, 0}, /* k */
christianle 9:07e3e2f6d6a9 132 // {0x0f, 0}, /* l */
christianle 9:07e3e2f6d6a9 133 // {0x10, 0}, /* m */
christianle 9:07e3e2f6d6a9 134 // {0x11, 0}, /* n */
christianle 9:07e3e2f6d6a9 135 // {0x12, 0}, /* o */
christianle 9:07e3e2f6d6a9 136 // {0x13, 0}, /* p */
christianle 9:07e3e2f6d6a9 137 // {0x14, 0}, /* q */
christianle 9:07e3e2f6d6a9 138 // {0x15, 0}, /* r */
christianle 9:07e3e2f6d6a9 139 // {0x16, 0}, /* s */
christianle 9:07e3e2f6d6a9 140 // {0x17, 0}, /* t */
christianle 9:07e3e2f6d6a9 141 // {0x18, 0}, /* u */
christianle 9:07e3e2f6d6a9 142 // {0x19, 0}, /* v */
christianle 9:07e3e2f6d6a9 143 // {0x1a, 0}, /* w */
christianle 9:07e3e2f6d6a9 144 // {0x1b, 0}, /* x */
christianle 9:07e3e2f6d6a9 145 // {0x1c, 0}, /* y */
christianle 9:07e3e2f6d6a9 146 // {0x1d, 0}, /* z */
christianle 9:07e3e2f6d6a9 147 // {0x2f, KEY_SHIFT}, /* { */
christianle 9:07e3e2f6d6a9 148 // {0x31, KEY_SHIFT}, /* | */
christianle 9:07e3e2f6d6a9 149 // {0x30, KEY_SHIFT}, /* } */
christianle 9:07e3e2f6d6a9 150 // {0x35, KEY_SHIFT}, /* ~ */
christianle 9:07e3e2f6d6a9 151 // {0,0}, /* DEL */
christianle 9:07e3e2f6d6a9 152 //
christianle 9:07e3e2f6d6a9 153 // {0x3a, 0}, /* F1 */
christianle 9:07e3e2f6d6a9 154 // {0x3b, 0}, /* F2 */
christianle 9:07e3e2f6d6a9 155 // {0x3c, 0}, /* F3 */
christianle 9:07e3e2f6d6a9 156 // {0x3d, 0}, /* F4 */
christianle 9:07e3e2f6d6a9 157 // {0x3e, 0}, /* F5 */
christianle 9:07e3e2f6d6a9 158 // {0x3f, 0}, /* F6 */
christianle 9:07e3e2f6d6a9 159 // {0x40, 0}, /* F7 */
christianle 9:07e3e2f6d6a9 160 // {0x41, 0}, /* F8 */
christianle 9:07e3e2f6d6a9 161 // {0x42, 0}, /* F9 */
christianle 9:07e3e2f6d6a9 162 // {0x43, 0}, /* F10 */
christianle 9:07e3e2f6d6a9 163 // {0x44, 0}, /* F11 */
christianle 9:07e3e2f6d6a9 164 // {0x45, 0}, /* F12 */
christianle 9:07e3e2f6d6a9 165 //
christianle 9:07e3e2f6d6a9 166 // {0x46, 0}, /* PRINT_SCREEN */
christianle 9:07e3e2f6d6a9 167 // {0x47, 0}, /* SCROLL_LOCK */
christianle 9:07e3e2f6d6a9 168 // {0x39, 0}, /* CAPS_LOCK */
christianle 9:07e3e2f6d6a9 169 // {0x53, 0}, /* NUM_LOCK */
christianle 9:07e3e2f6d6a9 170 // {0x49, 0}, /* INSERT */
christianle 9:07e3e2f6d6a9 171 // {0x4a, 0}, /* HOME */
christianle 9:07e3e2f6d6a9 172 // {0x4b, 0}, /* PAGE_UP */
christianle 9:07e3e2f6d6a9 173 // {0x4e, 0}, /* PAGE_DOWN */
christianle 9:07e3e2f6d6a9 174 //
christianle 9:07e3e2f6d6a9 175 // {0x4f, 0}, /* RIGHT_ARROW */
christianle 9:07e3e2f6d6a9 176 // {0x50, 0}, /* LEFT_ARROW */
christianle 9:07e3e2f6d6a9 177 // {0x51, 0}, /* DOWN_ARROW */
christianle 9:07e3e2f6d6a9 178 // {0x52, 0}, /* UP_ARROW */
christianle 9:07e3e2f6d6a9 179 //};
chris 2:41db78380a6e 180
chris 4:367de1084ea9 181 int main(void) {
christianle 9:07e3e2f6d6a9 182 Serial mac(USBTX, USBRX);
christianle 9:07e3e2f6d6a9 183
emilmont 5:bf5becf7469c 184 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
emilmont 5:bf5becf7469c 185 PwmOut rled(LED_RED);
emilmont 5:bf5becf7469c 186 PwmOut bled(LED_BLUE);
christianle 8:de23747efc37 187
christianle 9:07e3e2f6d6a9 188 // USBKeyboard keyboard;
christianle 9:07e3e2f6d6a9 189 // HID_REPORT report;
christianle 8:de23747efc37 190
christianle 9:07e3e2f6d6a9 191 AnalogIn flex(A0);
christianle 8:de23747efc37 192
christianle 9:07e3e2f6d6a9 193 // report.data[0] = 1; // this is the USB ID
christianle 9:07e3e2f6d6a9 194 // report.data[1] = 0; // this is a modifier key (ie: ctrl/shift/alt)
christianle 9:07e3e2f6d6a9 195 // report.data[2] = 0; // i haven't figured this one out
christianle 9:07e3e2f6d6a9 196 // report.data[3] = 0; // UP
christianle 9:07e3e2f6d6a9 197 // report.data[4] = 0; // DOWN
christianle 9:07e3e2f6d6a9 198 // report.data[5] = 0; // LEFT
christianle 9:07e3e2f6d6a9 199 // report.data[6] = 0; // RIGHT
christianle 9:07e3e2f6d6a9 200 // report.data[7] = keymap['z'].usage; // SHOOT
christianle 9:07e3e2f6d6a9 201 // report.data[8] = 0; // BOMB
christianle 9:07e3e2f6d6a9 202 // report.length = 9;
chris 4:367de1084ea9 203
emilmont 5:bf5becf7469c 204 while (true) {
christianle 9:07e3e2f6d6a9 205 mac.printf("%f", flex.read());
christianle 9:07e3e2f6d6a9 206
christianle 8:de23747efc37 207 float x = acc.getAccX();
christianle 8:de23747efc37 208 float y = acc.getAccY();
christianle 8:de23747efc37 209
christianle 8:de23747efc37 210 if (x < 0 - THRESHOLD) {
christianle 8:de23747efc37 211 mac.printf("Left\r\n");
christianle 9:07e3e2f6d6a9 212 // report.data[6] = 0;
christianle 9:07e3e2f6d6a9 213 // report.data[5] = keymap[LEFT_ARROW].usage;
christianle 8:de23747efc37 214 }
christianle 8:de23747efc37 215
christianle 8:de23747efc37 216 if (x > 0 + THRESHOLD) {
christianle 8:de23747efc37 217 mac.printf("Right\r\n");
christianle 9:07e3e2f6d6a9 218 // report.data[6] = keymap[RIGHT_ARROW].usage;
christianle 9:07e3e2f6d6a9 219 // report.data[5] = 0;
christianle 8:de23747efc37 220 }
christianle 8:de23747efc37 221
christianle 8:de23747efc37 222 if (y < 0 - THRESHOLD) {
christianle 8:de23747efc37 223 mac.printf("Up\r\n");
christianle 9:07e3e2f6d6a9 224 // report.data[3] = keymap[UP_ARROW].usage;
christianle 9:07e3e2f6d6a9 225 // report.data[4] = 0;
christianle 8:de23747efc37 226 }
christianle 8:de23747efc37 227
christianle 8:de23747efc37 228 if (y > 0 + THRESHOLD) {
christianle 8:de23747efc37 229 mac.printf("Down\r\n");
christianle 9:07e3e2f6d6a9 230 // report.data[3] = 0;
christianle 9:07e3e2f6d6a9 231 // report.data[4] = keymap[DOWN_ARROW].usage;
christianle 8:de23747efc37 232 }
christianle 8:de23747efc37 233
chris 3:f2d3e041d8f2 234 rled = 1.0 - abs(acc.getAccX());
christianle 8:de23747efc37 235 bled = 1.0 - abs(acc.getAccY());
christianle 8:de23747efc37 236
christianle 9:07e3e2f6d6a9 237 // keyboard.send(&report);
christianle 9:07e3e2f6d6a9 238 wait(0.5);
chris 2:41db78380a6e 239 }
chris 2:41db78380a6e 240 }