Hey all,
I have read a lot of post about serial communication but its still not working here. On my arduino mega i have the following running:
int ledPin = 13;
int state=0;
void setup() {
pinMode(ledPin, OUTPUT); // pin will be used to for output
Serial.begin(9600); // same as in your c++ script
}
void loop() {
if (Serial.available() > 0)
{
state = Serial.read(); // used to read incoming data
switch(state)// see what was sent to the board
{
case '1': // if the the one was sent
digitalWrite(ledPin,HIGH);
break;
case '0': // if 0 was sent
digitalWrite(ledPin,LOW);
break;
default:
break;
}
}
}
On my pc I have the Serial Class like its found here: see reply below
Then I wrote the next simple code:
#include "SerialClass.h"
#include < iostream >
int main( int argc, char **argv )
{
Serial mySerial("COM4");
std::cout << mySerial.IsConnected() << std::endl;
system("PAUSE");
return 0;
}
it compiles fine but when i run it it tells me it cant connect to COM4, while the ArduinoIDE can upload the code trough COM4.
Anybody know why its not working?
Cheers,
Xander