Go Down

Topic: Arduino and C# GUI (Read 381 times) previous topic - next topic

terance

Hi to everyone!

I have 5 botooms(1st bottom-move forward,2nd-move back,3d-turn right,4th-turn left,5th-stop moving)

When user presses e.x. 1st bottom ,then robot is moving forwad , when user presses 2nd robot is moving back and so on ... when stopbottom is pressed - robot stops

I'm interesting in developing application ,which implements this logic. I've wrote simple code , but I think it doest work properly.
Code: [Select]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArduinoProject
{
   public partial class myForm : Form
   {
       public int cycleNumber;

       void sendCommands(string commandName)
       {

           myTextBox.Text += commandName;
       }
       private void selectSycle()
       {
           //for (; ; )
           {
               switch (cycleNumber)
               {
                   default:
                       break;
                   case 1:
                       sendCommands("moving forward");
                       break;
                   case 2:
                       sendCommands("turn left");
                       break;
                   case 3:
                       sendCommands("turn right");
                       break;
                   case 4:
                       sendCommands("move back");
                       break;
               }
          }
       }

       public myForm()
       {
           InitializeComponent();
       }

       private void moveForward_Click(object sender, EventArgs e)
       {
           cycleNumber=1;
           selectSycle();
       }

       private void turnLeft_Click(object sender, EventArgs e)
       {
           cycleNumber=2;
           selectSycle();
       }

       private void turnRight_Click(object sender, EventArgs e)
       {
           cycleNumber=3;
           selectSycle();
       }

       private void moveBack_Click(object sender, EventArgs e)
       {
           cycleNumber=4;
           selectSycle();
       }

       private void Pause_Click(object sender, EventArgs e)
       {

       }
   }
}


any ideas how to improve it?

Go Up