In this below programme: i am facing a problem while trigger button on the loop() function.
it should display "CHECK CONTINUITY" on LCD and play "2.wav" simultaneously which is not happening.
instead of that it only displays the message "CHECK CONTINUITY" on LED . when next time hit the button. it play the "2.wav" file than execute the "p==2" condition.
can anyone suggest to me. I am new to this field.
//YWROBOT
//Comible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#define SD_ChipSelectPin 4
#include <TMRpcm.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo
TMRpcm tmrpcm;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
int L1 = 8;
int L2 = 6;
int L3 = 5;
int L4 = 3;
int L5 = 2; //5 LED pin
int buttonPin = 7; //the number of the pushbutton pin
int de=50; // delay time
int p=0; // variable for patten
int buttonState = 0; //variable for reading the pushbutton status
void setup()
{
lcd.init(); // initialize the lcd
lcd.init(); // Print a message to the LCD.
Serial.begin(9600);
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
pinMode(L5, OUTPUT);
pinMode(buttonPin, INPUT);
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)){
Serial.println("SD fail");
return;
}
myservo.attach(10); // attaches the servo on pin 10 to the servo object
lcd.backlight();
lcd.setCursor(6,0);
lcd.print("HELLO");
lcd.setCursor(0,1);
lcd.print("TALKING DISCHARGE ROD");
lcd.setCursor(4,2);
lcd.print("WELCOMES YOU");
lcd.setCursor(0,3);
lcd.print("PLEASE FOLLOW INST..");
delay(5000);
lcd.clear();
tmrpcm.setVolume(6);
tmrpcm.play("1.wav");
lcd.setCursor(1,1);
lcd.print("USE ELECTRICAL PPE");
delay(de);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
p++;
delay(2000);
}
if(p == 1)
{
lcd.clear();
lcd.setCursor(2,1);
lcd.print("CHECK CONTINUTY");
tmrpcm.setVolume(5);
tmrpcm.play("2.wav");
delay(de);
}
if(p == 2)
{
digitalWrite(L1,1);
digitalWrite(L2,0);
digitalWrite(L3,0);
digitalWrite(L4,0);
digitalWrite(L5,0); //1
tmrpcm.setVolume(5);
tmrpcm.play("3.wav");
delay(de);
lcd.clear();
lcd.setCursor(3,1);
lcd.print("CONNECT CLAMP");
lcd.setCursor(2,2);
lcd.print("WITH EARTH STRIP");
delay(de);
}
if(p == 3)
{
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,0);
digitalWrite(L4,0);
digitalWrite(L5,0); //2
tmrpcm.setVolume(5);
tmrpcm.play("4.wav");
delay(de);
lcd.clear();
lcd.setCursor(2,1);
lcd.print("CHECK NO VOLTAGE");
delay(de);
}
if(p == 4)
{
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,1);
digitalWrite(L4,0);
digitalWrite(L5,0); //3
tmrpcm.setVolume(5);
tmrpcm.play( "5.wav");
delay(de);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("WE ARE GOOD TO GO");
lcd.setCursor(1,1);
lcd.print("FOR SAFE DISCHARGE");
lcd.setCursor(6,2);
lcd.print("PLEASE");
lcd.setCursor(1,3);
lcd.print("OPERATE THE LIVER");
delay(de);
}
if(p == 5)
{
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,1);
digitalWrite(L4,1);
digitalWrite(L5,0); //4
delay(de);
}
if(p == 6)
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,1);
digitalWrite(L4,1);
digitalWrite(L5,1); //5
delay(de);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}