0% found this document useful (0 votes)
35 views

Shape Visual Studio and Arduino

This document contains code for an application that communicates with an Arduino board via serial communication. The application draws a circle on a form and moves it according to values received from the Arduino. The Arduino code reads the state of digital pins and sends the corresponding value over serial to indicate movement directions or no movement.

Uploaded by

Regidor Petiluna
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Shape Visual Studio and Arduino

This document contains code for an application that communicates with an Arduino board via serial communication. The application draws a circle on a form and moves it according to values received from the Arduino. The Arduino code reads the state of digital pins and sends the corresponding value over serial to indicate movement directions or no movement.

Uploaded by

Regidor Petiluna
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

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;

namespace WindowsFormsApplication7

public partial class Form1 : Form

Graphics circle;

int y = 140;

int x = 130;

String g = "";

public Form1()

InitializeComponent();

private void Form1_Load(object sender, EventArgs e)

}
private void oPENToolStripMenuItem_Click(object sender, EventArgs e)

serialPort1.Open();

private void cLOSEToolStripMenuItem_Click(object sender, EventArgs e)

serialPort1.Close();

private void Form1_Paint(object sender, PaintEventArgs e)

circle = e.Graphics;

circle.DrawArc(Pens.Blue, x, y, 20, 20, 0, 360);

private void timer1_Tick(object sender, EventArgs e)

if (g == "0")

{ x = x + 10; }

else if (g == "1")

{ x = x - 10; }

else if (g == "2")

{ y = y + 10; }

else if (g == "3")

{ y = y - 10; }

else if (g == "4")

{
x = x;

y = y;

this.Refresh();

private void button1_Click(object sender, EventArgs e)

x = 130;

y = 140;

private void button2_Click(object sender, EventArgs e)

timer1.Enabled = true;

private void serialPort1_DataReceived(object sender,


System.IO.Ports.SerialDataReceivedEventArgs e)

g = serialPort1.ReadExisting();

private void sERIALToolStripMenuItem_Click(object sender, EventArgs e)

}
ARDUINO

void setup() {

// put your setup code here, to run once:

pinMode(10,INPUT);

pinMode(11,INPUT);

pinMode(12,INPUT);

pinMode(13,INPUT);

Serial.begin(9600);// 115200

while (!Serial) {

void loop() {

// put your main code here, to run repeatedly:

if(digitalRead(10)==HIGH){

Serial.print("0");

else if(digitalRead(11)==HIGH){

Serial.print("1");

else if(digitalRead(12)==HIGH){

Serial.print("2");

else if(digitalRead(13)==HIGH){

Serial.print("3");

else

Serial.print("4");
delay(100);

You might also like