Paso 2: Esplora código
/* Esplora Google Earth Flight Sim This sketch shows you how to read the values from the accelerometer to control your Mouse. Mouse is active/inactive on SWITCH_4 Press. Use with Google Earth Flight Sim Mode This example is in the public domain. */ #include <Esplora.h> int state = 1; int state_old = 1; int mode = 0; int xAxis, xAxis_old = 0; int yAxis, yAxis_old = 0; int zAxis, zAxis_old = 0; voidsetup() { } voidloop() { state_old=state; state = Esplora.readButton(SWITCH_4); if (state_old && !state) { mode = !mode; if (mode) { Mouse.begin(); // take control of the mouse Keyboard.begin(); Mouse.press(); // Click to use Mouse Control in Sim delay(100); Mouse.release(); } else { Mouse.end(); Keyboard.end(); } } // Throttle ++ if (!Esplora.readButton(SWITCH_3)) { Keyboard.press(KEY_PAGE_UP); delay(100); Keyboard.releaseAll(); } // Throttle -- if (!Esplora.readButton(SWITCH_1)) { Keyboard.press(KEY_PAGE_DOWN); delay(100); Keyboard.releaseAll(); } xAxis_old = xAxis; yAxis_old = yAxis; xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis int delta_x = xAxis-xAxis_old; int delta_y = yAxis-yAxis_old; if (mode) Mouse.move(-5*delta_x, 2*delta_y, 0 ); delay(10); // wait half a second (500 milliseconds) }