PaulS:
Well, of course it will. You could study the message, and see that it is telling you that you can't have two variables of the same name.Hint:
int latch1 = 2;
int latch2 = 5;
Technically, the error is not in the upload. That happens after the compiler gets done and the linker does its job. You are causing a failure far earlier that the uploader.
Yeah your right, I should have said compiler. I always upload because it compiles for me before it shoots it out over the USB. So your saying that if I specify different latches and clocks in the code that I can divide it? I just typed that into my code and made doubles off all the "void setup" code. But by the time I got done with that, the compiler gave me an error that I don't understand. Heres my new code I just entered.
#include <MeetAndroid.h>
MeetAndroid meetAndroid;
int latch1 = 2; // set the latch pin
int clock1 = 3; // set the clock pin
int data1 = 4; // set the data pin
int latch2 = 5; // set the latch pin
int clock2 = 6; // set the clock pin
int data2 = 7; // set the data pin
int controllerData1[16]; // array to store data from 16 clock cycles
int controllerData2[16]; // array to store data from 16 clock cycles
/* SETUP */
void setup()
{
// set baud rate to 57.6k
Serial.begin(57600);
// set output/input pins
pinMode(latch1,OUTPUT);
pinMode(clock1,OUTPUT);
pinMode(data1,INPUT);
pinMode(latch2,OUTPUT);
pinMode(clock2,OUTPUT);
pinMode(data2,INPUT);
// set latch and clock high
digitalWrite(latch1,HIGH);
digitalWrite(clock1,HIGH);
digitalWrite(latch2,HIGH);
digitalWrite(clock2,HIGH);
}
/* THIS READS DATA FROM THE CONTROLLER */
void controllerRead()
{
// set latch and clock low
digitalWrite(latch1,LOW);
digitalWrite(clock1,LOW);
digitalWrite(latch2,LOW);
digitalWrite(clock2,LOW);
// set latch high to trigger controller data send
digitalWrite(latch1,HIGH);
delayMicroseconds(4);
digitalWrite(latch1,LOW);
delayMicroseconds(2);
digitalWrite(latch2,HIGH);
delayMicroseconds(4);
digitalWrite(latch2,LOW);
delayMicroseconds(2);
// Clock Cycle 1
controllerData1[0] = digitalRead(data1);
controllerData2[0] = digitalRead(data2);
// Clock Cycles 2-16
for (int i = 1; i <= 15; i++)
{
digitalWrite(clock1,HIGH);
delayMicroseconds(4);
digitalWrite(clock1,LOW);
delayMicroseconds(4);
controllerData1[i] = digitalRead(data1);
for (int i = 1; i <= 15; i++)
{
digitalWrite(clock2,HIGH);
delayMicroseconds(4);
digitalWrite(clock2,LOW);
delayMicroseconds(4);
controllerData2[i] = digitalRead(data2);
}
}
// NES Button Reference
// 01111111 - A [0]
// 10111111 - B [1]
// 11011111 - SELECT [2]
// 11101111 - START [3]
// 11110111 - UP [4]
// 11111011 - DOWN [5]
// 11111101 - LEFT [6]
// 11111110 - RIGHT [7]
// UP+RIGHT
// UP+LEFT
// DOWN+RIGHT
// DOWN+LEFT
/* MAIN LOOP */
void loop()
{
controllerRead();
String Out = "";
int length = 1;
// A
if (controllerData[0] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "QZ";
length = length + 2;
}
// B
if (controllerData[1] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "WL";
length = length + 2;
}
// SELECT
if (controllerData[2] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "EK";
length = length + 2;
}
// START
if (controllerData[3] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "UJ";
length = length + 2;
}
// UP
if (controllerData[4] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "I1";
length = length + 2;
}
// DOWN
else if (controllerData[5] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "AS";
length = length + 2;
}
// LEFT
else if (controllerData[6] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "DA";
length = length + 2;
}
// RIGHT
else if (controllerData[7] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "SI";
length = length + 2;
}
// UP+RIGHT
if (controllerData[4] == 0 && controllerData[7] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "KU";
length = length + 2;
}
// UP+LEFT
else if (controllerData[4] == 0 && controllerData[6] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "JE";
length = length + 2;
}
// DOWN+RIGHT
else if (controllerData[5] == 0 && controllerData[7] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "LQ";
length = length + 2;
}
// DOWN+LEFT
else if (controllerData[5] == 0 && controllerData[6] == 0)
{
if (Out != "")
{
Out = Out + ",";
length = length + 2;
}
Out = Out + "ZW";
length = length + 2;
}
char outData[length];
Out.toCharArray(outData, length);
meetAndroid.send(outData);
Serial.println(outData);
delay(16);
}
And heres the error it gave me.
NES_2_Controllers.cpp: In function 'void controllerRead()':
NES_2_Controllers:92: error: a function-definition is not allowed here before '{' token
NES_2_Controllers:249: error: expected `}' at end of input
The error is at the "{" below the "void loop" code line. Whats that about? Thanks again for your guys help. Later.