I have created this Arduino sketch that communicates with my pc through the Console library and using the serial monitor over my network. Essentially, when I enter the digit 1, my Arduino stepper motor moves 30 steps etc. However, it is inconvenient to have to type in the serial monitor. I was hoping anyone would know how I can create an executable windows form or something that can connect over my network, to the Arduino Yun console.
#include <Stepper.h>
#include <Console.h>
char incomingByte;
Stepper stepper(64,8,9,10,11);
int stepCount = 1;
void setup() {
Bridge.begin();
Console.begin();
while (!Console);
stepper.setSpeed(60);
}
void loop() {
if (Console.available() > 0)
{
incomingByte = Console.read();
if (incomingByte == '1')
{
stepCount += 30;
if (stepCount > 0 && stepCount < 4096)
{
stepper.step(30);
Console.println(stepCount);
}
else{stepCount = stepCount - 30;}
}
if (incomingByte == '2')
{
stepCount = stepCount - 30;
if (stepCount > 0 && stepCount < 4096)
{
stepper.step(-30);
Console.println(stepCount);
}
else{stepCount += 30;}
}
if (incomingByte == '3')
{
stepCount += 200;
if (stepCount > 0 && stepCount < 4096)
{
stepper.step(200);
Console.println(stepCount);
}
else{stepCount = stepCount - 200;}
}
if (incomingByte == '4')
{
stepCount = stepCount - 200;
if (stepCount > 0 && stepCount < 4096)
{
stepper.step(-200);
Console.println(stepCount);
}
else{stepCount += 200;}
}
}
}
Here is the windows form app I was hoping would work:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace Remote_Focuser
{
public partial class Form1 : Form
{
private SerialPort myPort;
public Form1()
{
Console.Read();
InitializeComponent();
Init();
}
private void Fwd_30_Button_Click(object sender, EventArgs e)
{
myPort.WriteLine("1");
}
private void Backward_30_Button_Click(object sender, EventArgs e)
{
myPort.WriteLine("2");
}
private void Forward_200_Button_Click(object sender, EventArgs e)
{
myPort.WriteLine("3");
}
private void Backward_200_Button_Click(object sender, EventArgs e)
{
myPort.WriteLine("4");
}
private void Init()
{
myPort = new SerialPort();
myPort.BaudRate = 9600;
myPort.PortName = "10.1.1.211";
myPort.Open();
}
}
}
Thanks heaps in advance, and yes I have probably made a big mistake, I am not too proficient yet... :)