Advertisement
Guest User

Untitled

a guest
May 30th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. private void touchsensorHandler(touchsensor.TouchSensorUpdate notification)
  2.         {
  3.  
  4.             if (notification.Body.TouchSensorOn)
  5.             {
  6.                 if (spotlightOn)
  7.                 {
  8.                     _nxtLightSensorPort.Spotlight(false);
  9.                 }
  10.                 else
  11.                 {
  12.                     _nxtLightSensorPort.Spotlight(true);
  13.                 }
  14.             }
  15.         }
  16.         //it is handling the light sensor
  17.         private void lightsensorHandler(lightsensor.Replace notification)
  18.         {
  19.             //measuring the intensity and storing in the intensity variable as an integer
  20.             intensity = notification.Body.Intensity;
  21.             //setting the spotlight on
  22.             _nxtLightSensorPort.Spotlight(true);
  23.         }
  24.         //
  25.         private void buttonsHandler(buttons.ButtonsUpdate notification)
  26.         {
  27.             //
  28.         }
  29.  
  30.         private void locateBlackLine(int angle)
  31.         {
  32.             go(0);
  33.  
  34.             for (int i = angle; i < 0; i -= 10)
  35.             {
  36.                 turn(false, 10);
  37.                 if (intensityReading() < 45)
  38.                 {
  39.                     return;
  40.                 }
  41.             }
  42.  
  43.             for (int i = -2*angle; i > 0; i += 10)
  44.             {
  45.                 turn(true, 10);
  46.                 if (intensityReading() < 45)
  47.                 {
  48.                     return;
  49.                 }
  50.             }
  51.         }
  52.  
  53.         private int intensityReading()
  54.         {
  55.             /*string color = null;
  56.             // set color string by appropriate intensity range
  57.             if (intensity > 65)
  58.                 color = "White";
  59.             else if (intensity < 45)
  60.                 color = "Black";
  61.             else
  62.                 color = "Grey";
  63.             LogInfo(LogGroups.Console, "Intensity: " + intensity + " | Color: " + color);
  64.             */
  65.             return intensity;
  66.         }
  67.  
  68.         /*
  69.         private void go(float power)
  70.         {
  71.             drive.SetDriveRequest request = new drive.SetDriveRequest();
  72.             request.LeftPower = power;
  73.             request.RightPower = power;
  74.             _nxtDrivePort.DriveDistance(request);
  75.         }
  76.         */
  77.  
  78.         private void go(float power)
  79.         {
  80.             gendrive.SetDrivePowerRequest request = new gendrive.SetDrivePowerRequest();
  81.             request.LeftWheelPower = power;
  82.             request.RightWheelPower = power;
  83.             _nxtGenDrivePort.SetDrivePower(request);
  84.         }
  85.  
  86.         /*
  87.         private void turn(bool direction, int angle)
  88.         {
  89.             drive.SetDriveRequest request = new drive.SetDriveRequest();
  90.             if (direction == 0) angle = -angle;
  91.             request.Degrees = angle;
  92.             _nxtDrivePort.RotateDegrees(request);
  93.         }
  94.         */
  95.  
  96.         private void turn(bool direction, int angle)
  97.         {
  98.             gendrive.RotateDegreesRequest request = new gendrive.RotateDegreesRequest();
  99.             if (direction == false) angle = -angle;
  100.             request.Degrees = angle;
  101.             _nxtGenDrivePort.RotateDegrees(request);
  102.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement