I have an Arduino Mega clone and I haven't used it for a while. I remember it not working so when I plugged it in and tried uploading the code to it and sure enough it didn't work. So I plugged in an Uno and it worked. The Mega is a 2560 Atmel. Here's my code:
#define distanceForward A0
#define distanceLeft A1
#define distanceRight A2
#define distanceRightAngle A3
#define distanceLeftAngle A4
#define distanceBack A5
int talk = 2;
void setup() {
Serial.begin(9600);
pinMode(talk, OUTPUT);
pinMode(distanceForward, INPUT);
// /\ Ir distance sensor pin for input signal to arduino, Front Facing
pinMode(distanceLeftAngle, INPUT);
// /\ Ir distance sensor pin for input signal to arduino, Left Angle
pinMode(distanceRightAngle, INPUT);
// /\ Ir distance sensor pin for input signal to arduino, Right Angle
pinMode(distanceLeft, INPUT);
// /\ Ir distance sensor pin for input signal to arduino, Left
pinMode(distanceRight, INPUT);
// /\ Ir distance sensor pin for input signal to arduino, Right
pinMode(distanceBack, INPUT);
// /\ Ir distance sensor pin for input signal to arduino, back
}
void hall_roam() {
Serial.write("forward");
if (analogRead(distanceLeftAngle) < 30) {
Serial.write("right");
if (analogRead(distanceLeftAngle) > 30) {
Serial.write("forward");
}
if (analogRead(distanceRightAngle) < 30) {
Serial.write("left");
if (analogRead(distanceRightAngle) < 30) {
Serial.write("forward");
}
if (analogRead(distanceForward) < 60) {
Serial.write("stop");
if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) < 60)) {
Serial.write("left");
if (analogRead(distanceForward) > 60) {
Serial.write("stop");
}
}
}
if ((analogRead(distanceLeft) > 60) && (analogRead(distanceRight) > 60)) {
Serial.write("left");
if (analogRead(distanceForward) > 60) {
Serial.write("stop");
}
}
if ((analogRead(distanceLeft) > 60) && (analogRead(distanceRight) < 60)) {
Serial.write("left");
if (analogRead(distanceForward) > 60) {
Serial.write("stop");
}
}
if ((analogRead(distanceLeft) > 60) && (analogRead(distanceRight) < 60)) {
Serial.write("left");
if (analogRead(distanceForward) > 60) {
Serial.write("stop");
}
}
if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) > 60)) {
Serial.write("right");
if (analogRead(distanceForward) > 60) {
Serial.write("stop");
}
} else {
Serial.write("forward");
}
}
}
}
void roam() {
Serial.write("forward");
if (analogRead(distanceForward) < 60) {
Serial.write("stop");
Serial.write("left");
if (analogRead(distanceForward) > 60) {
Serial.write("stop");
Serial.write("forward");
}
}
}
void talkbb8() {
pinMode(talk, HIGH);
pinMode(talk, LOW);
}
void chill() {
Serial.write("stop");
talkbb8();
}
void loop() {
if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) < 60)) {
hall_roam();
} else if ((analogRead(distanceForward) < 60) && (analogRead(distanceBack) < 60)) {
Serial.write("left");
if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) < 60)) {
Serial.write("stop");
hall_roam();
}
} else {
roam();
}
}
If there's a bracket out of place or something it's probably nothing. I'm talking about the characters. Is there anything in the characters that would screw up the upload like the three "!!!" problem I heard about or something like that. It's possible that the USB chip in it isn't recognized by my iMac. If so how do I fix that?