Arduino melody loop? - arduino

This is my code and everything works fine except that i don't know how to get the melody i've created to loop? Another question is how do i get the LED to flash simultaneously as the melody plays?
#include "pitches.h"
int led = 9;
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4
};
int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };
void setup() {
pinMode(led, OUTPUT);
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}

simply put your code inside a standalone function, and call it from within loop:
#include "pitches.h"
int led = 9;
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4
};
int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };
void play_melody();
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
// keep the LED on while the melody's playing
play_melody();
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
// pause for one second between each melody iteration (you can remove this for continuous playing)
delay(1000);
}
void play_melody() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
return;
}
If you don't know about function callings, I suggest you to open a C language book like the K&R, and read it, there's a lot to learn for you in it about the basics of C language programming.

在loop()內播放音樂,同時;在Timer中斷程式callback()內控制LED閃爍
例: Timer1.attachInterrupt(callback);
Playing the melody in the loop() function and blinking LED in the timer interrup function at the same time.
ex: Timer1.attachInterrupt(callback);

Related

Arduino Automatic Clothes Line : How can I make my meet the different criteria?

So I'm a novice in programming and is helping my friend with coding an automatic clothes line for a project.
Each component works fine individually but when I put all the code together the motors are confused in which direction to go. can anyone take a look at it and give us feedback?
We have a rain sensor, light sensor, 2 switches , and a motor.
When it rains OR when it is dark the motors pulls the clothes in and when the the clothes reaches the end it touches switch 1 and stops the motors.
When it stop rains/sunny AND/OR when there light it pulls the clothes out in the open.
Here is the code I was provided:
**
#include <Stepper.h>
//motors
const int stepsPerRevolution = 400;
//motor speeds
Stepper myStepper = Stepper(stepsPerRevolution, 2,4, 3, 5);//clockwise
Stepper myStepper2 = Stepper(stepsPerRevolution, 5, 3, 4, 2);//counterclockwise
//rain sensor
const int capture_D =4;
const int capture_A = A0;
int val_analogique;
int led = 8;
//switches
const int switch1 = A3;
const int switch2 =A4;
void setup() {
// put your setup code here, to run once:
// motors
myStepper.setSpeed(60);
myStepper2.setSpeed(60);
//rain sensor
pinMode(capture_D, INPUT);
pinMode(capture_A, INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
//light sensors
unsigned int AnalogValueL;
AnalogValueL = analogRead(A5);
Serial.println(AnalogValueL);
delay(2000);
//rainsensor
if((digitalRead(capture_A) && digitalRead(capture_D)) ==LOW)
{
digitalWrite(led, HIGH);
myStepper2.step(stepsPerRevolution); // bringclothesout
Serial.println("DRY");
delay(1000);
}
else
{
//when it rains the clolthes re brought in
digitalWrite(led, LOW);
Serial.println("WET");
myStepper.step(stepsPerRevolution);//bring clothes in
delay(1000);
}
if(AnalogValueL < 1010)
{
digitalWrite(led, HIGH);
Serial.println("SUNNY");
myStepper2.step(stepsPerRevolution);
delay(1000);
}
else
{
digitalWrite(led, LOW);
Serial.println("Dark");
myStepper.step(stepsPerRevolution);
delay(1000);
}
//switches
unsigned int AnalogValueS;
AnalogValueS = analogRead(switch1);
Serial.println(AnalogValueS);
delay(2000);
if(AnalogValueS <= 1000)
{
digitalWrite(led, HIGH);
Serial.println("Off");
myStepper.setSpeed(0);
}
else
{
digitalWrite(led, LOW);
Serial.println("on");
}
unsigned int AnalogValueSS;
AnalogValueSS = analogRead(switch2);
Serial.println(AnalogValueSS);
delay(2000);
if(AnalogValueSS <= 1000)
{
digitalWrite(led, HIGH);
Serial.println("ON");
}
else
{
digitalWrite(led, LOW);
Serial.println("Off");
}
*/
}//end of program
**
Feedback?
Here's my feedback:
Your code needs a little bit of tidying up for the sake of clarity and readability.
It is always recommended to declare your Serial.begin(); at the beginning of the setup() function.
You forgot to declare the switches pins as inputs:
pinMode(switchX, INPUT); // where X = 1, 2
Why are you using analog pins as switch inputs? (const int switch1 = A3). If you are connecting ON/OFF switches here you should rather use digital pins. In case your switches are the light sensors, then they are fine (read comment 9 below). Otherwise, this:
AnalogValueS = analogRead(switch1);
is wrong as you cannot read a digital switch with an analogRead()
Additionally, you don't say if your switches are active HIGH or active LOW, namely, if they pulse LOW when pressed and HIGH when released or viceversa.
One important mistake is that you are assigning pin 4 twice for different functions. First as a motor pin, then as capture_D:
Stepper myStepper = Stepper(stepsPerRevolution, 2, 4, 3, 5);
Stepper myStepper2 = Stepper(stepsPerRevolution, 5, 3, 4, 2);
const int capture_D = 4;
You read the analog value in a variable declared inside the main() loop while you previously declared int val_analogique without using it. This is poor consistency.
Similarly, you read from analog pin A5 without previously declaring it as an INPUT:
AnalogValueL = analogRead(A5);
The flow of your loop could be affected by that many delay() throughout the code.
You expressed having three sensors:
We have a rain sensor, light sensor, 2 switches, and a motor.
It is good practice to label the pins from these sensors with a representative name from the sensor in question: e.g.:
const int lightSensor1 = 4;
In the C++ mindset is common practice to use enums to define states from a specific event or scenario. For instance:
typedef enum {
RAINING,
DARK,
NOT_RAINING,
SUNNY
}WEATHER_CONDITIONS;
WEATHER_CONDITIONS currentCondition = SUNNY;
where the typedef means that you are creating your own data type WEATHER_CONDITIONS and their assigned values are 0,1, 2,... according to their order.
With regards to the Stepper.h library you are declaring two Stepper instances expecting that in that way you will reverse the direction of the motor. That is NOT how it works. According to the library (Stepper.cpp) to reverse the motor, you need to send a negative value as an argument to reverse its direction. Please read line 184 from this file from the library.
On this line:
if((digitalRead(capture_A) && digitalRead(capture_D)) ==LOW)
you are attempting to read a digital value from an analog pin. While it might work if the voltage on that pin is at a logic level, this is not recommended.
Finally, you SHOULD connect the switches for stopping the motor to INTERRUPT pins. This is a more effective way to detect when the switch has been pressed and take immediate action by changing a state. You would have to use pins 2 and 3 (INT0 and INT1).
This is my take on this code. Compiled correctly but UNTESTED!
#include <Arduino.h>
#include <Stepper.h>
/*Constants*/
//motor speeds
const int stepsPerRevolution = 400;
/*Pinout declarations*/
// Motor pins
const int motorPins[4] = {2, 3, 4, 5};
//rain sensor
const int capture_D = 4; // capture_D
const int capture_A = A0; // A0
const int lightSensor = A5;
//switches
const int switch1 = 9; // Previously: A3 So this is an analog switch?
const int switch2 = 10; // Previously: A4 You should assing this to other two digital pins
//Led
const int led = 8;
/*Custom variables*/
typedef enum {
DARK,
SUNNY
} LIGHT_CONDITIONS;
LIGHT_CONDITIONS lightState = SUNNY;
const char* lightLabels[] = {"DARK",
"SUNNY"};
typedef enum {
DRY,
WET
} HUMIDITY_CONDITIONS;
HUMIDITY_CONDITIONS humidityState = DRY;
const char* humidityLabels[] = {"DRY",
"WET"};
typedef enum {
CW, // Let's assume that this is bring them in
CCW, // this is take them out
STOP
} MOTOR_DIRECTION;
MOTOR_DIRECTION currentDirection = STOP; // This declares a default state
const char* directionLabels[] = {"Clothes In",
"Clothes Out"};
/*General variables*/
int rawLightValue;
// Objects declaration
Stepper myStepper = Stepper(stepsPerRevolution,
motorPins[0],
motorPins[1],
motorPins[2],
motorPins[3]);
void activateMotor(int direction) {
switch (direction) {
case MOTOR_DIRECTION::CW:
myStepper.step(-stepsPerRevolution);
currentDirection = CW;
break;
case MOTOR_DIRECTION::CCW:
myStepper.step(stepsPerRevolution);
currentDirection = CCW;
break;
case MOTOR_DIRECTION::STOP:
currentDirection = STOP;
myStepper.step(0);
break;
default:
// so much empty
break;
}
}
void setup() {
Serial.begin(9600);
// motors
myStepper.setSpeed(60);
//rain sensor
pinMode(capture_D, INPUT);
pinMode(capture_A, INPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(lightSensor, INPUT);
pinMode(led, OUTPUT);
}
void loop() {
// First, read light sensor
rawLightValue = analogRead(lightSensor);
Serial.println(rawLightValue);
if (rawLightValue < 1010) {
digitalWrite(led, HIGH);
lightState = SUNNY;
Serial.println(lightLabels[lightState]);
} else {
digitalWrite(led, LOW);
lightState = DARK;
Serial.println(lightLabels[lightState]);
}
// Then read rain sensor --> digital portion only, granted that you have calibrated
// its pulsing voltage corectly. I am assuming that you are using one of these sensors:
// https://circuitdigest.com/microcontroller-projects/rain-detector-using-arduino
if (digitalRead(capture_D) == LOW) {
digitalWrite(led, HIGH);
humidityState = DRY;
Serial.println(humidityLabels[humidityState]);
}
else {
//when it rains the clolthes re brought in
digitalWrite(led, LOW);
humidityState = WET;
Serial.println(humidityLabels[humidityState]);
}
// Based on these conditions, activate the motor accordingly
/* When it rains OR when it is dark the motors pulls the clothes in and when
the the clothes reaches the end it touches switch 1 and stops the motors.
*/
if ((humidityState == WET) || (lightState == DARK)) {
// While the switch is released, meaning that the switch has NOT been pressed:
while (digitalRead(switch1) == HIGH) {
activateMotor(CCW);
Serial.println(directionLabels[currentDirection]);
}
// Finally, let the motors go until the swithces tell the system to stop the motor
activateMotor(STOP);
}
if ((humidityState == DRY) && (lightState == SUNNY)) {
// While the switch is released, meaning that the switch has NOT been pressed:
while (digitalRead(switch2) == HIGH) {
activateMotor(CW);
Serial.println(directionLabels[currentDirection]);
}
// Finally, let the motors go until the swithces tell the system to stop the motor
activateMotor(STOP);
}
}

speed,time,cycle and direction stepper motor by arduino

I want my stepper motor to run at a specified speed for a specified time and stop for a set time and then repeat the same cycle.
In fact, the number of times the user has to do this will determine the user
I have the last code that failed, but this is not working properly for more than 30 seconds and the steppper motor rotates permanently.
#include <Stepper.h>
const int stepPin = 6; //PUL -Pulse
const int stepsPerRevolution = 1600;
const int dirPin = 7; //DIR -Direction
const int enPin = 8; //ENA -Enable
int one = 30000;//user input
int c = 2;// user input
int rpm = 1200;//user input
unsigned long t = 0;
Stepper myStepper(stepsPerRevolution, 6, 7);
void setup() {
Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
myStepper.setSpeed(rpm);
}
void loop() {
Cycle();
digitalWrite(enPin, HIGH);
}
void Cycle() {
int cycle = 1;
for (cycle ; cycle <= c; cycle++) {
t = millis();
while ((millis() - t) < one) {
myStepper.step(stepsPerRevolution);//counter clockwise rotation
}
delay(3000);
}
}
int one = 30000;//user input
If you're going to use an int as your timing variable, then you need to look up what is the maximum value that an int can hold on your particular board. If you're using something like an UNO or a Mega then that's 32767 and that will probably explain why it doesn't work with anything over about 32 seconds.

How can I make an LED blink every n seconds without developing a lag?

I'm using an Arduino Uno to control LED. I want the LED to turn on every m seconds and remain ON for n seconds.
I've tried this code using the delay() function (by adding delays after LED is turned ON and OFF) and also using the millis() function (by keeping a track of the time passed since the previous event - ON/OFF). However, in both the approaches, the LED develops a lag of ~1 second after a few (!10) iterations of the ON-OFF cycle. What can I do to increase the accuracy of the time at which the events occur?
int led = 13;
long experimentTime = 240000;
long ledOFFDuration = 8000;
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
for (int i = 0; i < 100; i++){
digitalWrite(led, HIGH);
delay(10000);
digitalWrite(led, LOW);
delay(10000);
}
}
I've also tried using the watchdog timer (shown below). However, it has the same issue:
#include <avr/wdt.h>
int led = 13;
volatile byte watchDogState = 0b01000000;
volatile int counter = 0;
int counterMax = 5;
bool state = 1;
void setup() {
// put your setup code here, to run once:
wdt_disable();
pinMode(led, OUTPUT);
digitalWrite(led, 1);
setWDT(watchDogState);
}
void loop() {
// put your main code here, to run repeatedly:
// if (time_elapsed == 40){
//state = !state;
//}
}
void setWDT(byte sWDT){
WDTCSR |= 0b00011000;
WDTCSR = sWDT | WDTO_2S;
wdt_reset();
}
ISR (WDT_vect){
counter++;
if (counter >= counterMax){
state = !state;
digitalWrite(led, state);
counter = 0;
}
}
I tried using the port registers directly to avoid using digitalWrite completely. But that doesn't work either. There's a lag of ~5s after 20 minutes using the following code:
int led = 13;
int m = 10;
int n = 10;
boolean on;
long change;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
long now = millis();
if (!on && change < now) {
on = true; //led is now on
change = now + n*1000; //turn off in <n> seconds
PORTB |= B00100000;
}
else if (on && change < now){
on = false; //led is now off
change = now + m*1000; //turn on in <m> seconds
PORTB &= B11011111; // Set pin 4 to 0
}
}
The lag is caused by the digitalWrite-calls. Your processing application waits until digitalWrite has finished and this may take 0.05 seconds or so. To fix your problem I would save the current time in milliseconds.
int led = 13;
int m = 24;
int n = 8;
boolean on;
long change;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
long now = System.currentTimeMillis();
if (!on && change < now) { //led is off and time for change has come
on = true; //led is now on
change = += n*1000; //turn off in <n> seconds
digitalWrite(led, HIGH); //turn on led
} else if (on && change < now) { //led is on and time for change has come
on = false; //led is now off
change = += m*1000; //turn on in <m> seconds
digitalWrite(led, LOW); //turn off led
}
}
the lamp will now instantly turn on on startup, wait n seconds, turn off, wait m seconds and restart from the beginning.
If you want to create a delay at the beginning so that the lamp doesn't get turned on immediately you can simply add this to your setup-function:
change = now + SECONDS*1000;
EDIT
You pointed out that it still gives you lag.
One problem might be that loop() is not run every millisecond. So I maybe got a solution for you.
Replace the following two lines:
change = now + n*1000; //turn off in <n> seconds
...
change = now + m*1000; //turn on in <m> seconds
to this:
change += n*1000; //turn off in <n> seconds
...
change += m*1000; //turn on in <m> seconds
Now it won't take the current time anymore which means that even if loop is only run every second or two it should still not cause any lag.
If this won't work I'm afraid it looks like the timer on the arduino might not be the most precise one. If this is the case try to measure the exact offset and then create a miltiplicator for the time.

