Im sure someone must have already asked this before, but ive been searching with no success.
Here is what i want to do, not sure if possible. I am in my 1st semester at school and just learned C language. I bought my arduino 4 days ago, and Ive managed to run trough a few LED exercises without a problem. What i want to do next is Communicate with my Arduino UNO from within another language, and i am familiar with C and PHP.
Here is my example code:
#define LEDR 8 //LED
#define LEDG 10 //
#define LEDB 12 //
int incomingByte = 0; // for incoming serial data
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(LEDR,OUTPUT);
pinMode(LEDG,OUTPUT);
pinMode(LEDB,OUTPUT);
Serial.print("Hello world! Arduino Loaded.\n"); // prints hello with ending line break
Serial.println("Usage: 1 = LED_R, 2 = LED_G, 3 = LED_B");
Serial.print("The value of incomingByte is " );
Serial.println(incomingByte, DEC);
}
void loop() // run over and over again
{
int R = 49; //1 = 49 in ASCII
int G = 50; //2 = 50 ASCII
int B = 51; //3 = 51 ASCII
if (Serial.available() > 0)
{
// read the incoming byte:
incomingByte = Serial.read();
Serial.flush();
// print incoming byte:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if (incomingByte == R)
{
Serial.print("Sending LED command.\n");
digitalWrite(LEDR, HIGH);
delay(500);
digitalWrite(LEDR, LOW);
delay(500);
incomingByte = 0;
}
if (incomingByte == G)
{
Serial.print("Sending LED command.\n");
digitalWrite(LEDG, HIGH);
delay(500);
digitalWrite(LEDG, LOW);
delay(500);
incomingByte = 0;
}
if (incomingByte == B)
{
Serial.print("Sending LED command.\n");
digitalWrite(LEDB, HIGH);
delay(500);
digitalWrite(LEDB, LOW);
delay(500);
incomingByte = 0;
}
if ((incomingByte != R) && (incomingByte != G) && (incomingByte != B)&& (incomingByte != 0))
{
Serial.print("Command not recognized.\n");
incomingByte = 0;
}
}
So this works just fine when i use the serial monitor built in the Arduino IDE, what i want to do is write a program in C to send receive serial information.
NOT sure if it helps but im using COM5.
Any help would be greatly appreciated.