hi guys
please help me
I am Kishor Kumar from India Actually i am trying to One Small Project. I am using Arduino Mega 2560 Rv3 with 4 channel Relay and 4 Pushbutton. Which are using Select the Operation
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <LiquidCrystal_PCF8574.h>
#include <Button.h>
// Pin Definitions
#define PUSHBUTTON_1_PIN_2 2
#define PUSHBUTTON_2_PIN_2 3
#define PUSHBUTTON_3_PIN_2 4
#define PUSHBUTTON_4_PIN_2 5
#define RELAYMODULE4CH_PIN_IN1 6
#define RELAYMODULE4CH_PIN_IN2 7
#define RELAYMODULE4CH_PIN_IN4 9
#define RELAYMODULE4CH_PIN_IN3 8
// Global variables and defines
// There are several different versions of the LCD I2C adapter, each might have a different address.
// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints.
// To find your LCD address go to: http://playground.arduino.cc/Main/I2cScanner and run example.
#define LCD_ADDRESS 0x3F
#define LCD_ADDRESS 0x27
// Define LCD characteristics
#define LCD_ROWS 2
#define LCD_COLUMNS 16
#define SCROLL_DELAY 150
#define BACKLIGHT 255
//define an array for the 4ch relay module pins
int RelayModule4chPins[] = { RELAYMODULE4CH_PIN_IN1, RELAYMODULE4CH_PIN_IN2, RELAYMODULE4CH_PIN_IN3, RELAYMODULE4CH_PIN_IN4 };
// object initialization
LiquidCrystal_PCF8574 lcdI2C(0x27);
Button pushButton_1(PUSHBUTTON_1_PIN_2);
Button pushButton_2(PUSHBUTTON_2_PIN_2);
Button pushButton_3(PUSHBUTTON_3_PIN_2);
Button pushButton_4(PUSHBUTTON_4_PIN_2);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println(“start”);
// initialize the lcd
lcdI2C.begin(0x00,2,16);
pushButton_1.init();
pushButton_2.init();
pushButton_3.init();
pushButton_4.init();
pinMode(RELAYMODULE4CH_PIN_IN1, OUTPUT);
pinMode(RELAYMODULE4CH_PIN_IN2, OUTPUT);
pinMode(RELAYMODULE4CH_PIN_IN3, OUTPUT);
pinMode(RELAYMODULE4CH_PIN_IN4, OUTPUT);
menuOption = menu();
}
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
if(menuOption == '1') {
// LCD 16x2 I2C - Test Code
// The LCD Screen will display the text of your choice.
lcdI2C.clear(); // Clear LCD screen.
lcdI2C.print(" Circuito.io "); // Print print String to LCD on first line
lcdI2C.selectLine(2); // Set cursor at the begining of line 2.<<<<< Here i am getting Problem
lcdI2C.print(" Rocks! "); // Print print String to LCD on second line
delay(1000);
}
else if(menuOption == '2') {
// Mini Pushbutton Switch #1 - Test Code
//Read pushbutton state.
//if button is pressed function will return HIGH (1). if not function will return LOW (0).
//for debounce funtionality try also pushButton_1.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_1Val = pushButton_1.read();
Serial.print(F("Val: ")); Serial.println(pushButton_1Val);
}
else if(menuOption == '3') {
// Mini Pushbutton Switch #2 - Test Code
//Read pushbutton state.
//if button is pressed function will return HIGH (1). if not function will return LOW (0).
//for debounce funtionality try also pushButton_2.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_2Val = pushButton_2.read();
Serial.print(F("Val: ")); Serial.println(pushButton_2Val);
}
else if(menuOption == '4') {
// Mini Pushbutton Switch #3 - Test Code
//Read pushbutton state.
//if button is pressed function will return HIGH (1). if not function will return LOW (0).
//for debounce funtionality try also pushButton_3.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_3Val = pushButton_3.read();
Serial.print(F("Val: ")); Serial.println(pushButton_3Val);
}
else if(menuOption == '5') {
// Mini Pushbutton Switch #4 - Test Code
//Read pushbutton state.
//if button is pressed function will return HIGH (1). if not function will return LOW (0).
//for debounce funtionality try also pushButton_4.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_4Val = pushButton_4.read();
Serial.print(F("Val: ")); Serial.println(pushButton_4Val);
}
else if(menuOption == '6') {
// Relay Module 4-Ch - Test Code
//This loop will turn on and off each relay in the array for 0.5 sec
for (int i = 0; i < 4; i++) {
digitalWrite(RelayModule4chPins[i],HIGH);
delay(500);
digitalWrite(RelayModule4chPins[i],LOW);
delay(500);
}
}
if (millis() - time0 > timeout)
{
menuOption = menu();
}
}
// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{
Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) LCD 16x2 I2C"));
Serial.println(F("(2) Mini Pushbutton Switch #1"));
Serial.println(F("(3) Mini Pushbutton Switch #2"));
Serial.println(F("(4) Mini Pushbutton Switch #3"));
Serial.println(F("(5) Mini Pushbutton Switch #4"));
Serial.println(F("(6) Relay Module 4-Ch"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());
// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{
if(c == '1')
Serial.println(F("Now Testing LCD 16x2 I2C"));
else if(c == '2')
Serial.println(F("Now Testing Mini Pushbutton Switch #1"));
else if(c == '3')
Serial.println(F("Now Testing Mini Pushbutton Switch #2"));
else if(c == '4')
Serial.println(F("Now Testing Mini Pushbutton Switch #3"));
else if(c == '5')
Serial.println(F("Now Testing Mini Pushbutton Switch #4"));
else if(c == '6')
Serial.println(F("Now Testing Relay Module 4-Ch"));
else
{
Serial.println(F("illegal input!"));
return 0;
}
time0 = millis();
return c;
}
}
}