Hi, some of you might remember this post. I fixed all the problems in the code, but there is still a problem. I have 5 switches, (you can tell from the code) 1 is an ON/OFF, and the other 4 are for controlling which maze the car should run through. I just did something simple, to test my code, which was to turn on Switch A - D, and my LCD (attached to car) would print Maze A - D, depending on the the switch I press. Here is the updated code with the non-working switches (already test swiches with LED and LCD individually):
Master Controller (tab 1):
#include <FastIO.h>
#include <I2CIO.h>
#include <LiquidCrystal_I2C_ByVac.h>
#include <LiquidCrystal_SI2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR1W.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <SI2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int ENA = 13;
const int ENB = 12;
const int IN1 = 51;
const int IN2 = 50;
const int IN3 = 53;
const int IN4 = 52;
const int SW1 = 49;
const int SW2 = 48;
const int SW3 = 47;
const int SW4 = 46;
void Move_Forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); //keep in mind that the port Output 2 has been connected with reverse terminals
digitalWrite(IN4, HIGH);
analogWrite(ENA, 75); //add more power to this wheel to avoid tada waida move forward-ing
analogWrite(ENB, 75);
delay(1500);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void setup() {
lcd.begin (20,4);
pinMode (ENA, OUTPUT);
pinMode (ENB, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
pinMode (IN3, OUTPUT);
pinMode (IN4, OUTPUT);
pinMode (SW1, INPUT);
pinMode (SW2, INPUT);
pinMode (SW3, INPUT);
pinMode (SW4, INPUT);
}
Maze A (tab 2):
#include <FastIO.h>
#include <I2CIO.h>
#include <LiquidCrystal_I2C_ByVac.h>
#include <LiquidCrystal_SI2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR1W.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <SI2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int ENA = 13;
const int ENB = 12;
const int IN1 = 51;
const int IN2 = 50;
const int IN3 = 53;
const int IN4 = 52;
const int SW1 = 49;
const int SW2 = 48;
const int SW3 = 47;
const int SW4 = 46;
void Move_Forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); //keep in mind that the port Output 2 has been connected with reverse terminals
digitalWrite(IN4, HIGH);
analogWrite(ENA, 75); //add more power to this wheel to avoid tada waida move forward-ing
analogWrite(ENB, 75);
delay(1500);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
void setup() {
lcd.begin (20,4);
pinMode (ENA, OUTPUT);
pinMode (ENB, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
pinMode (IN3, OUTPUT);
pinMode (IN4, OUTPUT);
pinMode (SW1, INPUT);
pinMode (SW2, INPUT);
pinMode (SW3, INPUT);
pinMode (SW4, INPUT);
}
Maze B (tab 3):
void maze_b() {
lcd.setCursor(7,1);
lcd.print("Maze B");
delay(3000);
}
Maze C (tab 4):
void maze_c() {
lcd.setCursor(7,1);
lcd.print("Maze C");
delay(3000);
}
Maze D (tab 5):
void maze_d() {
lcd.setCursor(7,1);
lcd.print("Maze D");
delay(3000);
}
Maze Controller (tab 6, new):
void loop() {
if (SW1 == HIGH) {
maze_a();
}
if (SW2 == HIGH) {
maze_b();
}
if (SW3 == HIGH) {
maze_c();
}
if (SW4 == HIGH) {
maze_d();
}
}
Also, just one last question: does Maze_Controller need to be the last tab? Or can it be the second tab? I am worried it wont work with the tab being 2nd, because the arduino doesn't know what maze_a() thru d is? Dunno.
Thanks!