Hi!
I need to control 2 dc motors (5V)
so what did I do:
1)wrote scetch for arduino and uploaded to thr board
include <AFMotor.h>;
int outputPin = 13; //[ch1079][ch1076][ch1077][ch1089][ch1100] [ch1093][ch1088][ch1072][ch1085][ch1080][ch1084] [ch1085][ch1086][ch1084][ch1077][ch1088] [ch1082][ch1086][ch1085][ch1090][ch1072][ch1082][ch1090][ch1072]
int val;
AF_DCMotor motorL(1);
AF_DCMotor motorR(2);
void setup()
{
Serial.begin(9600); //[ch1091][ch1089][ch1090][ch1072][ch1085][ch1086][ch1074][ch1082][ch1072] [ch1087][ch1086][ch1088][ch1090][ch1072] [ch1085][ch1072] [ch1089][ch1082][ch1086][ch1088][ch1086][ch1089][ch1090][ch1100] 9600 [ch1073][ch1080][ch1090]/[ch1089][ch1077][ch1082]
pinMode(outputPin, OUTPUT); //[ch1091][ch1089][ch1090][ch1072][ch1085][ch1072][ch1074][ch1083][ch1080][ch1074][ch1072][ch1077][ch1084] 13 [ch1082][ch1086][ch1085][ch1090][ch1072][ch1082][ch1090] [ch1074] [ch1088][ch1077][ch1078][ch1080][ch1084] [ch1074][ch1099][ch1074][ch1086][ch1076][ch1072]
}
void loop()
{
if (Serial.available()) { //[ch1077][ch1089][ch1083][ch1080] [ch1077][ch1089][ch1090][ch1100] [ch1087][ch1088][ch1080][ch1085][ch1103][ch1090][ch1099][ch1081] [ch1089][ch1080][ch1084][ch1074][ch1086][ch1083],
val = Serial.read(); // [ch1090][ch1086] [ch1095][ch1080][ch1090][ch1072][ch1077][ch1084] [ch1077][ch1075][ch1086] [ch1080] [ch1089][ch1086][ch1093][ch1088][ch1072][ch1085][ch1103][ch1077][ch1084] [ch1074] val
if (val == 'L') { // [ch1077][ch1089][ch1083][ch1080] [ch1087][ch1088][ch1080][ch1085][ch1103][ch1090] [ch1089][ch1080][ch1084][ch1086][ch1074][ch1086][ch1083] 'H',...
motorL.run(FORWARD);
motorL.setSpeed(128);
motorR.run(BACKWARD);
motorR.setSpeed(128);
}
if (val == 'R') { // [ch1077][ch1089][ch1083][ch1080] [ch1087][ch1088][ch1080][ch1085][ch1103][ch1090] [ch1089][ch1080][ch1084][ch1086][ch1074][ch1086][ch1083] 'L',
motorL.run(BACKWARD);
motorL.setSpeed(128);
motorR.run(FORWARD);
motorR.setSpeed(128);
}
if(val=='S'){
motorL.run(RELEASE);
motorL.setSpeed(128);
motorR.run(RELEASE);
motorR.setSpeed(128);
}
if(val=='B'){
motorL.run(BACKWARD);
motorL.setSpeed(128);
motorR.run(BACKWARD);
motorR.setSpeed(128);
}
if(val=='F'){
motorL.run(FORWARD);
motorL.setSpeed(128);
motorR.run(FORWARD);
motorR.setSpeed(128);
}
}
}
2)wrote program in C#,which sent commands to arduiono
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
SerialPort port = new SerialPort("COM3", 9600);
port.Open();
while (true)
{
String s = Console.ReadLine();
if (s.Equals("exit"))
{
break;
}
port.Write(s + '\n');
}
port.Close();
}
}
}
…but when I use my C# program , to control DC motors nothing happenes,while using terminal - is OK!
what did I do wrong?
Coun you explaine me , is it possible t send commands direct to arduino (via com-port) without uploading scetch to arduino board?
thx in advance!