edy
edy

Reputation: 59

From Arduino IDE to Visual Studio

I have created an Arduino project and I've tried it in Arduino IDE and it works perfectly, but now I want to add it to Visual Studio (I want to create an interface for the program as well), and when I tried to do so, I've got like 18 errors. Most functions from Arduino (like DigitalWrite(out,LOW) are not recognised).

Here is the code so far:

int out=12;

void send1(int);
void send0(int);

void A_On(void);
void A_Off(void);
void B_On(void);
void B_Off(void);
void C_On(void);
void C_Off(void);

void a_on(void);
void a_off(void);
void b_on(void);
void b_off(void);
void c_on(void);
void c_off(void);

String rec_ser="";

void printMenu(void);
int nr_rep=4;
int t=390; //microsecunde delay
int T=1100;

void setup()
{
pinMode(out, OUTPUT);
digitalWrite(out,LOW);
Serial.begin(9600);
Serial.println("RC ready");
printMenu();
}

void loop() 
{
while(Serial.available() >0)
  {
  char c=Serial.read();
  if(c!='\n')
    rec_ser+=c;
  else
    {
    if(rec_ser.indexOf("Aon")>=0)
      {
      rec_ser="";        
      Serial.println("Comanda primita: Aon");  
      A_On();
      }
    else if(rec_ser.indexOf("Aoff")>=0)
      {
      rec_ser="";  
      Serial.println("Comanda primita: Aoff");
      A_Off();
      }
    else if(rec_ser.indexOf("Bon")>=0)
      {
      rec_ser="";        
      Serial.println("Comanda primita: Bon");        
      B_On();
      }
    else if(rec_ser.indexOf("Boff")>=0)
      {
      rec_ser="";        
      Serial.println("Comanda primita: Boff");
      B_Off();      
      }
    else if(rec_ser.indexOf("Con")>=0)
      {
      rec_ser="";        
      Serial.println("Comanda primita: Con");  
      C_On();
      }
    else if(rec_ser.indexOf("Coff")>=0)
      {
      rec_ser="";
      Serial.println("Comanda primita: Coff");  
      C_Off();
      }
    else
      {
      rec_ser="";
      Serial.println("Comanda invalida!");  
      printMenu();
      }    
    }  
  }
}

void send0(int d)
{
digitalWrite(out,LOW);
delayMicroseconds(d);
digitalWrite(out,HIGH);
}

void send1(int d)
{
digitalWrite(out,HIGH);
delayMicroseconds(d);
digitalWrite(out,LOW);
}

void A_On(void)
{
send1(t);
send0(2*T);
send1(t);
send0(T);
send1(T);
send0(t);

for(int i=0; i<nr_rep; i++)
  a_on();

}  

void A_Off(void)
{
send1(t);
send0(2*T);
send1(t);
send0(T);

for(int i=0; i<nr_rep; i++)
  a_off();

}

void printMenu(void)
{
Serial.println("Comenzi valide: ");  
Serial.println("Aon");
Serial.println("Aoff");
Serial.println("Bon");
Serial.println("Boff");
Serial.println("Con");
Serial.println("Coff");
Serial.println();
}

void a_on(void)
{
send1(3*T);
send0(7*T);
send1(t);
send0(T);
send1(T);
}

void a_off(void)
{
send1(3*T);
send0(7*T);
send1(t);
send0(T);
send1(T);
send0(t);
}

void B_On(void)
{
send1(t);
send0(2*T);
send1(t);
send0(T);

for(int i=0; i<nr_rep; i++)
  b_on();
}

void B_Off(void)
{
send1(t);
send0(2*T);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);
send0(T);

for(int i=0; i<nr_rep; i++)
  b_off();
}

void C_On(void)
{
send1(t);
send0(2*T);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);

for(int i=0; i<nr_rep; i++)
  c_on();
}

void C_Off(void)
{
send1(t);
send0(2*T);
send1(t);
send0(T);
send0(2*T);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);
send1(t);
send0(2*T);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);
send0(T);

for(int i=0; i<nr_rep; i++)
  c_off();
}

void b_on(void)
{
send1(3*T);
send0(7*T);
send1(t);
send0(T);
send1(T);
send0(t);
}

void b_off(void)
{
send1(3*T);
send0(7*T);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);  
}

void c_on(void)
{
send1(3*T);
send0(7*T);
send1(t);
send0(T);
send1(T);
send0(t);
send1(t);  
}

void c_off(void)
{
send1(3*T);
send0(7*T);
send1(t);
send0(T);
send1(T);
}

Upvotes: 0

Views: 420

Answers (2)

febles
febles

Reputation: 11

Why don't you try with this Arduino IDE for Microsoft Visual Studio and Atmel Studio? http://www.visualmicro.com/

To sum it up:

"Visual Micro is a free Arduino programming plugin that makes Microsoft Visual Studio 2008-2013 and Atmel Studio 6.2 into full Arduino programming environment. Visual Micro ensures that your sketch code remains fully compatible with the Arduino Ide and is the only Ide to support all Arduino versions in a single Ide." I think this is the easiest way for edy 2006 to make his code work using MS Visual Studio."

That would probably solve your problems.

Good luck!

Upvotes: 1

frarugi87
frarugi87

Reputation: 2880

If you want to "create an interface" I assume you want to create one for a PC.

So... Why do you need to include the arduino code? You will just have to create a form with, for instance, some buttons and then, when you press one of them, you just have to send "Aon" rather than "Aoff" or the other commands through a serial interface.

You don't need the whole arduino code.

Upvotes: 0

Related Questions