Arduino fan controller code issues (LM35)

I got an issue with the PWM signal on the fan, it actually gets to 100% right away when it hits 21°C when it should be on 10%. I don't think it's a circuit issue, so any suggestions on the code ? I am pretty sure the problem is somewhere at the Map function, just can't seem to figure it out.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 20; // the temperature to start the fan
int tempMax = 30; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
Serial.begin(9600);
}
void loop() {
temp = readTemp(); // get the temperature
if(temp < tempMin) { // if temp is lower than minimum temp
fanSpeed = 0; // fan is not spinning
digitalWrite(fan, LOW);
}
if((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 115, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
if(temp > tempMax) { // if temp is higher than tempMax
digitalWrite(led, HIGH); // turn on led
} else { // else turn off led
digitalWrite(led, LOW);
}
lcd.print("TEMP: ");
lcd.print(temp,1); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(500);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return (temp * 0.48828125)-48;
}
Ok so apparently there was a problem with this specific pin, i tried another one (PWM), and it worked perfectly!

arduino interrupts with servo motor

currently am working on project to open a door with access code using arduino UNO and a servo motor. Normal operation requires entering access code using keypad which is working fine. Another option requires pressing a button that causes an interrupt to rotate the servo motor. My problem is my interrupt only works once and never works again. Plus how do i put the for-loop to rotate the servo motor inside the interrupt function with a delay. I know that is not possible but am calling another function that has the delayMicroseconds but all this is not working. Below is my implementation please help
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
Servo servo;
const int openButtonPin = 2;
void setup() {
// put your setup code here, to run once:
servo.attach(5);
pinMode(openButtonPin, INPUT); //Pin 2 is input
attachInterrupt(0, enforceOpenAccess, HIGH); // PIN 2
}
void(* resetFunc)(void) = 0;
void loop()
{
//My other keypad implementations go here
}
void myDelay(int x) // function to cause delay in the interrupt
{
for(int i = 0; i<x; i++)
{
delayMicroseconds(1000);
}
}
void enforceOpenAccess() // ISR
{
for(int k =0; k<=180; k+=2)
{
servo.write(k); //rotate the servo
myDelay(30); //delay the rotation of the servo
}
}
The code above is run on arduino UNO being simulated in proteus and the interrupt button is a push button. Please if there is other ways of implementing that but with the same behaviour as I have described above help out. Thanks a lot
There are a couple of problems in the slice of code you posted. Just for completeness, you should post the loop function, since we can't guess what you wrote inside.
Just one comment: did you put a pullup? Otherwise use INPUT_PULLUP instead of INPUT for the button pinmode.
The main one is that you attached the interrupt for the HIGH mode, which will trigger the interrupt any time the pin is up, not on the rising edge. And please use the macro digitalPinToInterrupt to map to the correct pin:
attachInterrupt(digitalPinToInterrupt(openButtonPin), enforceOpenAccess, RISING);
Then.. Let's improve the code. You really should use the interrupts only when strictly necessary when you have to respond IMMEDIATELY (= less than a couple of milliseconds) to an input. Here you don't have to, so it's MUCH better to check for the button in the loop (more on turning the motor following)
uint8_t lastState;
void setup()
{
...
lastState = LOW;
}
void loop()
{
uint8_t currentState = digitalRead(openButtonPin);
if ((currentState != lastState) && (currentState == HIGH))
{
// Start turning the motor
}
lastState = currentState;
...
}
This will enable you to properly debounce the button too:
#include <Bounce2.h>
Bounce debouncer = Bounce();
void setup()
{
...
pinMode(openButtonPin, INPUT); //Pin 2 is input
debouncer.attach(openButtonPin);
debouncer.interval(5); // interval in ms
}
void loop()
{
debouncer.update();
if (debouncer.rose())
{
// Start turning the motor
}
...
}
If, on the other way, you REALLY want to use the interrupts (because waiting for a couple of milliseconds is too much for you), you should do something like this:
#include <Bounce2.h>
Bounce debouncer = Bounce();
void setup()
{
...
pinMode(openButtonPin, INPUT);
attachInterrupt(digitalPinToInterrupt(openButtonPin), enforceOpenAccess, RISING);
}
void loop()
{
...
}
void enforceOpenAccess() // ISR
{
// Start turning the motor
}
It looks like your code? No, because now we'll speak about turning the motor
You should NOT use delays to make steps, because otherwise you will wait for 30ms * 180 steps = 5.4s before being able to do anything else.
You can, however, make a sort of reduced state machine. You want your servo to move from 0 to 180 in steps of 1. So let's code the "don't move" state with any value greater than 180, and consequently we can do something like this in the loop:
unsigned long lastServoTime;
uint8_t servoPosition = 255;
const int timeBetweenSteps_in_ms = 30;
void loop()
{
...
if (servoPosition <= 180)
{ // servo should move
if ((millis() - lastServoTime) >= timeBetweenSteps_in_ms)
{
lastServoTime += timeBetweenSteps_in_ms;
servoPosition++;
if (servoPosition <= 180)
servo.write(servoPosition);
}
}
}
Then, using any of the previous examples, instead of // Start turning the motor write
lastServoTime = millis();
servoPosition = 0;
servo.write(servoPosition);
This way you won't block the main loop even when the button is pressed
This is what is in my loop()
char key = keypad.getKey();
if(key)
{
if(j < 10)
{
studentNumber[j] = key;
//holdMaskedNumber[j] = '*';
lcd.setCursor(0,2);
lcd.print(String(studentNumber));
if(j == 9)
{
studentNumber[9] = '\0';
//holdMaskedNumber[9] = 0;
lcd.clear();
//String number = String(studentNumber);
//lcd.print(number);
//delay(1000);
//lcd.clear();
lcd.print("Access Code");
}
j++;
}
else
{
if(i < 5)
{
accessCode[i] = key;
holdMaskedCode[i] = '*';
lcd.setCursor(1,2);
lcd.print(String(holdMaskedCode));
if(i == 4)
{
holdMaskedCode[5] = '\0';
accessCode[5] = '\0';
//lcd.clear();
//lcd.setCursor(0,0);
//accessCodeString = String(accessCode);
//lcd.print(accessCodeString);
//delay(1000);
lcd.clear();
for(int i =0; i<6; i++)
{
lcd.print("Please wait.");
delay(500);
lcd.clear();
lcd.print("Please wait..");
delay(500);
lcd.clear();
lcd.print("Please wait...");
delay(500);
lcd.clear();
}
digitalWrite(4, HIGH);
lcd.print("Access Granted");
for(int k =0; k<=180; k+=2)
{
servo.write(k);
delay(30);
}
resetFunc();
}
i++;
}
}
}

Resources