dsMotion.pp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. program dsMotion;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9;
  5. //sets the offset of the x and y and gyro and the 1 G offset of z
  6. //to callivrate other offsets you would have to instruct the user to orient
  7. //the DS in various positions
  8. procedure Calibrate();
  9. begin
  10. scanKeys();
  11. consoleClear();
  12. iprintf('Set the DS on a flat table...'#10'Press A'#10);
  13. while ((not keysDown()) and KEY_A) <> 0 do
  14. scanKeys();
  15. //these set the zero points of the accelerometers and gryo
  16. motion_set_offs_x();
  17. motion_set_offs_y();
  18. motion_set_offs_gyro();
  19. //this should be set to the acceleration value at 1 z
  20. motion_set_sens_z(motion_read_z());
  21. end;
  22. begin
  23. consoleDemoInit();
  24. motion_init();
  25. while true do
  26. begin
  27. scanKeys();
  28. if (keysDown() and KEY_A) <> 0 then
  29. Calibrate();
  30. consoleClear();
  31. if motion_init() <> 0 then
  32. iprintf('Nds is inserted'#10)
  33. else
  34. iprintf('Nds is not inserted'#10);
  35. iprintf('X: raw %i miliG %i'#10, motion_read_x(), motion_acceleration_x());
  36. iprintf('Y: raw %i miliG %i'#10, motion_read_y(), motion_acceleration_y());
  37. iprintf('Z: raw %i miliG %i'#10, motion_read_z(), motion_acceleration_z());
  38. iprintf('R: raw %i deg/sec %i'#10, motion_read_gyro(), motion_rotation());
  39. iprintf('Press A to calibrate'#10);
  40. swiWaitForVBlank();
  41. end;
  42. end.