Hi Folks,
I'm in the process of developing a cross plaform interface for the arduino using Runtime Revolution programming environment. Unfortunately I don't know C and this is limiting what I'm able to do on the Arduino side. At the moment I have coded to set all Analogue pins to output, and all digital to input. You will see from my code that I've done this in a very primitive way but it's all I know. The problem is that when I send to the Arduino it responds very inconsistently. I'm guessing that a lot of the data sent is getting lost because of my poor programming in C.
Any help or advice would be greatly appreciated.
Best
Jim H
#include <stdlib.h>
char buffer[4];
int received;
int analogValue = 0;
int analogValue1 = 1;
int analogValue2 = 2;
int analogValue3 = 3;
int analogValue4 = 4;
int analogValue5 = 5;
int outputPin2 = 2;
int outputPin4 = 4;
int outputPin7 = 7;
int outputPin8 = 8;
int outputPin12 = 12;
int outputPin13 = 13;
int pwmPin9 = 9;
int val;
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
received = 0;
buffer[received] = '\0';
pinMode(outputPin2, OUTPUT);
pinMode(outputPin4, OUTPUT);
pinMode(outputPin7, OUTPUT);
pinMode(outputPin8, OUTPUT);
pinMode(pwmPin9, OUTPUT);
pinMode(outputPin12, OUTPUT);
pinMode(outputPin13, OUTPUT);
}
void loop() {
// read the analog input on pin 0:
analogValue = analogRead(0);
Serial.print("@");
Serial.println(analogValue);
analogValue1 = analogRead(1);
Serial.print("*");
Serial.println(analogValue1);
analogValue2 = analogRead(2);
Serial.print("$");
Serial.println(analogValue2);
analogValue3 = analogRead(3);
Serial.print("%");
Serial.println(analogValue3);
analogValue4 = analogRead(4);
Serial.print("^");
Serial.println(analogValue4);
analogValue5 = analogRead(5);
Serial.print("!");
Serial.println(analogValue5);
if (Serial.available()) {
buffer[received++] = Serial.read();
buffer[received] = '\0';
if (received >= (sizeof(buffer)-1))
{
int myInt = atoi(buffer);
analogWrite(pwmPin9, myInt);
received = 0;
}
val = Serial.read();
if (val == 'V') {
digitalWrite(outputPin2, HIGH);
}
if (val == 'F') {
digitalWrite(outputPin4, HIGH);
}
if (val == 'Y') {
digitalWrite(outputPin7, HIGH);
}
if (val == 'H') {
digitalWrite(outputPin8, HIGH);
}
if (val == 'W') {
digitalWrite(outputPin12, HIGH);
}
if (val == 'E') {
digitalWrite(outputPin13, HIGH);
}
if (val == 'B') {
digitalWrite(outputPin2, LOW);
}
if (val == 'G') {
digitalWrite(outputPin4, LOW);
}
if (val == 'T') {
digitalWrite(outputPin7, LOW);
}
if (val == 'L') {
digitalWrite(outputPin8, LOW);
}
if (val == 'Q') {
digitalWrite(outputPin12, LOW);
}
if (val == 'R') {
digitalWrite(outputPin13, LOW);
}
}
}