I am attempting to make a recreation of a childhood toy BigTrack. I am using arduino uno, 4 x 4 keypad, a LCD and a motor driver. The code I am attaching is by no means complete. I am trying to get 1 command working at a time and also I'm self taught so go easy on me please. My problem now occurs on line 189 and is "incompatible types in assignment of 'int' to 'int [10]'" I'm not sure how to fix this. Any help would be appreciated.
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
enum pageType { Main_Menu, Menu_2, Fwd, Rev, LTurn, RTurn, Pause, Beep, Run,};
enum pageType currPage = Main_Menu;
byte data_count = 0;
const byte ROWS = 4;
const byte COLS = 4;
char Forward;
char Reverse;
char LeftTurn;
char RightTurn;
char PauseTime;
char BeepTime;
int O = 0;
int Time;
int revAmount;
int revRun[10];
int b = 0;
int fwdAmount;
int fwdRun[10];
int x = 0;
int leftAmount;
int leftRun[10];
int l = 0;
int rightAmount;
int rightRun[10];
int r = 0;
int runOrder[10][10];
int d= 0;
int runDir[10];
int runDur[10];
int motor1pin1 = 10; // pin assignment for motors
int motor1pin2 = 13;
int motor2pin1 = 11;
int motor2pin2 = 12;
char hexaKeys[ROWS][COLS] = { // array for keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}};
byte rowPins[ROWS] = {9, 8, 7, 6}; // pin assignments for keypad
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad =
Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd =
LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,20,4) for 20x4 LCD.
// ==============================================================================
// || SETUP LOOP ||
// ==============================================================================
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
// Initiate the LCD:
lcd.init();
lcd.backlight();
lcd.clear();
}
// ==============================================================================
// || MAIN LOOP ||
// ==============================================================================
void loop() {
// put your main code here, to run repeatedly:
switch (currPage) { // start menu system
case Main_Menu:
page_Main_Menu();
break;
}
}
// ==============================================================================
// || PAGE MAIN MENU called from void loop ||
// ==============================================================================
void page_Main_Menu() { // print menu
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" MAIN MENU");
lcd.setCursor(0, 1);
lcd.print("1. FWD 2. REV");
lcd.setCursor(0, 2);
lcd.print("3. LTURN 4. RTURN");
lcd.setCursor(0, 3);
lcd.print("5. NEXT #. RUN");
char customKey = customKeypad.waitForKey();
if (customKey) { // get input from menu
switch (customKey) {
case '1':
page_Fwd();
break;
case '2':
page_Rev();
break;
case '3':
page_LTurn();
break;
case '4':
page_RTurn();
break;
case '5':
page_Menu_2();
break;
case '#':
page_Run();
break;
default:
lcd.clear();
lcd.setCursor(8, 0);
lcd.print("Error");
delay(2000);
currPage = Main_Menu;
break;
}
}
}
// ==============================================================================
// || PAGE MENU 2 called from Main Menu ||
// ==============================================================================
void page_Menu_2() { // print menu
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" MENU 2");
lcd.setCursor(0, 1);
lcd.print("6. BEEP 7. PAUSE");
lcd.setCursor(0, 2);
lcd.print("8. 9. ");
lcd.setCursor(0, 3);
lcd.print("B. BACK #. RUN");
char customKey = customKeypad.waitForKey();
if (customKey) { // get input from menu
switch (customKey) {
case '6':
page_Beep();
break;
case '7':
page_Pause();
break;
case 'B':
page_Main_Menu();
break;
case '#':
page_Run();
break;
default:
lcd.clear();
lcd.setCursor(8, 0);
lcd.print("Error");
delay(2000);
currPage = Menu_2;
break;
}
}
}
// ==============================================================================
// || PAGE FORWARD called from main menu ||
// ==============================================================================
void page_Fwd() { // print menu
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Distance in Feet");
lcd.setCursor(6, 1);
lcd.print(" 1 to 9");
lcd.setCursor(9, 2);
lcd.blink();
char Forward = customKeypad.waitForKey();
if (Forward >= '0' && Forward <= '9') { // weed out unavailable input
fwdRun[x] = Forward;
runDir[x] = 'F';
runDur[x] = fwdRun[x];
lcd.noBlink();
runOrder[0] = 0;
// lcd.clear();
//lcd.print( runOrder[0] + runOrder[1]);
// delay(2000);
x++;
O++;
}
else {
lcd.setCursor(9, 2);
lcd.print("Error");
delay(2000);
lcd.clear();
page_Fwd();
}
}
// ==============================================================================
// || PAGE REVERSE ||
// ==============================================================================
void page_Rev() { // print menu
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Distance in Feet");
lcd.setCursor(6, 1);
lcd.print(" 1 to 9");
lcd.setCursor(9, 2);
lcd.blink();
char Reverse = customKeypad.waitForKey();
if (Reverse >= '0' && Reverse <= '9') { // weed out unavailable input
lcd.print(Reverse); // get entry converet to int and pass to array
delay(1000);
revAmount = Reverse - '0';
revRun[b] = revAmount;
runDir[b] = 'B';
runDur[b] = revRun[b];
lcd.noBlink();
b++;
}
else {
lcd.setCursor(9, 2);
lcd.print("Error");
delay(2000);
currPage = Rev;
}
}
// ==============================================================================
// || PAGE LEFT TURN ||
// ==============================================================================
void page_LTurn() {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Direction in Degrees");
lcd.setCursor(6, 1);
lcd.print(" 1 to 359");
lcd.setCursor(9, 2);
lcd.blink();
char LeftTurn = customKeypad.waitForKey();
if (LeftTurn >= '0' && LeftTurn <= '9') { // weed out unavailable input
lcd.print(LeftTurn); // get entry converet to int and pass to array
delay(1000);
leftAmount = LeftTurn - '0';
leftRun[l] = leftAmount;
runDir[l] = 'L';
runDur[l] = leftRun[l];
lcd.noBlink();
l++;
}
else {
lcd.setCursor(9, 2);
lcd.print("Error");
delay(2000);
currPage = LTurn;
}
}
// ==============================================================================
// || PAGE RIGHT TURN ||
// ==============================================================================
void page_RTurn() {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Direction in Degrees");
lcd.setCursor(6, 1);
lcd.print(" 1 to 359");
lcd.setCursor(9, 2);
lcd.blink();
char LeftTurn = customKeypad.waitForKey();
if (RightTurn >= '0' && RightTurn <= '9') { // weed out unavailable input
lcd.print(RightTurn); // get entry converet to int and pass to array
delay(1000);
rightAmount = RightTurn - '0';
rightRun[r] = rightAmount;
runDir[r] = 'R';
runDur[r] = rightRun[r];
lcd.noBlink();
r++;
}
else {
lcd.setCursor(9, 2);
lcd.print("Error");
delay(2000);
currPage = RTurn;
}
}
// ==============================================================================
// || PAGE PAUSE ||
// ==============================================================================
void page_Pause() {}
// ==============================================================================
// || PAGE BEEP ||
// ==============================================================================
void page_Beep() {}
// ==============================================================================
// || PAGE RUN called from menus ||
// ==============================================================================
void page_Run() {
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("RUN PROGRAM");
delay(2000);
if (runOrder[d] == 70){ //ascii for F
runDur[d] = (runDur[d] * 2000);
forwardRun();
d = (d+1);
}
else if (runOrder[d] == 66){ //ascii for B
runDur[d] = (runDur[d] * 2000);
reverseRun();
d = (d+1);
}
else if (runOrder[d] == 76){ //ascii for L
runDur[d] = (runDur[d] * 2000);
LTurnRun();
d = (d+1);
}
else if (runOrder[d] == 82){ //ascii for R
runDur[d] = (runDur[d] * 2000);
RTurnRun();
d = (d+1);
}
else{
x = 0;
b = 0;
l = 0; // reset variables to 0
r = 0;
lcd.clear();
lcd.print ("fwd run variable is");
lcd.print (fwdRun[d]);
delay(2000);
memset(fwdRun, '\0', 10 * sizeof(char)); // clear arrays
memset(revRun, '\0', 10 * sizeof(char));
memset(runDir, '\0', 10 * sizeof(char));
memset(runDur, '\0', 10 * sizeof(char));
currPage = Main_Menu;
}
}
// ==============================================================================
// || PAGE forward run called from Run ||
// ==============================================================================
void forwardRun() {
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("FORWARD ");
digitalWrite(motor1pin1, LOW); // turn motor on
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
Time = runDur[0];
delay(Time); // TIME MOTOR RUNS
digitalWrite(motor1pin1, LOW); // turn motor off
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
}
// ==============================================================================
// || PAGE reverse run called from Run ||
// ==============================================================================
void reverseRun(){
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("REVERSE ");
digitalWrite(motor1pin1, HIGH); // turn motor on
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
Time = runDur[0];
delay(Time); // TIME MOTOR RUNS
digitalWrite(motor1pin1, LOW); // turn motor off
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
}
// ==============================================================================
// || PAGE LTurn run called from Run ||
// ==============================================================================
void LTurnRun(){
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("LEFT TURN ");
digitalWrite(motor1pin1, LOW); // turn motor on
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
Time = runDur[0];
delay(Time); // TIME MOTOR RUNS
digitalWrite(motor1pin1, LOW); // turn motor off
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
}
// ==============================================================================
// || PAGE RTurn run called from Run ||
// ==============================================================================
void RTurnRun(){
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("RIGHT TURN ");
digitalWrite(motor1pin1, HIGH); // turn motor on
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
Time = runDur[0];
delay(Time); // TIME MOTOR RUNS
digitalWrite(motor1pin1, LOW); // turn motor off
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
}