Advertisement
Ceron

Calibrate.nxc

Oct 8th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. task main() {
  2.  
  3.     SetSensorLowspeed(S1);
  4.     byte out;
  5.     char tone;
  6.     char result = ReadI2CRegister(S1,HT_ADDR_COMPASS, 0x41, out); //sicherung des Modus Bytes
  7.     // result == NO_ERR erfolgreich
  8.     if(result == NO_ERR) {
  9.         result = WriteI2CRegister(S1,HT_ADDR_COMPASS, 0x41, 0x43); //calibration-modus
  10.             if(result == NO_ERR) {
  11.                 //1x umdrehung in ca. 20 sekunden  danach wert lesen um kalibierung
  12.                 // zu beenden
  13.                 OnFwd(OUT_A, 5);
  14.                 OnFwd(OUT_B, 5);
  15.                 OnFwd(OUT_C, 5);
  16.                 result = WriteI2CRegister(S1,HT_ADDR_COMPASS, 0x41, 0x0); //normaler Modus 
  17.                 if(result == NO_ERR) {
  18.                     while(!ButtonPressed(BTNCENTER, true)) {
  19.                         int angle = SensorHTCompass(S1);
  20.                         //NumOut(1, LCD_LINE1, angle, 0x0);
  21.                         TextOut(1, LCD_LINE1, "Winkel:" + NumToStr(angle), 0x01);
  22.                         Wait(50);
  23.                     }
  24.                 }
  25.                 else {
  26.                     tone = PlayToneEx(TONE_E6, 50, 2, false);
  27.                     Wait(20);
  28.                     tone = PlayToneEx(TONE_E6, 50, 2, false);
  29.                     TextOut(1, LCD_LINE2, "Fehler bei Aktivierung NormMode");
  30.                 }
  31.             }
  32.             else {
  33.                 tone = PlayToneEx(TONE_E6, 50, 2, false);
  34.                 Wait(20);
  35.                 tone = PlayToneEx(TONE_E6, 50, 2, false);
  36.                 TextOut(1, LCD_LINE2, "Fehler bei Aktivierung KalMode");
  37.             }
  38.     }
  39.     else {
  40.         tone = PlayToneEx(TONE_E6, 50, 2, false);
  41.         Wait(20);
  42.         tone = PlayToneEx(TONE_E6, 50, 2, false);
  43.         TextOut(1, LCD_LINE2, "Fehler bei Sicherung des Registers!");
  44.     }
  45.     Wait(10000);
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement