⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controllrobot.java

📁 1、手持设备机器人——应用端; 2、基于蓝牙传输;
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		}else if(xdirection == 4)
	    {
			// We are turning right so let's go to neutral.
			bluetooth.command(5);

			// Depending on the ydirection we set the wheel to a certain angle.
			if(ydirection == 2 || ydirection == 3)
			 {
				 direction  = ydirection;
			 }else{
				 direction  = 6;
			}

		   xdirection = 6;

		// If it's in neutral send right
		}else if(xdirection == 6)
		{

			bluetooth.command(5);
			xdirection = 5;
			direction  = 5;

		}else{ // Other
	          direction  = 5;
	          bluetooth.command(5);
	          xdirection = 5;
		}


   }

  // Up
  if ((keyStates & UP_PRESSED) != 0)
   {
	  if(ydirection == 2)
	  	{
			// Already going forward
			direction = 2;
		}else if(ydirection == 3)
		{
			bluetooth.command(6);
			ydirection = 6;
			direction  = 6;
		}else if(ydirection == 6)
		{
			bluetooth.command(2);
			ydirection = 2;
			direction  = 2;
		}else{
			bluetooth.command(2);
			ydirection = 2;
			direction  = 2;
		}

     }

  // Down
  if ((keyStates & DOWN_PRESSED) !=0)
   {
	  if(ydirection == 3)
	  	{
			// Already going backwards
			direction = 3;
		}else if(ydirection == 2)
		{
			bluetooth.command(6);
			ydirection = 6;
			direction  = 6;

		}else if(ydirection == 6)
		{
			bluetooth.command(3);
			ydirection = 3;
			direction  = 3;
		}else{
			bluetooth.command(3);
			ydirection = 3;
			direction  = 3;
		}
  }

  // Fire
  if ((keyStates & FIRE_PRESSED) !=0)
   {
     if(direction != 8)
      {

			  // We don't know what we want to do here

      }else{
              direction = 6;
 	     	  bluetooth.command(0);
      }
   }

   keyStates = 0;
   try{ Thread.sleep(15); } catch (Exception e) { /* Do nothing */ }
}

// Method to Display Graphics
private void drawScreen(Graphics g) {
  g.setColor(0xffffff);
  g.fillRect(0, 0, getWidth(), getHeight());

   //border
  g.setColor(0xFC932C);
  g.fillRect(0, 0, width, height);

  g.setColor(0xffffff);
  g.fillRect(1, 1, width - 2, height - 2);

 // top

  g.setColor(0xEBF1F7);
  g.fillRect(1, 1, width - 2, 27);

  g.setColor(0xADC2D6);
  g.fillRect(1, 28, width - 2, 2);

  g.drawImage (bluetooth.logo, width - 138, 1, Graphics.TOP | Graphics.LEFT);

  if(direction == 8)
   {

         g.drawImage (bluetooth.start, left, top, Graphics.TOP | Graphics.LEFT);
         g.drawImage (bluetooth.stopped, left, 40, Graphics.TOP | Graphics.LEFT);
    }else{
         g.drawImage (bluetooth.running, left, 40, Graphics.TOP | Graphics.LEFT);

           if(direction == 4)
            {
             g.drawImage (bluetooth.Left, left + 82, 37, Graphics.TOP | Graphics.LEFT);
             bluetooth.wheel.setPosition(width / 2 - 59, height / 2 - 59 + 25);
             bluetooth.wheel.setFrame(0);
             bluetooth.wheel.paint(g);
            }

           if(direction == 5)
            {
             g.drawImage (bluetooth.right, left + 82, 37, Graphics.TOP | Graphics.LEFT);
             bluetooth.wheel.setPosition(width / 2 - 59, height / 2 - 59 + 25);
             bluetooth.wheel.setFrame(1);
             bluetooth.wheel.paint(g);
            }

           if(direction == 2)
            {
             g.drawImage (bluetooth.forward, left + 82, 37, Graphics.TOP | Graphics.LEFT);
             bluetooth.wheel.setPosition(width / 2 - 59, height / 2 - 59 + 25);
             bluetooth.wheel.setFrame(2);
             bluetooth.wheel.paint(g);
            }

           if(direction == 3)
            {
             g.drawImage (bluetooth.backward, left + 82, 37, Graphics.TOP | Graphics.LEFT);
             bluetooth.wheel.setPosition(width / 2 - 59, height / 2 - 59 + 25);
             bluetooth.wheel.setFrame(3);
             bluetooth.wheel.paint(g);
            }

           if(direction == 6)
            {
             g.drawImage (bluetooth.nowhere, left + 82, 37, Graphics.TOP | Graphics.LEFT);
             bluetooth.wheel.setPosition(width / 2 - 59, height / 2 - 59 + 25);
             bluetooth.wheel.setFrame(2);
             bluetooth.wheel.paint(g);
            }

          g.setColor(0x0000ff);
         }

  flushGraphics();
 }

 private void drawAboutScreen(Graphics g) {
  g.setColor(0xffffff);
  g.fillRect(0, 0, getWidth(), getHeight());

   //border
  g.setColor(0xFC932C);
  g.fillRect(0, 0, width, height);

  g.setColor(0xffffff);
  g.fillRect(1, 1, width - 2, height - 2);

 // top

  g.setColor(0xEBF1F7);
  g.fillRect(1, 1, width - 2, 27);

  g.setColor(0xADC2D6);
  g.fillRect(1, 28, width - 2, 2);

  g.drawImage (bluetooth.logo, width - 138, 1, Graphics.TOP | Graphics.LEFT);
  g.drawImage (bluetooth.about, width / 2 - 59, height / 2 - 59 + 10, Graphics.TOP | Graphics.LEFT);
  flushGraphics();
 }

 private void drawPointerScreen(Graphics g) {
  g.setColor(0xffffff);
  g.fillRect(0, 0, getWidth(), getHeight());

   //border
  g.setColor(0xFC932C);
  g.fillRect(0, 0, width, height);

  g.setColor(0xffffff);
  g.fillRect(1, 1, width - 2, height - 2);

  g.setColor(0xFC932C);
  g.fillRect(width / 2 - 90, 40, 179, boxy - 40);

  g.setColor(0xDAE4ED);
  g.fillRect(width / 2 - 89, 41, 177, boxy - 42);

 // top

  g.setColor(0xEBF1F7);
  g.fillRect(1, 1, width - 2, 27);

  g.setColor(0xADC2D6);
  g.fillRect(1, 28, width - 2, 2);

  g.drawImage (bluetooth.logo, width - 138, 1, Graphics.TOP | Graphics.LEFT);

   // Clear and run button
   g.drawImage (bluetooth.clear, width / 2 - 90, boxy + 10, Graphics.TOP | Graphics.LEFT);
   g.drawImage (bluetooth.run, width / 2 + 10, boxy + 10, Graphics.TOP | Graphics.LEFT);


    // Draws the line
    g.setColor(0x43506B);
    if(havePoints == true)
     {
       g.fillRect(points[0][0],points[0][1],2,2);

        for (int i=0; i < nrpoints; i++)
         {
          g.fillRect(points[i][0],points[i][1],2,2);

          if(i == 0)
           {
           }else{
           int tmp = i - 1;
            g.drawLine(points[tmp][0],points[tmp][1],points[i][0],points[i][1]);
          }
         }
   }

   flushGraphics();
 }

 private void drawPointerScreenRunning(Graphics g) {
  g.setColor(0xffffff);
  g.fillRect(0, 0, getWidth(), getHeight());

   //border
  g.setColor(0xFC932C);
  g.fillRect(0, 0, width, height);

  g.setColor(0xffffff);
  g.fillRect(1, 1, width - 2, height - 2);

  g.setColor(0xFC932C);
  g.fillRect(width / 2 - 90, 40, 179, boxy - 40);

  g.setColor(0xDAE4ED);
  g.fillRect(width / 2 - 89, 41, 177, boxy - 42);

 // top

  g.setColor(0xEBF1F7);
  g.fillRect(1, 1, width - 2, 27);

  g.setColor(0xADC2D6);
  g.fillRect(1, 28, width - 2, 2);

  g.drawImage (bluetooth.logo, width - 138, 1, Graphics.TOP | Graphics.LEFT);

   // Clear and run button
   g.drawImage (bluetooth.clear, width / 2 - 90, boxy + 10, Graphics.TOP | Graphics.LEFT);
   g.drawImage (bluetooth.run, width / 2 + 10, boxy + 10, Graphics.TOP | Graphics.LEFT);


    // Draws the line
    g.setColor(0x43506B);
    if(havePoints == true)
     {
       g.fillRect(points[0][0],points[0][1],2,2);

        for (int i=0; i < nrpoints; i++)
         {
          g.fillRect(points[i][0],points[i][1],2,2);

          if(i == 0)
           {
           }else{
           int tmp = i - 1;
            g.drawLine(points[tmp][0],points[tmp][1],points[i][0],points[i][1]);
          }
         }
   }



    // Draws the second line
    g.setColor(0xFFFFFF);
    if(havePoints == true)
     {
       g.fillRect(dpoints[0][0],dpoints[0][1],2,2);

        for (int i=0; i < dnrpoints; i++)
         {
          g.fillRect(dpoints[i][0],dpoints[i][1],2,2);

          if(i == 0)
           {
           }else{
           int tmp = i - 1;
            g.drawLine(dpoints[tmp][0],dpoints[tmp][1],dpoints[i][0],dpoints[i][1]);
          }
         }
   }
   flushGraphics();
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -