Hi Guys,
Im new to arduino and took on a big project.
I need to control 37 IO digital pins. I am using a GUI made in C# which sends the data like this:
string data3 = "6;13;14;19;21;22;28;39;40;41;42";
sendint = data3.Split(';').Select(n => Convert.ToInt32(n)).ToArray();
sendbytes = data3.Select(x => (byte)x).ToArray();
serialPort1.Write(sendbytes, 0, sendbytes.Length);
And here is my Arduino code:
#include<Servo.h> // Serial library
#include <SPI.h> // SPI library
#include <Wire.h> // I2C library
//#define ADDRESS 0x00
int bytes;
int count = 0;
int newArray[36];
void setup() {
Serial.begin(9600); // initialize serial communication with computer
pinMode(SS, OUTPUT);
//GPIO pins for testing
pinMode(0, OUTPUT); //RX0
pinMode(1, OUTPUT); //TX0
pinMode(2, OUTPUT); //PWM2
pinMode(3, OUTPUT); //PWM3
pinMode(4, OUTPUT); //PWM4
pinMode(5, OUTPUT); //PWM5
pinMode(6, OUTPUT); //PWM6
pinMode(7, OUTPUT); //PWM7
pinMode(8, OUTPUT); //PWM8
pinMode(9, OUTPUT); //PWM9
pinMode(10, OUTPUT); //PWM10
pinMode(11, OUTPUT); //PWM11
pinMode(12, OUTPUT); //PWM12
pinMode(13, OUTPUT); //PWM13
pinMode(14, OUTPUT); //TX3
pinMode(15, OUTPUT); //RX3
pinMode(16, OUTPUT); //TX2
pinMode(17, OUTPUT); //RX2
pinMode(18, OUTPUT); //TX1
pinMode(19, OUTPUT); //RX1
pinMode(20, OUTPUT); //20
pinMode(21, OUTPUT); //21
pinMode(22, OUTPUT); //22
pinMode(23, OUTPUT); //23
pinMode(24, OUTPUT); //24
pinMode(25, OUTPUT); //25
pinMode(26, OUTPUT); //26
pinMode(27, OUTPUT); //27
pinMode(28, OUTPUT); //28
pinMode(29, OUTPUT); //29
pinMode(30, OUTPUT); //30
pinMode(31, OUTPUT); //31
pinMode(32, OUTPUT); //32
pinMode(33, OUTPUT); //33
pinMode(34, OUTPUT); //34
pinMode(35, OUTPUT); //35
pinMode(36, OUTPUT); //36
pinMode(37, OUTPUT); //37
pinMode(38, INPUT); //38 // New input for Arduino device, ill change with time
}
void loop()
{ // Establishes the HIGH/LOW state for the I/O pins
while(Serial.available() > 0)
{
bytes = Serial.read(); //- '0'; // Starts reading the buffer 1 byte at a time
newArray[bytes] = 1;
for (int j = 0; j <= 36; j++)
{
if (newArray[j] != 1)
{
newArray[j] == 0;
}
}
} // end of while loop
for(int i = 0; i <= 36; i++){
if(newArray[i] == 1){
digitalWrite(newArray[i], LOW);
}
else if (newArray[i] == 0){
digitalWrite(newArray[i], HIGH);
}
}
}
Basically, I cant seem to use the information properly.
I have an array that holds all IO pins needed. The ones that need to be turned on =1 and the ones that don't =0. Goes through a for loop to go through each index of the array and puts them in their digitalWrite().
Any help would be awesome!!
I do have a technical background so feel free to go nerdy.