Pages: [1]   Go Down
Author Topic: Arduino and C# GUI  (Read 331 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Pages: [1]   Go Up
Jump to: