FRDM-KL25Z with Nokia 3110 type LCD display Using accelerometer to make movements

Dependencies:   MMA8451Q N3310LCD mbed

Fork of FRDM_MMA8451Q by mbed official

Committer:
SomeRandomBloke
Date:
Fri Mar 15 22:48:58 2013 +0000
Revision:
8:857444086b3f
Parent:
5:bf5becf7469c
Child:
9:1afbf9010118
first commit;

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"
SomeRandomBloke 8:857444086b3f 3 #include "N3310SPIConfig.h"
SomeRandomBloke 8:857444086b3f 4 #include "N3310LCD.h"
SomeRandomBloke 8:857444086b3f 5 #include "Joystick.h"
SomeRandomBloke 8:857444086b3f 6 #include "splash.h"
chris 2:41db78380a6e 7
chris 2:41db78380a6e 8 #define MMA8451_I2C_ADDRESS (0x1d<<1)
SomeRandomBloke 8:857444086b3f 9 Serial pc(USBTX,USBRX);
chris 2:41db78380a6e 10
SomeRandomBloke 8:857444086b3f 11 #define MIN(a,b) (((a)<(b))?(a):(b))
SomeRandomBloke 8:857444086b3f 12 #define MAX(a,b) (((a)>(b))?(a):(b))
SomeRandomBloke 8:857444086b3f 13
SomeRandomBloke 8:857444086b3f 14 // menu starting points
SomeRandomBloke 8:857444086b3f 15 #define MENU_X 10 // 0-83
SomeRandomBloke 8:857444086b3f 16 #define MENU_Y 0 // 0-5
SomeRandomBloke 8:857444086b3f 17
SomeRandomBloke 8:857444086b3f 18 #define MENU_ITEMS 3
SomeRandomBloke 8:857444086b3f 19
SomeRandomBloke 8:857444086b3f 20 int8_t blflag = 1; // Backlight initially ON
SomeRandomBloke 8:857444086b3f 21
SomeRandomBloke 8:857444086b3f 22
SomeRandomBloke 8:857444086b3f 23 void about(N3310LCD* lcd, Joystick* jstick);
SomeRandomBloke 8:857444086b3f 24 void draw(N3310LCD* lcd, Joystick* jstick);
SomeRandomBloke 8:857444086b3f 25 void backlight(N3310LCD* lcd, Joystick* jstick);
SomeRandomBloke 8:857444086b3f 26 void waitforOKKey(N3310LCD* lcd, Joystick* jstick);
SomeRandomBloke 8:857444086b3f 27 uint8_t checkKeypressed( Joystick* jstick);
SomeRandomBloke 8:857444086b3f 28
SomeRandomBloke 8:857444086b3f 29 // menu definition
SomeRandomBloke 8:857444086b3f 30 char menu_items[MENU_ITEMS][12] = {
SomeRandomBloke 8:857444086b3f 31 "SKETCH",
SomeRandomBloke 8:857444086b3f 32 "BACKLIGHT",
SomeRandomBloke 8:857444086b3f 33 "ABOUT"
SomeRandomBloke 8:857444086b3f 34 };
SomeRandomBloke 8:857444086b3f 35
SomeRandomBloke 8:857444086b3f 36 void (*menu_funcs[MENU_ITEMS])(N3310LCD*,Joystick*) = {
SomeRandomBloke 8:857444086b3f 37 draw,
SomeRandomBloke 8:857444086b3f 38 backlight,
SomeRandomBloke 8:857444086b3f 39 about
SomeRandomBloke 8:857444086b3f 40 };
SomeRandomBloke 8:857444086b3f 41
SomeRandomBloke 8:857444086b3f 42
SomeRandomBloke 8:857444086b3f 43 void about(N3310LCD* lcd, Joystick* jstick)
SomeRandomBloke 8:857444086b3f 44 {
SomeRandomBloke 8:857444086b3f 45 lcd->writeString(0, 0, "mbed-a-sketch", NORMAL);
SomeRandomBloke 8:857444086b3f 46 lcd->writeString(12, 1, "driven by", NORMAL);
SomeRandomBloke 8:857444086b3f 47 lcd->writeString(10, 2, "KL25Z mbed", NORMAL);
SomeRandomBloke 8:857444086b3f 48 lcd->writeString(0, 3, "By AD Lindsay", NORMAL);
SomeRandomBloke 8:857444086b3f 49 }
SomeRandomBloke 8:857444086b3f 50
SomeRandomBloke 8:857444086b3f 51 void backlight(N3310LCD* lcd, Joystick* jstick)
SomeRandomBloke 8:857444086b3f 52 {
SomeRandomBloke 8:857444086b3f 53 lcd->writeString( 0, 1, "Toggle", NORMAL);
SomeRandomBloke 8:857444086b3f 54 lcd->writeString( 0, 2, "Backlight", NORMAL);
SomeRandomBloke 8:857444086b3f 55 if( blflag != 0 ) {
SomeRandomBloke 8:857444086b3f 56 lcd->writeString( 60, 2, "Off", HIGHLIGHT);
SomeRandomBloke 8:857444086b3f 57 } else {
SomeRandomBloke 8:857444086b3f 58 lcd->writeString( 60, 2, "On", HIGHLIGHT);
SomeRandomBloke 8:857444086b3f 59 }
SomeRandomBloke 8:857444086b3f 60
SomeRandomBloke 8:857444086b3f 61 int8_t i;
SomeRandomBloke 8:857444086b3f 62 bool exitFlag = false;
SomeRandomBloke 8:857444086b3f 63
SomeRandomBloke 8:857444086b3f 64 while( !exitFlag ) {
SomeRandomBloke 8:857444086b3f 65 for (int i = 0; i < NUM_KEYS; i++) {
SomeRandomBloke 8:857444086b3f 66 if (jstick->getKeyState(i) != 0) {
SomeRandomBloke 8:857444086b3f 67 jstick->resetKeyState(i); // reset button flag
SomeRandomBloke 8:857444086b3f 68 switch(i) {
SomeRandomBloke 8:857444086b3f 69 case CENTER_KEY:
SomeRandomBloke 8:857444086b3f 70 exitFlag = true;
SomeRandomBloke 8:857444086b3f 71 break;
SomeRandomBloke 8:857444086b3f 72 case UP_KEY:
SomeRandomBloke 8:857444086b3f 73 case DOWN_KEY:
SomeRandomBloke 8:857444086b3f 74 if( blflag != 0 ) {
SomeRandomBloke 8:857444086b3f 75 blflag=0;
SomeRandomBloke 8:857444086b3f 76 lcd->backlight( OFF );
SomeRandomBloke 8:857444086b3f 77 } else {
SomeRandomBloke 8:857444086b3f 78 blflag = 1;
SomeRandomBloke 8:857444086b3f 79 lcd->backlight( ON );
SomeRandomBloke 8:857444086b3f 80 }
SomeRandomBloke 8:857444086b3f 81 lcd->writeString( 60, 2, (blflag != 0 ? (char*)"Off" : (char*)"On "), HIGHLIGHT);
SomeRandomBloke 8:857444086b3f 82 break;
SomeRandomBloke 8:857444086b3f 83 }
SomeRandomBloke 8:857444086b3f 84 }
SomeRandomBloke 8:857444086b3f 85 }
SomeRandomBloke 8:857444086b3f 86 }
SomeRandomBloke 8:857444086b3f 87 }
SomeRandomBloke 8:857444086b3f 88
SomeRandomBloke 8:857444086b3f 89
SomeRandomBloke 8:857444086b3f 90 void draw(N3310LCD* lcd, Joystick* jstick)
SomeRandomBloke 8:857444086b3f 91 {
SomeRandomBloke 8:857444086b3f 92 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS, false, 4);
SomeRandomBloke 8:857444086b3f 93 lcd->cls();
SomeRandomBloke 8:857444086b3f 94 // lcd->writeString(10, 2, "La", NORMAL);
SomeRandomBloke 8:857444086b3f 95
SomeRandomBloke 8:857444086b3f 96 // Draw a rectangle
SomeRandomBloke 8:857444086b3f 97 lcd->drawRectangle(0,0,83,47, PIXEL_ON);
SomeRandomBloke 8:857444086b3f 98
SomeRandomBloke 8:857444086b3f 99 int8_t px = 42;
SomeRandomBloke 8:857444086b3f 100 int8_t py = 24;
SomeRandomBloke 8:857444086b3f 101 int8_t nx = px;
SomeRandomBloke 8:857444086b3f 102 int8_t ny = py;
SomeRandomBloke 8:857444086b3f 103
SomeRandomBloke 8:857444086b3f 104 lcd->setPixel( px, py, PIXEL_ON );
SomeRandomBloke 8:857444086b3f 105
SomeRandomBloke 8:857444086b3f 106 float x, y; //, z;
SomeRandomBloke 8:857444086b3f 107 float cValues[3] = { 0.0, 0.0, 0.0 };
SomeRandomBloke 8:857444086b3f 108 int16_t xI, yI; //, zI;
SomeRandomBloke 8:857444086b3f 109 int16_t xInc, yInc;
SomeRandomBloke 8:857444086b3f 110
SomeRandomBloke 8:857444086b3f 111 // Take 100 readings to get stable centre point
SomeRandomBloke 8:857444086b3f 112
SomeRandomBloke 8:857444086b3f 113 for( int i = 0; i < 100; i++ ) {
SomeRandomBloke 8:857444086b3f 114 float axis[3] = { 0.0, 0.0, 0.0 };
SomeRandomBloke 8:857444086b3f 115 acc.getAccAllAxis( axis );
SomeRandomBloke 8:857444086b3f 116 cValues[0] += axis[0];
SomeRandomBloke 8:857444086b3f 117 cValues[1] += axis[1];
SomeRandomBloke 8:857444086b3f 118 // cValues[2] += axis[2];
SomeRandomBloke 8:857444086b3f 119 }
SomeRandomBloke 8:857444086b3f 120
SomeRandomBloke 8:857444086b3f 121 cValues[0] /= 100.0;
SomeRandomBloke 8:857444086b3f 122 cValues[1] /= 100.0;
SomeRandomBloke 8:857444086b3f 123 // cValues[2] /= 100.0;
SomeRandomBloke 8:857444086b3f 124 // pc.printf( "Steady State X: %f Y: %f Z: %f\n", cValues[0], cValues[1], cValues[2] );
SomeRandomBloke 8:857444086b3f 125
SomeRandomBloke 8:857444086b3f 126 // Exit on joystick pressed
SomeRandomBloke 8:857444086b3f 127 bool exitFlag = false;
SomeRandomBloke 8:857444086b3f 128 while ( !exitFlag ) {
SomeRandomBloke 8:857444086b3f 129 uint8_t keyPress = checkKeypressed( jstick );
SomeRandomBloke 8:857444086b3f 130 if( keyPress == CENTER_KEY )
SomeRandomBloke 8:857444086b3f 131 exitFlag = true;
SomeRandomBloke 8:857444086b3f 132
SomeRandomBloke 8:857444086b3f 133 x = (acc.getAccX() - cValues[0]) * 100.0;
SomeRandomBloke 8:857444086b3f 134 y = (acc.getAccY() - cValues[1]) * 100.0;
SomeRandomBloke 8:857444086b3f 135 // z = (acc.getAccZ() - cValues[2]) * 100.0;
SomeRandomBloke 8:857444086b3f 136 // pc.printf( "X: %f Y: %f Z: %f\n", x, y, z);
SomeRandomBloke 8:857444086b3f 137
SomeRandomBloke 8:857444086b3f 138 xI = (int16_t)(x);
SomeRandomBloke 8:857444086b3f 139 yI = (int16_t)(y);
SomeRandomBloke 8:857444086b3f 140 // zI = (int16_t)(z);
SomeRandomBloke 8:857444086b3f 141 xInc = xI/10;
SomeRandomBloke 8:857444086b3f 142 yInc = ((yI/10) * -1);
SomeRandomBloke 8:857444086b3f 143
SomeRandomBloke 8:857444086b3f 144 nx += xInc;
SomeRandomBloke 8:857444086b3f 145 ny += yInc;
SomeRandomBloke 8:857444086b3f 146
SomeRandomBloke 8:857444086b3f 147 nx = MAX( 1, MIN( nx, 82 ) );
SomeRandomBloke 8:857444086b3f 148 ny = MAX( 1, MIN( ny, 46 ) );
SomeRandomBloke 8:857444086b3f 149
SomeRandomBloke 8:857444086b3f 150 if( abs(xInc) > 1 || abs(yInc) > 1 ) {
SomeRandomBloke 8:857444086b3f 151 // Draw line
SomeRandomBloke 8:857444086b3f 152 lcd->drawLine((uint8_t)px, (uint8_t)py, (uint8_t)nx, (uint8_t)ny, PIXEL_ON);
SomeRandomBloke 8:857444086b3f 153 } else {
SomeRandomBloke 8:857444086b3f 154 // Plot pixel
SomeRandomBloke 8:857444086b3f 155 lcd->setPixel( (uint8_t)nx, (uint8_t)ny, PIXEL_ON );
SomeRandomBloke 8:857444086b3f 156 }
SomeRandomBloke 8:857444086b3f 157
SomeRandomBloke 8:857444086b3f 158 px = nx;
SomeRandomBloke 8:857444086b3f 159 py = ny;
SomeRandomBloke 8:857444086b3f 160
SomeRandomBloke 8:857444086b3f 161 // pc.printf( "X: %d Y: %d Z: %d\n", xI, yI, zI);
SomeRandomBloke 8:857444086b3f 162 wait(0.1);
SomeRandomBloke 8:857444086b3f 163 }
SomeRandomBloke 8:857444086b3f 164
SomeRandomBloke 8:857444086b3f 165
SomeRandomBloke 8:857444086b3f 166 }
SomeRandomBloke 8:857444086b3f 167
SomeRandomBloke 8:857444086b3f 168
SomeRandomBloke 8:857444086b3f 169
SomeRandomBloke 8:857444086b3f 170
SomeRandomBloke 8:857444086b3f 171 void initMenu(N3310LCD* lcd)
SomeRandomBloke 8:857444086b3f 172 {
SomeRandomBloke 8:857444086b3f 173 lcd->writeString(MENU_X, MENU_Y, menu_items[0], HIGHLIGHT );
SomeRandomBloke 8:857444086b3f 174
SomeRandomBloke 8:857444086b3f 175 for (int i = 1; i < MENU_ITEMS; i++) {
SomeRandomBloke 8:857444086b3f 176 lcd->writeString(MENU_X, MENU_Y + i, menu_items[i], NORMAL);
SomeRandomBloke 8:857444086b3f 177 }
SomeRandomBloke 8:857444086b3f 178 }
SomeRandomBloke 8:857444086b3f 179
SomeRandomBloke 8:857444086b3f 180 void waitforOKKey(N3310LCD* lcd, Joystick* jstick)
SomeRandomBloke 8:857444086b3f 181 {
SomeRandomBloke 8:857444086b3f 182 lcd->writeString(38, 5, "OK", HIGHLIGHT );
SomeRandomBloke 8:857444086b3f 183
SomeRandomBloke 8:857444086b3f 184 int key = 0xFF;
SomeRandomBloke 8:857444086b3f 185 while (key != CENTER_KEY) {
SomeRandomBloke 8:857444086b3f 186 for (int i = 0; i < NUM_KEYS; i++) {
SomeRandomBloke 8:857444086b3f 187 if (jstick->getKeyState(i) !=0) {
SomeRandomBloke 8:857444086b3f 188 jstick->resetKeyState(i); // reset
SomeRandomBloke 8:857444086b3f 189 if (CENTER_KEY == i) key = CENTER_KEY;
SomeRandomBloke 8:857444086b3f 190 }
SomeRandomBloke 8:857444086b3f 191 }
SomeRandomBloke 8:857444086b3f 192 }
SomeRandomBloke 8:857444086b3f 193 }
SomeRandomBloke 8:857444086b3f 194
SomeRandomBloke 8:857444086b3f 195 // Check if joystick is moved or pressed
SomeRandomBloke 8:857444086b3f 196 uint8_t checkKeypressed( Joystick* jstick)
SomeRandomBloke 8:857444086b3f 197 {
SomeRandomBloke 8:857444086b3f 198 uint8_t key = 0xFF;
SomeRandomBloke 8:857444086b3f 199
SomeRandomBloke 8:857444086b3f 200 for(int i=0; i<NUM_KEYS; i++) {
SomeRandomBloke 8:857444086b3f 201 if (jstick->getKeyState(i) !=0) {
SomeRandomBloke 8:857444086b3f 202 jstick->resetKeyState(i); // reset
SomeRandomBloke 8:857444086b3f 203 if (CENTER_KEY == i) key = CENTER_KEY;
SomeRandomBloke 8:857444086b3f 204 }
SomeRandomBloke 8:857444086b3f 205 }
SomeRandomBloke 8:857444086b3f 206 return key;
SomeRandomBloke 8:857444086b3f 207 }
SomeRandomBloke 8:857444086b3f 208
SomeRandomBloke 8:857444086b3f 209
SomeRandomBloke 8:857444086b3f 210 int main(void)
SomeRandomBloke 8:857444086b3f 211 {
SomeRandomBloke 8:857444086b3f 212 // MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS, false, 4);
SomeRandomBloke 8:857444086b3f 213 Joystick jstick(N3310SPIPort::AD0);
SomeRandomBloke 8:857444086b3f 214 N3310LCD lcd(N3310SPIPort::MOSI, N3310SPIPort::MISO, N3310SPIPort::SCK,
SomeRandomBloke 8:857444086b3f 215 N3310SPIPort::CE, N3310SPIPort::DAT_CMD, N3310SPIPort::LCD_RST,
SomeRandomBloke 8:857444086b3f 216 N3310SPIPort::BL_ON);
SomeRandomBloke 8:857444086b3f 217 lcd.init();
SomeRandomBloke 8:857444086b3f 218 lcd.cls();
SomeRandomBloke 8:857444086b3f 219 lcd.backlight(ON);
SomeRandomBloke 8:857444086b3f 220
SomeRandomBloke 8:857444086b3f 221 // demo stuff
SomeRandomBloke 8:857444086b3f 222 // autoDemo(&lcd);
SomeRandomBloke 8:857444086b3f 223
SomeRandomBloke 8:857444086b3f 224 lcd.drawBitmap(0, 0, splash, 84, 48);
SomeRandomBloke 8:857444086b3f 225 wait( 5 );
SomeRandomBloke 8:857444086b3f 226 lcd.cls();
SomeRandomBloke 8:857444086b3f 227
SomeRandomBloke 8:857444086b3f 228 initMenu(&lcd);
SomeRandomBloke 8:857444086b3f 229 int currentMenuItem = 0;
SomeRandomBloke 8:857444086b3f 230 Ticker jstickPoll;
SomeRandomBloke 8:857444086b3f 231 jstickPoll.attach(&jstick, &Joystick::updateADCKey, 0.01); // check ever 10ms
chris 4:367de1084ea9 232
emilmont 5:bf5becf7469c 233 while (true) {
SomeRandomBloke 8:857444086b3f 234 for (int i = 0; i < NUM_KEYS; i++) {
SomeRandomBloke 8:857444086b3f 235 if (jstick.getKeyState(i) != 0) {
SomeRandomBloke 8:857444086b3f 236 jstick.resetKeyState(i); // reset button flag
SomeRandomBloke 8:857444086b3f 237 switch(i) {
SomeRandomBloke 8:857444086b3f 238 case UP_KEY:
SomeRandomBloke 8:857444086b3f 239 // current item to normal display
SomeRandomBloke 8:857444086b3f 240 lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], NORMAL);
SomeRandomBloke 8:857444086b3f 241 currentMenuItem -=1;
SomeRandomBloke 8:857444086b3f 242 if (currentMenuItem <0) currentMenuItem = MENU_ITEMS -1;
SomeRandomBloke 8:857444086b3f 243 // next item to highlight display
SomeRandomBloke 8:857444086b3f 244 lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], HIGHLIGHT);
SomeRandomBloke 8:857444086b3f 245 break;
SomeRandomBloke 8:857444086b3f 246
SomeRandomBloke 8:857444086b3f 247 case DOWN_KEY:
SomeRandomBloke 8:857444086b3f 248 // current item to normal display
SomeRandomBloke 8:857444086b3f 249 lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], NORMAL);
SomeRandomBloke 8:857444086b3f 250 currentMenuItem +=1;
SomeRandomBloke 8:857444086b3f 251 if(currentMenuItem >(MENU_ITEMS - 1)) currentMenuItem = 0;
SomeRandomBloke 8:857444086b3f 252 // next item to highlight display
SomeRandomBloke 8:857444086b3f 253 lcd.writeString(MENU_X, MENU_Y + currentMenuItem, menu_items[currentMenuItem], HIGHLIGHT);
SomeRandomBloke 8:857444086b3f 254 break;
SomeRandomBloke 8:857444086b3f 255
SomeRandomBloke 8:857444086b3f 256 case LEFT_KEY:
SomeRandomBloke 8:857444086b3f 257 initMenu(&lcd);
SomeRandomBloke 8:857444086b3f 258 currentMenuItem = 0;
SomeRandomBloke 8:857444086b3f 259 break;
SomeRandomBloke 8:857444086b3f 260
SomeRandomBloke 8:857444086b3f 261 case RIGHT_KEY:
SomeRandomBloke 8:857444086b3f 262 lcd.cls();
SomeRandomBloke 8:857444086b3f 263 (*menu_funcs[currentMenuItem])(&lcd, &jstick);
SomeRandomBloke 8:857444086b3f 264 waitforOKKey(&lcd, &jstick);
SomeRandomBloke 8:857444086b3f 265 lcd.cls();
SomeRandomBloke 8:857444086b3f 266 initMenu(&lcd);
SomeRandomBloke 8:857444086b3f 267 currentMenuItem = 0;
SomeRandomBloke 8:857444086b3f 268 break;
SomeRandomBloke 8:857444086b3f 269 }
SomeRandomBloke 8:857444086b3f 270 }
SomeRandomBloke 8:857444086b3f 271 }
chris 2:41db78380a6e 272 }
SomeRandomBloke 8:857444086b3f 273
SomeRandomBloke 8:857444086b3f 274 /*
SomeRandomBloke 8:857444086b3f 275 // PwmOut rled(LED_RED);
SomeRandomBloke 8:857444086b3f 276 // PwmOut gled(LED_GREEN);
SomeRandomBloke 8:857444086b3f 277 // PwmOut bled(LED_BLUE);
SomeRandomBloke 8:857444086b3f 278 float x, y, z;
SomeRandomBloke 8:857444086b3f 279 float cValues[3] = { 0.0, 0.0, 0.0 };
SomeRandomBloke 8:857444086b3f 280 int16_t xI, yI, zI;
SomeRandomBloke 8:857444086b3f 281
SomeRandomBloke 8:857444086b3f 282 // Take 100 readings to get stable centre point
SomeRandomBloke 8:857444086b3f 283
SomeRandomBloke 8:857444086b3f 284 for( int i = 0; i < 100; i++ ) {
SomeRandomBloke 8:857444086b3f 285 float axis[3] = { 0.0, 0.0, 0.0 };
SomeRandomBloke 8:857444086b3f 286 acc.getAccAllAxis( axis );
SomeRandomBloke 8:857444086b3f 287 cValues[0] += axis[0];
SomeRandomBloke 8:857444086b3f 288 cValues[1] += axis[1];
SomeRandomBloke 8:857444086b3f 289 cValues[2] += axis[2];
SomeRandomBloke 8:857444086b3f 290 }
SomeRandomBloke 8:857444086b3f 291
SomeRandomBloke 8:857444086b3f 292 cValues[0] /= 100.0;
SomeRandomBloke 8:857444086b3f 293 cValues[1] /= 100.0;
SomeRandomBloke 8:857444086b3f 294 cValues[2] /= 100.0;
SomeRandomBloke 8:857444086b3f 295 pc.printf( "Steady State X: %f Y: %f Z: %f\n", cValues[0], cValues[1], cValues[2] );
SomeRandomBloke 8:857444086b3f 296
SomeRandomBloke 8:857444086b3f 297 while (true) {
SomeRandomBloke 8:857444086b3f 298
SomeRandomBloke 8:857444086b3f 299 x = (acc.getAccX() - cValues[0]) * 100.0;
SomeRandomBloke 8:857444086b3f 300 y = (acc.getAccY() - cValues[1]) * 100.0;
SomeRandomBloke 8:857444086b3f 301 z = (acc.getAccZ() - cValues[2]) * 100.0;
SomeRandomBloke 8:857444086b3f 302 // pc.printf( "X: %f Y: %f Z: %f\n", x, y, z);
SomeRandomBloke 8:857444086b3f 303
SomeRandomBloke 8:857444086b3f 304 xI = (int16_t)(x);
SomeRandomBloke 8:857444086b3f 305 yI = (int16_t)(y);
SomeRandomBloke 8:857444086b3f 306 zI = (int16_t)(z);
SomeRandomBloke 8:857444086b3f 307 pc.printf( "X: %d Y: %d Z: %d\n", xI, yI, zI);
SomeRandomBloke 8:857444086b3f 308 // pc.printf( "X: %f Y: %f Z: %f\n", x*100.0, y*100.0, z*100.0);
SomeRandomBloke 8:857444086b3f 309 // rled = 1.0 - abs(acc.getAccX());
SomeRandomBloke 8:857444086b3f 310 // gled = 1.0 - abs(acc.getAccY());
SomeRandomBloke 8:857444086b3f 311 // bled = 1.0 - abs(acc.getAccZ());
SomeRandomBloke 8:857444086b3f 312 wait(0.5);
SomeRandomBloke 8:857444086b3f 313 }
SomeRandomBloke 8:857444086b3f 314 */
chris 2:41db78380a6e 315 }