Hia, this is probably a pretty simple question, but I am completely stumped on this bug/gaff.
Anyway I am trying to get two servos to turn when I move the mouse over a windows form.
I know using an uno would probably be better, but all I have available right now is a nano, just curious if I could even use a nano. Thanks!
this is my visual studio code.
public Stopwatch timer { get; set; }
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer = Stopwatch.StartNew();
TheCoolBeans.Open();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
writeToPort(new Point(e.X, e.Y));
}
public void writeToPort(Point coordinates)
{
if (timer.ElapsedMilliseconds > 15)
{
timer = Stopwatch.StartNew();
// put in 180- if going in the wrong direction, why than you, oh its
// no problem, but thanks any way!
TheCoolBeans.Write(String.Format("X{0}Y{1}",
(coordinates.X / (Size.Width / 180)),
(coordinates.Y / (Size.Height / 180))));
}
}
}
}
TheCoolBeans is a serial port
#include<Servo.h>
Servo servX;
Servo servY;
String serialData;
void setup() {
// put your setup code here, to run once:
servY.attach(10);
servX.attach(11);
Serial.begin(9600);
Serial.setTimeout(10);
}
void loop() {
//lol
}
void SerialEvent(){
serialData = Serial.readString();
parseDataX(serialData);
parseDataY(serialData);
servX.write(parseDataX(serialData));
servY.write(parseDataY(serialData));
}
int parseDataX (String data){
data.remove(data.indexOf("Y"));
data.remove(data.indexOf("X"), 1);
return data.toInt();
}
int parseDataY (String data){
data.remove(0, data.indexOf("Y") + 1);
return data.toInt();
}
and that was my Arduino nano code.