text:
LCDs larger than 20x04 and 5" diagonal
Are there any i2c LCD screens that are larger than 2004 characters and larger than 4.8 x 2.7 x 1.2 inches in dimensions?
I have the Sainsmart 2004 LCD but it can't display all the information that I need. Maybe a 20x8 character screen? Because the screen will be viewed from a distance of about 50cm, the screen size should be at least 5" in diagonal.

Short answer: No. Long answer: No, but you can fake it.

@IgnacioVazquez-Abrams Fake it, as in use multiple LCDs over i2c? Are 20x04 LCDs as large as they get?

As in configure a MCU with a font table as a I2C slave and hook it up to a graphical LCD.

Naked displays... search e.g. Ebay for "40x4 lcd" (maybe enable "worldwide" search)...
...naked... so not i2c ... but Arduino libs for these displays exist (e.g.: liquidcrystal440), so add an Arduino-Pro or such and you can have i2c... basically they are two 40x2 displays on the same spi bus selected by different chip select lines...

The 44780 display chip used by these devices has 80 bytes of storage, which is why you can scroll the 2x16 side to side to show up to 40 characters per line. however 4x20 is 80 and that's the limit of the chip.

There are ST7920 based displays which may come close to what you are looking for. They have a similar parallel (4 or 8 bit) interface to the HD44780 based displays (as you have been using), but also support a 3-wire SPI-like interface.
A quick google found the datasheet here:
https://www.lcd-module.de/eng/pdf/zubehoer/st7920_chinese.pdf
They have both graphics and text modes, and most of the displays appear to have 128x64 pixels, giving 16x8 characters assuming 8x8 font, although it appears the native text font is 16x8 pixels.
While it might be more complicated to use these in graphics mode, they are probably the closest to the HD44780 based displays in appearance (large monochrome pixels), unlike other large displays which will probably have more (smaller) pixels than you need.
See also https://playground.arduino.cc/Code/LCD12864


text:
All the differences between Arduinos: Pro Mini & Pro Micro
I'd like to know the differences between these two boards: Arduino Pro Mini and Arduino Pro Micro.
Even if I've read this and this related post, it is not clear enough. I've always used the Arduino Uno or Leonardo and I'm a little bit scared of using these compact miniaturised boards.
I have seen so far those differences:

The Micro doesn’t need the separate FTDI, while the Mini does
The Micro takes more time to boot up due to USB device (keyboard/mouse) emulation (is more like a Leonardo than an Uno)
They both have 5 V and 3.3 V versions
The Mini has 2 more digital IO and 2 more analog Inputs (1 more PWM)
The pinout is the same (a shield designed for the Pro Mini is OK also with Pro Micro)
Micro is more expensive (IF you don't have already an FTDI cable).

So, what I care about most is the boot up time (because it could make debug harder) but other than that.. if I don't need the 2 more Digital IO and the 2 more Analog Inputs.. why buy one over the other?
And some more question: can I use the Mini boot loader inside the Micro to avoid the boot up time (if I do not need the keyboard/mouse emulation)?
Is the power consumption the same? Can I use the same battery?
Sorry if this is a silly question but I'm little bit confused.

It is more the differences between ATMega328P + FTDI (Pro Mini) vs ATMega32u4 (Pro Micro)
Apart from the minor pin differences, the peripherals for both MCUs are the same. The major difference is the ATMega32u4 has built in full-speed USB. This allows the board to function as a USB device by implementing the appropriate USB stack. E.g. it can act as a

USB to serial converter (CDC device)
Keyboard or mouse (HID device)
USB hard drive (MSC device)
MIDI controller
and more...

The LUFA library from AVR devices can be used for this but means going outside of the Arduino IDE and compiling proper C code using the latest avr-gcc tools.
The Arduino core library has built-in support for the HID and CDC device profiles. The CDC profile is used for comms with the Leonardo, Micro, etc. while the HID profile is used for keyboard / mouse emulation.
The Leonardo / Micro boot loader implements a CDC profile for communications with the PC. This CDC profile uses Arduino vendor and product ids so unlike FTDI devices, requires an extra step to install an *.inf file on Windows.
You would have to recompile the Pro Mini bootloader for the Micro, but even then it would require an FTDI board as programming would need to be done via the TX and RX UART pins. If you we going to go to all that trouble you could just recompile the proper boot loader to have a shorter time out. Why is difference of 1 or 2 seconds in boot loader time important?
The ATMega32u4 uses more power than the ATMega328P.

Arduino Pro Mini

Pin Mapping
Arduino Micro

Pin Mapping

The Arduino page for the Arduino Pro Mini and the Arduino Micro.
Microcontroller
Arduino Pro Mini: ATmega328 (ATmega168 on older boards)
Arduino Micro: ATmega32U4
Memory
Both have 32KB of Flash and 1KB of EEPROM
The Arduino Pro Mini has 2KB of SRAM where as the Arduino Micro has 2.5KB
Digital I/O
The Arduino Pro Mini has 14 (of which 6 provide PWM output)
The Arduino Micro has 14 also (of which 7 provide PWM output)
Some of the analog pins can also be used as digital I/O
Analog Inputs
Arduino Pro Mini: 8 (some boards only break out 6 analog inputs)
Arduino Micro: 12 (6 dedicated and 6 from digital I/O pins)
USB
Arduino Pro Mini: Requires FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.
Arduino Micro: Native USB
Clock
Both are 16 MHz (although the 3V Arduino Pros run at 8MHz)
Power
There are two version of each of the Arduinos. One runs at 3.3V and 8 MHz, the other at 5V and 16 MHz.
Arduino Pro Mini: VRAW  can accept voltage up to 12VDC.
Arduino Micro: USB or external supply of 6 to 20 volts (recommended range is 7 to 12 volts)
Interrupts
Arduino Pro Mini: The Atmega328 has 2 hardware interrupts available
Arduino Micro: The ATMega32u4 has 5 hardware interrupts available
credit: Enric Blanco

There seems to be a bit of confusion here: You're conflating the SparkFun Pro Micro and the Arduino Micro. Are they just the same or if not, what are the differences between them?

They are pretty much the same but not identical. The Arduino hardware design files are open source. So Sparkfun have taken the design files and made their own assembled PCB. Sparkfun have made their version smaller by not exposing all of the pins (eg. 11,12, A4, A5 etc.). They both use the ATmega32U4 microcontroller (which is also used on the Arduino Leonardo). Check out the schematics for all differences: http://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Pro_Micro_v13b.pdf and https://content.arduino.cc/assets/arduino_micro_schematic.pdf

So, what I care about most is the boot up time (because it could make debug harder)

still couldn't figure out the link between boot up time and debug.

but other than that.. if I don't need the 2 more Digital IO and the 2 more Analog Inputs.. why buy one over the other?

sounds like there is no reason for you to the other board.

And some more question: can I use the Mini boot loader inside the Micro to avoid the boot up time (if I do not need the keyboard/mouse emulation)?

the only way to avoid boo up time in anything, pro mini or pro micro, is to not boot it up. you cannot have boot up time if you don't boot it up.
As to the two boards, they use different avrs. the U4 has amazing analog features, but most pro micros don't route out AIN0/AIN1 - rendering them as the same as pro mini. that's a shame.
obviously, if you don't use those features,  they have no value to you and cannot justify the premium / added complexity.

In addition to what @geometrikal says (excellent answer, BTW) ATMega32u4 has 5 available true hardware interrupts (so-called "external"), whereas ATMega328p only has 2.
IMHO, that is a key advantage for some applications.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Arduino 16x2 LCD Black Boxes
I hooked up a 16x2 Arduino compatible LCD yesterday and made sure all the connections were according to the program and the schematics provided all over the web. My contrast is adjusted perfectly but the problem is that there are black boxes on the top line while the lower one is empty.

I know this question has been asked many times but no one has answered the question other than saying, "Check your contrast pin". I'm using the default sample code provided in the Arduino IDE.
HELP!
Regards.

Do you use a I2C interface on the LCD?

@RienBrand Nope. Just the standard interface(i dont know what its called).
Here's a link to its data sheet by the way:
http://www.evselectro.com/image/data/datasheet/LMB162ABC.pdf

Can you post a picture of how you connected it? Contrast, indeed, isn't the issue here.

Most commonly this kind of problem is because the display has been connected backwards.  Double check which pin of the header on your display is pin 1.

@Majenko The display can't possibly be connected backwards because the pins are labelled on the display itself. I didn't even have to look for the datasheet. Pin 1 and 2 are the power pins then we have contrast,RS,R/W,E and so on. And oh yeah R/W is connected to ground.

@Gerneb How? There's no option :/

Look at this answer here: http://arduino.stackexchange.com/a/17472/11174

Try in your code lcd(0x27,16,2); insted of lcd(0x3f,16,2);

I have done some Googling across the web and it turns out that this can be caused by a couple of things:

Incorrect wiring.
Wiring of LCD backwards (ie 1 to 16 and 16 to 1).
Faulty wiring (ie broken cables & dry joints).
Incorrect initialization of the LCD.
Buggy software.
Damaged screen.

The LCD screen that you have is a based on the Hitachi HD44780 chipset. It is the most common interface for text-based LCDs. It can be identified by the 16-pin interface. I2C is the next most common interface and is distinguishable as it has a 4-pin (sometimes 5-pin) interface.
Lets assume that your screen isn't damaged. From the details in your question, it sounds like your contrast is working just fine. The list above can be shrunk to just 2 things: bad wiring and/or bad code. Lets eliminate both of those by using known working software and known working circuit.
Arduino has an LCD library with example programs. Details for this library, including a wiring diagram, can be found over at the Arduino site in the Reference section. I use these example sketches to test my wiring connections before I write my own program. I recommend using the Autoscroll example.

Schematic:

These diagrams are from the Arduino Autoscroll page. I highly suggest that you read this page thoroughly.
The code can be easily uploaded into your Arduino, through the IDE, by going into File > Examples > LiquidCrystal > AutoScroll, then Sketch > Upload.
You should see the sketch print the characters 0 to 9 on the top line (with autoscroll off), then moves the cursor to the bottom right (turns autoscroll on,) and prints the characters 0 to 9 on the bottom line, but as it prints each character the display should move one to the left.
If you get this example program to work then you know that you have a working LCD and also that your wiring is OK as well.

Are you using an LCD driver board that has 4 connections between it and the arruino, or do you have the LCD directly connected?
If using a driver board, download Liquid Crupystal Library here
Ten make sure to have the library running in that startup code.

Connect your RW pin to Ground.

Your answer is rather terse and could do with some expansion. For example, why will connecting RW to ground help? As it stands your answer would have been better as a comment

Alright guys thanks for everything! I've found the solution. It was a bad solder.

Your contrast is just fine. The black boxes indicate that your LCD isn't correctly initialized. Poor connections and / or bad code is to blame. So focus your debugging there.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
MAX232 chip fails to initialize properly with arduino
I have connected a MAX232 chip for RS232 communication with my Arduino.
The chip input is connected to Arduino Tx and it is getting power from external 3.3 volt dc power source.
My Arduino is also getting power from 12 volt DC external power source.
While I connect and start the device, the PC is not getting any data until I reboot the MAX232.
How do I make a robust setup so that after I turn the powers on, it starts transmitting. Even if connection to my PC has been lost.

MAX232 is not a microprocessor, and does not require initialization. It's really just an inverting level converter. Can you show a schematic of how you have it connected? Also, the typical MAX232 is a 5V part, so 3.3V powering it won't be reliable.

Agreed - for 3.3V operation you need to use the MAX3232.

Datasheet for MAX232

Section 7.3 Recommended Operating Conditions VCC Supply voltage
MIN=4.5, NOM=5, MAX=5.5 (V)

The MAX232 has a minimum supply voltage of 4.5V, typically expecting 5V.
There are other alternatives, such as the MAX3232, which supports either 3.3V or 5V supply voltage.

Thanks,  I also found that error in datasheet about 5 volt power. But is there any startup sequence?

Say i have to turn 12 volt power first, then 3.3 and then connect it to the pc. Is there any logic behind proper startup sequence?
I am using different power sources.

The MAX232 chip has no 12V supply. There is no startup sequence.

I have tried whatever I found here, but still I am unable to send data from Arduino to pc via MAX232. I have only connected the TX line, ground from Arduino to MAX232 chip, thats what i need actually (Arduino here is not supposed to get any data).

All common grounds are okay. Power lines are okay. Connections are too properly done.

I figured out the problem. There was no delay in my code. A 100 ms delay solved the issue. There is some specific switching frequency for the MAX232.

The 5v vcc also needs a resistor of some value to prevent the chip from overheating.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Can I switch from Arduino IDE to Atmel studio or Visual Micro but still use Arduino library?
If switch from Arduino IDE to Atmel studio or Visual Micro, how to use existing Arduino library?
Library serves important function of 'packaging' real and complex hardware (like NRF24L01 radio board) into functions of 'relatively standard format', like radio.init, radio.write, radio.read, radio.on, etc.
This allows user to easily use the hardware without reading the data sheet.
How can the same be achieved under Atmel studio?

Sorry for hijacking your question. Arduino itself is actually also a library. E.g. pinMode, digitalWrite and delay aren't standard functions. Just like your sketches, a lot of libraries depend on these functions. How would one get these to work as well in Atmel studio?

The thing that I just found is that you need to have Visual Studio, not Atmel Studio. For some reason you cant, AFAIK, add libraries with AS.

Visual Micro supports all Arduino libraries in the same way that the Arduino IDE supports these libraries.
When using Visual Micro in Atmel Studio your sketch code remains identical to the Arduino IDE. You can switch between the two IDEs and see the same compiler results.
If you can not see your user libraries on the "Atmel Studio>Projects>Add/Import Sketch Library" menu then this means you have configured the SketchBook folder path incorrectly.
Arduino and Visual Micro use the SketchBook folder to find user libraries in a sub folder called 'Libraries'.
I recommend leaving the sketchbook folder empty because Visual Micro will then auto discover the SketchBook folder that the Arduino IDE uses and remove the possibility of confusion.
When the sketchbook folder is empty and has not been set in the Arduino IDE the default will be myDocuments\Arduino, therefore your user libraries will be expected to exist in myDocuments\Arduino\Libraries.
@John, in response to your question below. It's a big topic and maybe best answered in our forum.
A few examples are:

Ability to re-define arduino core to use tools such as cygwin, we see
the Arducopter example as a good one for this. They produce a window
SITL program.
Obviously we can all use the flexible Arduino 1.5 config structure to
define our own hardware and build process but we also support the
Teensy customization system which allows windows apps/tools to manage
the build process and tool chains. Visual Micro supports both of
these customizations combined in the same hardware def but also a
number of other build properties.
There is also the ability, in Visual Micro, to add compiler #defines
for project or configuration and the ability to add programmers that
use, for example, the atmel toolchain (if using atmel studio).
Libraries can be referenced with a folder name (unlike arduino) which
allows different projects to use similar libraries but of different
versions. (Library paths are declared for the lib folder roots as
well as individual libraries).
If you consider the various different build properties build
properties of Arduino, Teensy, Energia, ChipKIT and Intel then add a
few on top this describes what you can do in any project regardless
of hardware IDE.

Thanks for the answer which cover (a) as below taken from official web. Can you please state a bit more specific on (b).   From web, (a) New Arduino users are guided to work within the normal Arduino framework, in a similar manner to the Arduino IDE. (b) Advanced Arduino users have a range of options that allow the simple (but restricting) Arduino rules to be broken.

@John Some answers above in the post

At the end of the day, an Arduino library and the Arduino core are just files full of code.
There is nothing to stop you creating a project in Atmel studio (or wherever) and importing all those files into your project.
You will need all the core files (hardware/arduino/core/arduino/*) plus all the files for the libraries you want to use.


text:
Testing Arduino with Visual Studio Community 2013 raise LNK error
I have two projects in my Visual Studio Community 2013 solution.
I created a project for Arduino, and create another project for Test. When I run the project tests without adding the Arduino project reference, it run ok, but when I add the Arduino project reference I get it error:
LNK1561: entry point must be defined D:\VisualStudioArduino\PrinterProject\LINK PrinterProject

What is the entry point for Arduino project?
It does not generate any file like a dll or main file?
What can I do to solve this error?
UPDATE I
I also tried this configuration in the Arduino Project but I get the same error:
Properties -> Linker -> System -> SubSystem to "Windows (/SUBSYSTEM:WINDOWS)"

UPDATE II
I am using Visual Micro extension. But the problems is when I try to compile the Test project. Then I recreate this scenario with a C++ console application and create a simple class, and create a test project and added the console application reference to test project and it worked. Then my doubts is about to how do I configure a Test Project to test my Arduino project.

When you create a Test project you need to add the project reference do you want to test. When I compile the arduino project it compiles ok, the problem is with the tests project.

I use Visual Studio Community Edition 2013 along with the Visual Micro extensions, which I think is what you need as the "missing link" between VS and Arduino.

I am using VSC Edition 2013 with Visual Micro, then when I compile the arduino there is not problem, the error is when I compile the Test project.

Sorry, I don't understand what are yout trying to do. You seem to want to "configure a Test Project to test your Arduino project.". What do you exactly mean with "test your Arduino project"? can you provide details?. do you mean to upload the program to the Arduino?

When I create a class I want to create a test for this class: an Unit Test. I am trying to do a TDD development approach. Some object and function need to be stub, fake and also mocking.

The best place for answers is in the Visual Micro forum.

Be sure about is that the main .ino source file of your Arduino project matches both the name of the Visual Studio project and the name of the folder they existing in. For example:

Folder = Sketch1
Master Source = Sketch1.ino
Visual Studio Project Name = Sketch1

This ensure Visual Micro will compile the project and also it will be compatible with the Arduino Ide.

With two projects in a Visual Studio solution it is important to note which is the "Startup Project". You can control which is the startup by right clicking a project in the explorer and clicking "Set as Startup project". The project name will then appear in bold.

The startup project affects which project is uploaded/started/debugged when you click any of the "Start" commands.

The menu item "Build>Configuration Manager" allows you to exclude your Arduino project from Visual Studio Win32 builds but changing this option should not normally be required.
You can right click each project and click "Start>New instance" to override the current "Startup project" and specifically build and upload a project.

Summary
If the build/upload fails and you see the visual studio c++ compiler error that you have described above this means that Visual Micro is not handling the build process for the project.
Therefore, please confirm point 1 is correct by trying out build task described in point 4 above.
It would be useful to know which build command you are selecting when the problem happens.

You are trying to build a Windows program.  You need a main() function as an entry point.  I suspect that when your code is built through the Arduino IDE it adds in a main function in.
You can tell Visual Studio to build your files differently by defining some build rules, but it sounds like someone may have done this sort of thing by looking at the other answers.
But the easiest short term solution would be copying and pasting into the Arduino IDE.


text:
Arduino shuts off randomly (Temperature?)
I've got an Arduino Uno running in a case, with a Fona 808 shield from Adafruit on top. It's used as a location tracker; it'll get the current GPS location three times a second, then send the average to a webserver.
While testing the Arduino software, I noticed the Arduino would get quite hot and shut off while using a 9V 1A power supply, so instead I opted for powering it through the USB port I also used for debugging. This didn't seem to be a problem, but I haven't tested it for hours at a time.
Right now I've got it installed in my motorcycle. As I felt the 12V would be a bit too much (although it's in the acceptable range) because it couldn't handle 9V, I put a transformer with short-circuit protection in the line, stepping it down to 5V 600mA.
Because this too was cutting out at seemingly random times (3, 2.5, 13 hours), I'm really not sure what to do. The motorcycle is outside, so the outside temperature may interfere with this amazing scientific test, but I don't see any reason for it to get so hot it would turn off completely.
Does anyone have an explanation for it?

What specifically happens? Does the whole board lose power (no power led on the UNO)? Does the program no longer appear to run? Try adding a blinking led to your code, sort of like a heartbeat, so you can see if the code is still running. If it's the code that locks up, you might want to look into the watchdog timer inside the UNO. Using this watchdog you can make the Arduino reset itself if it stop/hangs.

That "transformer"?  These do not work between DC sources, so presumably you mean some sort of DC-DC convert.  What you are doing to accomodate the GSM module's notoriously high pulse power demand during transmit??  How much thought have you put into the power consumption savings you will need to achieve to have this run for any substantial period of time on battery?  And how are you juggling two presumably serial peripherals?

@Gerben I modified the code a bit to make one of the LEDs blink. Can't look at the arduino power LED because it's in a closed case. I'll update as soon as it stops again.


text:
SOLVED: Strange phenomenon with avrdude: stk500v2_ReceiveMessage(): timeout only with ATmega250 on windows 7x64
I know this problem has been reported multiple times but in my case I think there is a different light on it.
My desktop is a w7x64 box and I also have a notebook with w10.
Both system have the arduino IDE 1.8.5 with the latest updates.
The desktop though has more boards and drivers as it is my main development system.
I have at ATmega2560 clone with CH340 which used to work on my desktop about half a year ago when I tried to get an LCD touch shield to work.
Yesterday I tried to resume on it and I got the ubiquitous timeout error.
So I removed the shield and tried the basic blink sketch but no change.
I tried an arduino nano and there was no problem to upload the blink sketch.
Then I tried different USB cables and ports but the timeout problem with the ATmega persisted.
So I went to the notebook and the ATmega worked like a charm.
Now I know that the board is ok as well as the cable.
The port is also ok as the nano worked on it smoothly.
I also tried the upload from an elevated command prompt with the verbose option but it gave me no further clue.
The output is below:
C:\Users\Pete\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/bin/avrdude -vvvv -CC:\Users\Pete\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/etc/avrdude.conf -v -patmega2560 -cstk500v2 -PCOM34 -b57600 -D -Uflash:w:T:\TMP\arduino_build_330193/Blink.ino.hex:i

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Pete\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0 -arduino14/etc/avrdude.conf"

         Using Port                    : COM34
         Using Programmer              : stk500v2
         Overriding Baud Rate          : 57600
STK500V2: stk500v2_open()
STK500V2: stk500v2_getsync()
STK500V2: stk500v2_send(0x1b 0x01 0x00 0x01 0x0e 0x01 0x14 , 7)
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
STK500V2: stk500v2_recv(): avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout

Does anybody have an idea how to further tackle the problem?

Is there a reason to stay behind with an old version? There has been problems with the version from the Microsoft Store. Try to remove the old version and install the newest: https://www.arduino.cc/en/Main/Software It is possible that the usb-serial drivers have a problem, perhaps you can try to remove them before installing the new version. It is also possible that there is a problem with the hidden "Arduino15" folder. You can delete that folder before installing a new version.

if you upload a sketch that prints on Serial, does it print to Serial Monitor on your desktop?

I downloaded the 1.8.8 release of the arduino IDE but the version of avrdude is the same as on 1.8.6. Thus the command line output does show the same timeout problem as before. As I said the Nano works without problems. It can print on serial too. The Mega does not upload and the print on serial is not working on the desktop. On the notebook there is no problem printing on serial.

I found the problem coming from a mismatch of the port speed setting and the baudrate in the avrdude command.
It seems that the ATmega is very sensitive to timing issues.
After I did set everything to 115200 it works on my w7 box like on the notebook.

where did you set the baud rate? avrdude sets the baud rate


text:
Simulating a real time clock module with software
I am building a clock with an Arduino.
Most clocks have a RTC module or some kind of RTC chip in order to get the time. I do not.
How do i replace this chip with software? Is there a C/C++ library equivalent to the Java library  java.util.date?
Can I run a Java program instead of a C program on my Arduino so I can use this Java library? I only know Java and have little experience with C/C++. I have looked into ways to program this clock in Java which I have had success with, but this is only in my computer, not in the Arduino.

you have to do some research before posting a question .... i suspect that you have not bothered to do anything before posting your question because a web search for arduino timekeeping returns good info

Can i run a java program instead of a c program on my arduino so i can use this java library? Huh? How does switching to the Java language solve the problem on how to get the time? On a PC, your PC would get the time over NTP via an internet connection. The Java library just gets that already stored value. It doesn't get the time for the pure reason it's now written in Java instead of C++. You can use the same mechanism however -- either use a network connection of some sort (e.g. WiFI) and get the time via an NTP / SNTP client, or program the time once and store it in an RTC peripheral.

you did not answer the comments in your previous question about this https://arduino.stackexchange.com/questions/53108/arduino-clock-project

Possible duplicate of arduino clock project

Your question has been flagged for quality. Please see How do I ask a good question about the Arduino?

Explain how exactly do you expect this software simulation to work. E.g., do you want the clock to always start at a predefined time after a reset?

how do i replace [an RTC] chip with software?

You can't. An RTC is made of basically two things:

a carefully trimmed crystal oscillator that has a very stable and well
calibrated frequency
some logic to count the oscillations and convert that to time and
date.

The logic can be easily replaced by software, but the crystal cannot.
Any “pure software” solution you may find ultimately relies on counting
cycles of the system clock (the signal that clocks the whole
microcontroller). On most Arduinos, including the Uno, the system clock
is based on a ceramic resonator. These are usually specified with
0.5% frequency tolerance, and they typically have a frequency offset of
about ±0.1%. That's a drift of ±44 minutes per month!
You can get better accuracy by calibrating your Arduino's clock, and
correcting by software the frequency offset you measure. However, the
frequency is not only off, it is also quite unstable, and very sensitive
to temperature variations. So even with calibration you end up with a
clock that is ridiculously bad compared with the cheapest quartz watch.

is there a c++ library equivalent to the java library java.util.date?

I don't know Java, but there are C++ libraries available for managing
time. For example, you could initialize Paul Stoffregen's TimeLib as
follows:
setTime(hr,min,sec,day,mnth,yr);  // set initial time
setSyncInterval(-1);  // pretend we don't need to resync

and then periodically query the time with now(). That should be all
you need to build a “proof of concept” of your clock: it will tell you
the time, but with an awfully bad long-term accuracy.
Note that, once you add an RTC or another good time source, you can add
a “time provider” to that library, keep the rest of your code unchanged,
and benefit from the accuracy of your new time source.

Can i run a java program instead of a c program on my arduino [...]?

No, you can't. A Java runtime will never fit in your Arduino.

The resonator can be readily replaced with an actual 16 MHz crystal.  Some older / kit boards already work that way, as do the arduino on breadboard instructions on the arduino site.  The main disadvantage then is power consumption - but your basic Arduino project runs at full speed drawing full power all the time anyway.  For the more advanced, activating the clock divider can minimize the amount of circuitry that runs at 16 MHz, peripherals can be disabled, and the processor core itself can be suspended leaving just a hardware timer counting ticks.

Having looked at you other question it seems you are trying to run before you can walk.  You may be a good java programmer, but you need to get your head around C++ before you go all in and build a clock.
To answer this question, yes there are ways to get software to keep time, but when you power it up, how do you know what the time is?  This is where having a RTC will help, there are plenty of bare ICs out there and even ones with libraries.
If you had a network then you could grab the header data from the network packets, but you are running this on a Mega, which seems an odd choice for something as simple as a network time clock, surly a nano would do, or an ESP8266.
These links will help you, but personally I think you need to break the problem down into smaller chunks.
https://www.arduino.cc/reference/en/
https://playground.arduino.cc/Code/Time


text:
Why do the LEDs visibly flicker?
The aim of the project was to be able to show two "kinds" of LEDs in a 8x8 single color LED matrix. I used a MAX7219 chip to drive the LEDs using my Arduino UNO R3 as the driver (with the usual connections).
Despite the frequency of the blackupdate() function being near to a 100Hz, why do I see the LEDs corresponding to currentblack() flickering? 100Hz is much beyond the resolution of the eye, as I understand it. The multiplexing frequency of the MAX7219 chip is also much beyond resolution (800Hz). Why do the "white" LEDs not flicker?
Here's the code with Serial.println() added for debugging:
int DataPin = 2; // Pin 1 on MAX
int LoadPin = 3; // Pin 12 on MAX
int ClockPin = 4; // Pin 13 on MAX
int currentwhite[8]={B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
int currentblack[8]={B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};

#define SCAN_LIMIT_REG 0x0B
#define DECODE_MODE_REG 0x09
#define SHUTDOWN_REG 0x0C
#define INTENSITY_REG 0x0A
#define DISPLAY_CHECK_REG 0x0F

void setup() {
  pinMode(DataPin, OUTPUT);
  pinMode(LoadPin, OUTPUT);
  pinMode(ClockPin, OUTPUT);
  digitalWrite(LoadPin, LOW);
  shiftOut(DataPin, ClockPin, MSBFIRST, SCAN_LIMIT_REG); // scan limit set to 0:7
  shiftOut(DataPin, ClockPin, MSBFIRST, B00000111);
  digitalWrite(LoadPin, HIGH);
  digitalWrite(LoadPin, LOW);
  shiftOut(DataPin, ClockPin, MSBFIRST, DECODE_MODE_REG);
  shiftOut(DataPin, ClockPin, MSBFIRST, B00000000);
  digitalWrite(LoadPin, HIGH);
  digitalWrite(LoadPin, LOW);
  shiftOut(DataPin, ClockPin, MSBFIRST, SHUTDOWN_REG);
  shiftOut(DataPin, ClockPin, MSBFIRST,  B00000001);
  digitalWrite(LoadPin, HIGH);
  digitalWrite(LoadPin, LOW);
  shiftOut(DataPin, ClockPin, MSBFIRST, DISPLAY_CHECK_REG);
  shiftOut(DataPin, ClockPin, MSBFIRST, B00000000);
  digitalWrite(LoadPin, HIGH);
  digitalWrite(LoadPin, LOW);
  shiftOut(DataPin, ClockPin, MSBFIRST, INTENSITY_REG);
  shiftOut(DataPin, ClockPin, MSBFIRST, 0);
  digitalWrite(LoadPin, HIGH);
  Serial.begin(9600);

  currentblack[3]=B00001000;
  currentblack[4]=B00010000;
  currentwhite[3]=B00010000;
  currentwhite[4]=B00001000;
}

void blackupdate() {
  digitalWrite(LoadPin, LOW);
    shiftOut(DataPin, ClockPin, MSBFIRST, INTENSITY_REG);
    shiftOut(DataPin, ClockPin, MSBFIRST, 0);
    digitalWrite(LoadPin, HIGH);
  for (byte row=0; row<8; row++){
    digitalWrite(LoadPin, LOW);
    shiftOut(DataPin, ClockPin, MSBFIRST, row+1);
    shiftOut(DataPin, ClockPin, MSBFIRST, (currentblack[row]));
    digitalWrite(LoadPin, HIGH);
  }
}

void whiteupdate() {
  digitalWrite(LoadPin, LOW);
    shiftOut(DataPin, ClockPin, MSBFIRST, INTENSITY_REG);
    shiftOut(DataPin, ClockPin, MSBFIRST, 15);
    digitalWrite(LoadPin, HIGH);
  for (byte row=0; row<8; row++){
    digitalWrite(LoadPin, LOW);
    shiftOut(DataPin, ClockPin, MSBFIRST, row+1);
    shiftOut(DataPin, ClockPin, MSBFIRST, (currentwhite[row]));
    digitalWrite(LoadPin, HIGH);
  }
}

void loop() {
  Serial.print("A");
  Serial.println(millis());
  blackupdate();
  Serial.print("B");
  Serial.println(millis());
  whiteupdate();
  delay(5);
  Serial.print("C");
  Serial.println(millis());
}

And the Serial output was as follows:
A1
B3
C10
A10
B12
C19
A19
B21
C28
A28
B30
C37
A37
B39
C47
A47
B49
C56
A56
B59
C65
A66
B68
C75
A75
B77
C84
A84
B87
C94
A94
B96
C105
A105
B112
C123
A123
B131
C142
A143
B150
C161
A161
B168
C180
A180
B187
C198
A198
B205
C217
A218
B225
C236
A236
B243
C254
A254
B262
C273
A274
B281
C292
A292
B300
C311
A311
B318
C329
A329
B336
C348
A349
B356
C367
A367
B374
C386
A386
B393
C404
A404
B412
C422
A423
B431
C442
A442
B449
C460
A460
B467
C479
A480
B487
C498
A498
B505
C517
A517
B524
C535
A535
B542
C553
A555
B562
C573
A573
B580
C591
A591
B599
C610
A611
B618
C629
A629
B636
C648
A648
B655
C666
A666
B673
C685
A686
B693
C704
A704
B711
C722
A722
B730
C741

You're trying to implement two different brightness's for each led. I think the problem is that the update rate of the MAX7219 and the update rate of your Arduino code are not in sync, causing some variations in the brightness. Also you are setting the brightness of the MAX7219 to max, before updating the pixel data, which would cause the 'black' pixels from being a lot brighter for a short while. I'd move the first 4 lines in whiteupdate to the end of the function. PS you only need to do digitalWrite(LoadPin, LOW);...;digitalWrite(LoadPin, HIGH); once per function. No need to do this 9x.

I tried putting the intensity function at the end of the fuction, but it changed nothing. Even if the black LEDs are bright for a while, the entire function takes only 2 milliseconds to happen, so shouldn't be visible. Can you expand on what you mean by the two devices not being in sync?

Wouldn't we need to latch the data by putting the loadpin to high every time? Otherwise the data would simply be outputted through the Dout pin?

The max7219 updates the display at around 800hz. Your code updates the display data around 100hz. But not exactly. So ideally the max would multiplex every column 8 times between every update. But is it's slightly slower, it might have done the last column only 7 times. Which would make it less bright.

But then the entire black set invariably flickers irrespective of the position.

You are correct that this is updating at about 100 Hz. The clue is in the serial output:
A1
B3  <<
C10 <<
A10
B12 <<
C19 <<
A19
B21 <<
C28 <<
A28
B30 <<
C37 <<
A37

There is always a big gap between the ms reading between B and C. This is due to the delay in after the whiteupdate().
void loop() {
    Serial.print("A");
    Serial.println(millis());
    blackupdate();
    Serial.print("B");
    Serial.println(millis());
    whiteupdate();
    delay(5);    // <-- DELAY HERE
    Serial.print("C");
    Serial.println(millis());
}

There is no update between the blackupdate() and the whiteupdate(), so even though 5ms is just on the border of what your eyes can determine, due to the repeating pattern and persistence of vision, your eyes do notice it.
You will find that your flicker will dissapear if you split the delay so you have an equal delay between your blackupdate()->whiteupdate() and whiteupdate()->blackupdate().
void loop() {
    Serial.print("A");
    Serial.println(millis());
    blackupdate();
    delay(2);    // <-- DELAY HERE
    Serial.print("B");
    Serial.println(millis());
    whiteupdate();
    delay(2);    // <-- DELAY HERE
    Serial.print("C");
    Serial.println(millis());
}

Removing the serial debug lines give you:
void loop() {
    blackupdate();
    delay(2);
    whiteupdate();
    delay(2);
}

I tried doing that. I still found the LEDs flickering. I set both the delays at delay(10).

The hardware setup isn't clear. For example, do you have two matrix's or one? In any event, the effect of black update() stays on much shorter than the effect of white update() due to the delay inserted in the main loop.

One matrix. And I agree, but the functions still cycle at a very high frequency, and should be indistinguishable by eye. Only the average should be visible, right?

The pattern of white update is briefly interrupted by the pattern of blaackkuodate. That's the flickering you see. You can test this by commenting out one of the patterns. The MCU ISS doing what your code wants it to Do. What do you want your code to do?

I see only the blackupdated LEDs flickering. If the interrupts were a problem, the whiteupdated LEDs should flicker, right?

The white leds are probably too bright to see them flicker.

There may be some more physiology at work here, too. Did you notice the flickering while staring fixedly at one LED, or while looking around your project area ("scanning" as it were, with your eyes)? If you scan your vision past a flickering LED, even one that flickers at a rate beyond our perception, you can see a streak of dots cross your vision, where a steadily lit one would make a solid streak. I noticed it driving at night, when LED tail-lights were still new and unusual. Those cars stood out because their tail-lights left the same trail of dots across my vision (although some people have told me they do not see this phenomenon or aren't aware of it...).


text:
Powering Atmega328P-Pu externally
Please I'm new to Arduino and I need assistance. I'm working on a project which makes use of the ultrasonic sensor to make a certain pin high if a certain distance is attained. When I used the USB port to power it up it worked fine. When I use external power(tried two different 9V microphone battery) it's not giving desired result. Now I want to try using just the Atmega328P on the board externally(separately from the Arduino).
Questions

What could be the cause of the malfunction when I use external 9V battery
what voltage should I connect to the VCC of the Atmega cos I'm scared of damaging it.
Am I going to power the ultrasonic sensor with an entirely different source from the VCC or I can tap from that same VCC source.
Any other information I need to know using the ATmega on its own

What you need is a voltage regulator! There are many options to choose from linear regulators to buck (or boost) DC-DC converter. You can buy them from various sources as well.

What could be the cause of the malfunction when I use external 9V battery?

The ATMega can only handle 5V maximum, using 9V will either destroy it or engage protection circuitry that will prevent the chip from operating and being damaged.

What voltage should I connect to the VCC of the Atmega?.

Most of the time an ATMega is powered with 5V, but depending on the clock frequency they can operate at lower voltages, the datasheet will have the details.

Am I going to power the ultrasonic sensor with an entirely different source from the VCC or I can tap from that same VCC source?

With the appropriate choice of powersupply you can power both the AVR chip and your sensor with the same power supply.

Any other information I need to know using the ATmega on its own?

The datasheet will contain all you need to know, but if you want to use the Arduino tool chain you will need to:

Use an external crystal
Burn the Arduino (or AvrDUDE) bootloader

I can't conclude which of the questions you are helping me answer.

@user169847 I edited the answer to be more clear

1.8 - 5.5V (max)
The datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Summary.pdf) will tell you that input Voltage is: 1.8 - 5.5V
That's max of 5.5V so don't use 9V battery without a voltage divider.
To power the chip all you need is voltage to Pin 7 and GND to PIN 8.
16Mhz Crystal Most Likely Required
However, to get it to work after removing the chip from an Arduino Uno board you will also need a 16Mhz Crystal on pins 9 & 10.  You will also need two 22pF capacitors on pins 9 & 10, each connected to ground.
I've written this all up with pictures at my blog: http://raddev.us/arduino/post/2018/07/03/arduino-uno-using-your-atmega328p-u-as-stand-alone
Your final circuit will look something like the following (from my blog article):

Without the Crystal you will most likely find that your sketches don't seem to run.
Note: The red LED is connected just as a blink test (more on that in the article).

Thank you very much. I really appreciate your response. Would try everything out.

A voltage divider is not a regulator, don't try to power a chip with a divider!

Okay, good point. But was only attempting to mention that 9V was too much.  So are you saying that if he divided the voltage down to 3.3V for example and applied that voltage (which is in the range that the chip can handle) it would cause some kind of problem?

@raddevus a voltage divider doesn't regulate, as the load changes so will the voltage, a stable voltage is required to run a micro controller.


text:
How to create "Auto switch case"
I am new to programming. I want to modify this sketch and I really need help. I have a switch case in this sketch, and what I want is an auto change effect.
In this sketch 18 color effects for WS2812B led strip. To change effects you have to press ta button. How do I make it change effect automatically, for example 8-10 seconds. I don't know how to do this. So please help me, huge thanks!
#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN 6

#define BUTTON 2
byte selectedEffect=0;

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
}

// *** REPLACE FROM HERE ***
void loop() {
  EEPROM.get(0,selectedEffect);
  if(selectedEffect>18) {
    selectedEffect=0;
    EEPROM.put(0,0);
  }

  switch(selectedEffect) {

    case 0  : {
                // RGBLoop - no parameters
                RGBLoop();
                break;
              }

    case 1  : {
                // FadeInOut - Color (red, green. blue)
                FadeInOut(0xff, 0x00, 0x00); // red
                FadeInOut(0xff, 0xff, 0xff); // white
                FadeInOut(0x00, 0x00, 0xff); // blue
                break;
              }

    case 2  : {
                // Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
                Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
                break;
              }

    case 3  : {
                // HalloweenEyes - Color (red, green, blue), Size of eye, space between eyes, fade (true/false), steps, fade delay, end pause
                HalloweenEyes(0xff, 0x00, 0x00,
                              1, 4,
                              true, random(5,50), random(50,150),
                              random(1000, 10000));
                HalloweenEyes(0xff, 0x00, 0x00,
                              1, 4,
                              true, random(5,50), random(50,150),
                              random(1000, 10000));
                break;
              }

    case 4  : {
                // CylonBounce - Color (red, green, blue), eye size, speed delay, end pause
                CylonBounce(0xff, 0x00, 0x00, 4, 10, 50);
                break;
              }

    case 5  : {
                // NewKITT - Color (red, green, blue), eye size, speed delay, end pause
                NewKITT(0xff, 0x00, 0x00, 8, 10, 50);
                break;
              }

    case 6  : {
                // Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false)
                Twinkle(0xff, 0x00, 0x00, 10, 100, false);
                break;
              }

    case 7  : {
                // TwinkleRandom - twinkle count, speed delay, only one (true/false)
                TwinkleRandom(20, 100, false);
                break;
              }

    case 8  : {
                // Sparkle - Color (red, green, blue), speed delay
                Sparkle(0xff, 0xff, 0xff, 0);
                break;
              }

    case 9  : {
                // SnowSparkle - Color (red, green, blue), sparkle delay, speed delay
                SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
                break;
              }

    case 10 : {
                // Running Lights - Color (red, green, blue), wave dealy
                RunningLights(0xff,0x00,0x00, 50);  // red
                RunningLights(0xff,0xff,0xff, 50);  // white
                RunningLights(0x00,0x00,0xff, 50);  // blue
                break;
              }

    case 11 : {
                // colorWipe - Color (red, green, blue), speed delay
                colorWipe(0x00,0xff,0x00, 50);
                colorWipe(0x00,0x00,0x00, 50);
                break;
              }

    case 12 : {
                // rainbowCycle - speed delay
                rainbowCycle(20);
                break;
              }

    case 13 : {
                // theatherChase - Color (red, green, blue), speed delay
                theaterChase(0xff,0,0,50);
                break;
              }

    case 14 : {
                // theaterChaseRainbow - Speed delay
                theaterChaseRainbow(50);
                break;
              }

    case 15 : {
                // Fire - Cooling rate, Sparking rate, speed delay
                Fire(55,120,15);
                break;
              }

              // simple bouncingBalls not included, since BouncingColoredBalls can perform this as well as shown below
              // BouncingColoredBalls - Number of balls, color (red, green, blue) array, continuous
              // CAUTION: If set to continuous then this effect will never stop!!!

    case 16 : {
                // mimic BouncingBalls
                byte onecolor[1][3] = { {0xff, 0x00, 0x00} };
                BouncingColoredBalls(1, onecolor, false);
                break;
              }

    case 17 : {
                // multiple colored balls
                byte colors[3][3] = { {0xff, 0x00, 0x00},
                                      {0xff, 0xff, 0xff},
                                      {0x00, 0x00, 0xff} };
                BouncingColoredBalls(3, colors, false);
                break;
              }

    case 18 : {
                // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
                meteorRain(0xff,0xff,0xff,10, 64, true, 30);
                break;
              }
  }
}

void changeEffect() {
  if (digitalRead (BUTTON) == HIGH) {
    selectedEffect++;
    EEPROM.put(0, selectedEffect);
    asm volatile ("  jmp 0");
  }
}

// *************************
// ** LEDEffect Functions **
// *************************

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    // Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    // Fade OUT
    for(int k = 255; k >= 0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;

  for(int k = 0; k < 256; k=k+1) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }

  for(int k = 255; k >= 0; k=k-2) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }
}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
  }

 delay(EndPause);
}

void HalloweenEyes(byte red, byte green, byte blue,
                   int EyeWidth, int EyeSpace,
                   boolean Fade, int Steps, int FadeDelay,
                   int EndPause){
  randomSeed(analogRead(0));

  int i;
  int StartPoint  = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
  int Start2ndEye = StartPoint + EyeWidth + EyeSpace;

  for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, red, green, blue);
    setPixel(Start2ndEye + i, red, green, blue);
  }

  showStrip();

  if(Fade==true) {
    float r, g, b;

    for(int j = Steps; j >= 0; j--) {
      r = j*(red/Steps);
      g = j*(green/Steps);
      b = j*(blue/Steps);

      for(i = 0; i < EyeWidth; i++) {
        setPixel(StartPoint + i, r, g, b);
        setPixel(Start2ndEye + i, r, g, b);
      }

      showStrip();
      delay(FadeDelay);
    }
  }

  setAll(0,0,0); // Set all black

  delay(EndPause);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}

// used by NewKITT
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);

    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);

    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);

    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);

    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);

    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);

    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);

  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),red,green,blue);
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }

  delay(SpeedDelay);
}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);

  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }

  delay(SpeedDelay);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
  setAll(red,green,blue);

  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,0xff,0xff,0xff);
  showStrip();
  delay(SparkleDelay);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;

  for(int i=0; i<NUM_LEDS*2; i++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }

      showStrip();
      delay(WaveDelay);
  }
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  for(uint16_t i=0; i<NUM_LEDS; i++) {
      setPixel(i, red, green, blue);
      showStrip();
      delay(SpeedDelay);
  }
}

void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}

// used by rainbowCycle and theaterChaseRainbow
byte * Wheel(byte WheelPos) {
  static byte c[3];

  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }

  return c;
}

void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, red, green, blue);    //turn every third pixel on
      }
      showStrip();

      delay(SpeedDelay);

      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, 0,0,0);        //turn every third pixel off
      }
    }
  }
}

void theaterChaseRainbow(int SpeedDelay) {
  byte *c;

  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < NUM_LEDS; i=i+3) {
          c = Wheel( (i+j) % 255);
          setPixel(i+q, *c, *(c+1), *(c+2));    //turn every third pixel on
        }
        showStrip();

        delay(SpeedDelay);

        for (int i=0; i < NUM_LEDS; i=i+3) {
          setPixel(i+q, 0,0,0);        //turn every third pixel off
        }
    }
  }
}

void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;

  // Step 1.  Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);

    if(cooldown>heat[i]) {
      heat[i]=0;
    } else {
      heat[i]=heat[i]-cooldown;
    }
  }

  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }

  // Step 3.  Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }

  // Step 4.  Convert heat to LED colors
  for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }

  showStrip();
  delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);

  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252

  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) {                     // hottest
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) {             // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else {                               // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

void BouncingColoredBalls(int BallCount, byte colors[][3], boolean continuous) {
  float Gravity = -9.81;
  int StartHeight = 1;

  float Height[BallCount];
  float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
  float ImpactVelocity[BallCount];
  float TimeSinceLastBounce[BallCount];
  int   Position[BallCount];
  long  ClockTimeSinceLastBounce[BallCount];
  float Dampening[BallCount];
  boolean ballBouncing[BallCount];
  boolean ballsStillBouncing = true;

  for (int i = 0 ; i < BallCount ; i++) {
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
    ballBouncing[i]=true;
  }

  while (ballsStillBouncing) {
    for (int i = 0 ; i < BallCount ; i++) {
      TimeSinceLastBounce[i] =  millis() - ClockTimeSinceLastBounce[i];
      Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;

      if ( Height[i] < 0 ) {
        Height[i] = 0;
        ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
        ClockTimeSinceLastBounce[i] = millis();

        if ( ImpactVelocity[i] < 0.01 ) {
          if (continuous) {
            ImpactVelocity[i] = ImpactVelocityStart;
          } else {
            ballBouncing[i]=false;
          }
        }
      }
      Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }

    ballsStillBouncing = false; // assume no balls bouncing
    for (int i = 0 ; i < BallCount ; i++) {
      setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
      if ( ballBouncing[i] ) {
        ballsStillBouncing = true;
      }
    }

    showStrip();
    setAll(0,0,0);
  }
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
  setAll(0,0,0);

  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {

    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );
      }
    }

    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }

    showStrip();
    delay(SpeedDelay);
  }
}

// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    uint32_t oldColor;
    uint8_t r, g, b;
    int value;

    oldColor = strip.getPixelColor(ledNo);
    r = (oldColor & 0x00ff0000UL) >> 16;
    g = (oldColor & 0x0000ff00UL) >> 8;
    b = (oldColor & 0x000000ffUL);

    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);

    strip.setPixelColor(ledNo, r,g,b);
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
 #endif
}

// *** REPLACE TO HERE ***

// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

use millis to check
static unsigned long lastChange = millis();
if(auto_changing && millis()-lastChange  > 10*1000){
    selectedEffect++;
    EEPROM.put(0,selectedEffect);
    lastChange = millis();
}

Put this before the if(selectedEffect>18) and it will cycle each effect for at least 10 seconds before going to the next effect.

BTW I suggest that you rejig your code like blinkWithoutDelay so you don't need to use interrupts the flash memory and jmp 0 and can instead avoid that.
It'll require quite a bit of refactoring though but will allow you to fade from one effect to the next smoothly.

I got error when put your part of code after if(selectedEffect>18), that says next : 'auto_changing' was not declared in this scope
That's screenshot ( https://dl.dropboxusercontent.com/s/1l1342opvq43n6x/javaw_2018-05-31_14-21-35.png )

@VanderAGSN forgot to add that auto_changing is the enable variable for the auto changing mode. When true it will cycle the states if false the current state will remain active. How you change that is up to you

Code successfully accepted in arduino, but effects not switched, have any ideas? Also thanks for help!

Please post the updated code in your question, so that we can see how you followed ratchet freaks instructions


text:
arduino LCD help
I am trying to create smart clock with alarm using an Arduino Uno.
My problem is when I set the alarm, I can't set the alarm again. Every time I must power off my Arduino and then power on in order to set the alarm again.
I am using:
Arduino Uno
LCD 16*2
buttons
buzzer and LED
RTC
My code works like this:
At the beginning it will let you to set date and time by buttons and you can set alarm too.
When it reaches the alarm time, it turns on the melody of buzzer and LEDs turn on.
but
I want to turn off the alarm so I can set another alarm.
This is my code:
#include "RTClib.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int alarmState = 0;
int alarmSnooze = 0;
int btnSet = 0;
int btnSel = 0;
int alarmValue = 0;
int alarmCounter = 0;
boolean turnOffAlarm = false;
boolean settingAlarm = false;
int counter = 0;
boolean initialCount = true;
boolean alarmSet = false;
int timeArray[6]; // 0=Hour, 1=Minutes, 2=day, 3=Day of Week, 4=Month, 5=Year;
int timeCounter = 0;
int alarmArray[2];
char* days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
RTC_DS1307 rtc;    // Create a RealTimeClock object
DateTime now; // Read data from the RTC Chip

//////////////////////////
 ///difine button////
int  b6=6;
int b7=7;
int b8=8;
int b9=9;
////////////////////

///melody///
#include "pitches.h"

const int piezoPin = 13; //piezo
const int rPin = A0;  //red LED
const int gPin = A1;  //green LED
const int bPin = A2;  //blue LED
const int pPin = 6;  //pushbutton

int ledState = 0;
int ledOn = false;

// notes
int melody[] = {
  NOTE_F5,NOTE_D5,NOTE_AS4,NOTE_D5,NOTE_F5,NOTE_AS5,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_D5,NOTE_E5,NOTE_F5,
  NOTE_F5,NOTE_F5,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_A5,NOTE_AS5,NOTE_AS5,NOTE_F5,NOTE_D5,NOTE_AS4,
  NOTE_D6,NOTE_D6,NOTE_D6,NOTE_DS6,NOTE_F6,NOTE_F6,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_DS6,
  0,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_A5,NOTE_AS5,NOTE_D5,NOTE_E5,NOTE_F5,
  NOTE_F5,NOTE_AS5,NOTE_AS5,NOTE_AS5,NOTE_A5,NOTE_G5,NOTE_G5,NOTE_G5,NOTE_C6,NOTE_DS6,NOTE_D6,NOTE_C6,NOTE_AS5,NOTE_AS5,NOTE_A5,
  NOTE_F5,NOTE_F5,NOTE_AS5,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_F6,NOTE_AS5,NOTE_C6,NOTE_D6,NOTE_DS6,NOTE_C6,NOTE_AS5
};

// durations: 2 = half note, and 8/3,4,6,8,12. It appears that 8/2.9 is more accurate than 8/3.
float noteDurations[] = {
  6,12,4,4,4,2,6,12,4,4,4,2,
  8,8,8/2.9,8,4,2,8,8,4,4,4,4,4,
  6,12,4,4,4,2,8,8,4,4,4,2,
  8,8,8/2.9,8,4,2,8,8,4,4,4,2,
  4,4,4,8,8,4,4,4,4,8,8,8,8,4,4,
  8,8,8/2.9,8,8,8,2,8,8,4,4,4,2
};

// calculates the number of elements in the melody array.
int musicLength=sizeof(melody)/sizeof('NOTE_F5');

//////////////////////////

void setup()
{

  pinMode(pPin, INPUT);
  pinMode(rPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);

  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(10, OUTPUT);
  rtc.begin(); // Start the RTC library code
  rtc.adjust(DateTime(0, 0, 0, 0, 0, 0));
}
void loop()

{ alarmState = digitalRead(b9);
  alarmSnooze = digitalRead(b6);
  btnSet = digitalRead(b7);
  btnSel = digitalRead(b8);

  if (timeCounter == 0)
  {
    if(initialCount == true){
      counter=0;
      initialCount = false;
    }
    setHour();
  }
  else if (timeCounter == 1)
  {
    if(initialCount == true){
      counter=0;
      initialCount =false;
    }
    setMinute();
  }
  else if (timeCounter == 2)
  {
    if(initialCount == true){
      counter= 1;
      initialCount=false;
    }
    setDay();
  }
  else if (timeCounter == 3)
  {
    if(initialCount == true){
      counter = 0;
      initialCount =false;
    }
    setDOW();
  }
  else if (timeCounter == 4)
  {
    if(initialCount==true){
      counter=0;
      initialCount=false;
    }
    setMonth();
  }
  else if (timeCounter == 5)
  {
    if(initialCount==true){
      counter=0;
      initialCount=false;
    }
    setYear();
  }
  else if (timeCounter == 6)
  {
    rtc.adjust(DateTime(2000+timeArray[5], timeArray[4], timeArray[2], timeArray[0], timeArray[1], 0));
    timeCounter++;
    delay(200);
  }
  else if (timeCounter > 6){
    if(alarmState == LOW&&settingAlarm==false){
      now = rtc.now();
      digitalClockDisplay();
    }
    else if(alarmState == HIGH||settingAlarm==true)
    {
      settingAlarm = true;
      if(alarmValue==0){
        if(initialCount==true)
        {
          lcd.clear();
          alarmCounter=0;
          initialCount=false;
        }
        setAlarmHour();
      }
      else if(alarmValue==1){
        if(initialCount==true)
        {
          alarmCounter=0;
          initialCount=false;
        }
        setAlarmMinute();
      }
      else if(alarmValue>1){
        alarmSet = true;
        settingAlarm = false;
      }
    }
    if(alarmArray[0]==now.hour()&&alarmArray[1]==now.minute()&&turnOffAlarm==false&&alarmSet==true&&alarmSnooze==LOW){
       for (int thisNote = 0; thisNote < musicLength; thisNote++) {
      // blink the three LEDs in sequence
      if (thisNote%3==0){
        digitalWrite(rPin, HIGH);
        digitalWrite(gPin, LOW);
        digitalWrite(bPin, LOW);
      }
      else if (thisNote%3==1){
        digitalWrite(rPin, LOW);
        digitalWrite(gPin, HIGH);
        digitalWrite(bPin, LOW);
      }
      else if (thisNote%3==2){
        digitalWrite(rPin, LOW);
        digitalWrite(gPin, LOW);
        digitalWrite(bPin, HIGH);
      }

      // calculate the note duration. change tempo by changing 2000 to other values
      int noteDuration = 2000/noteDurations[thisNote];
      tone(piezoPin, melody[thisNote],noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well
      float pauseBetweenNotes = noteDuration * 1.30;

      //split the delay into two parts and check to see
      //whether the pushbutton is pressed to turn off
      //the sound and light
      delay(pauseBetweenNotes/2);
      if(digitalRead(pPin)==HIGH) {
        break;
      }
      delay(pauseBetweenNotes/2);
      if(digitalRead(pPin)==HIGH) {
        break;
      }

    }
      digitalWrite(13, HIGH);

    }

    else if(alarmArray[0]==now.hour() && alarmArray[1]==now.minute()&&turnOffAlarm==false&&alarmSet==true&&alarmSnooze==HIGH){
      noTone(13);
      digitalWrite(13, LOW);
      digitalWrite(rPin, LOW);
    digitalWrite(gPin, LOW);
    digitalWrite(bPin, LOW);
      turnOffAlarm = true;
    }
  }
}

void nextValue(){
  btnSel=LOW;
  // Update array value with counter
  timeArray[timeCounter] = counter;
  counter=0;
  initialCount = true;
  timeCounter++;
  delay(200);
  lcd.clear();
}
void nextAlarmValue(){
  btnSel=LOW;
  // Update array value with counter
  alarmArray[alarmValue] = alarmCounter;
  alarmCounter=0;
  initialCount = true;
  alarmValue++;
  delay(200);
  lcd.clear();
}

void setAlarmHour(){
   if(alarmCounter==24){
    alarmCounter=0;
    lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set alarm hour");
  lcd.setCursor(7,1);
  lcd.print(alarmCounter);
  if (btnSet==HIGH)
  {
    alarmCounter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextAlarmValue();
 }
}

void setAlarmMinute(){
  if(alarmCounter==59){
  alarmCounter=0;
  lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set alarm minute");
  lcd.setCursor(7,1);
  lcd.print(alarmCounter);
  if (btnSet==HIGH)
  {
    alarmCounter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextAlarmValue();
 }
}

void setDOW(){
  if(counter==7){
    counter=0;
    lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set day of week");
  lcd.setCursor(7,1);
  lcd.print(days[counter]);
  if (btnSet==HIGH)
  {
    counter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextValue();
 }
}
void setHour()
{
  if(counter==24){
    counter=0;
    lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set hour");
  lcd.setCursor(7,1);
  lcd.print(counter);
  if (btnSet==HIGH)
  {
    counter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextValue();
 }
}

// Function to set minutes
void setMinute()
{
  if(counter==60){
    counter=0;
    lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set minute");
  lcd.setCursor(7,1);
  lcd.print(counter);
  if (btnSet==HIGH)
  {
    counter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextValue();
 }
}

// Function to set date
void setDay()
{
  if(counter==32){
    counter=1;
    lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set day");
  lcd.setCursor(7,1);
  lcd.print(counter);
  if (btnSet==HIGH)
  {
    counter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextValue();
 }
}

// Function to set month
void setMonth()
{
  if(counter==12){
    counter=0;
    lcd.clear();
  }
  lcd.setCursor(0,0);
  lcd.print("Set month");
  lcd.setCursor(7,1);
  lcd.print(months[counter]);
  if (btnSet==HIGH)
  {
    counter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextValue();
 }
}

// Function to set year
void setYear()
{
  lcd.setCursor(0,0);
  lcd.print("Set year");
  lcd.setCursor(7,1);
  lcd.print(counter);
  if (btnSet==HIGH)
  {
    counter++;
    delay(200);
  }
 else if(btnSel==HIGH)
 {
  nextValue();
 }
}

void digitalClockDisplay(){
  // digital clock display of the time
  long hours;
  String amOrPm = "";
  if(now.hour() > 12){
    hours = now.hour() - 12;
    amOrPm = "PM";
  }
  else if(now.hour()==0){
    hours=12;
    amOrPm = "AM";
  }
  else{
    hours = now.hour();
    amOrPm = "AM";
  }
  lcd.setCursor(0,0);
  lcd.print(days[timeArray[3]]);
  lcd.print(" ");
  lcd.print(months[timeArray[4]]);
  lcd.print(" ");
  lcd.print(now.day());
  lcd.print(" ");
  lcd.print(now.year());
  lcd.setCursor(0,1);
  lcd.print(hours);
  printDigits(now.minute());
  printDigits(now.second());
  lcd.print(" ");
  lcd.print(amOrPm);
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  lcd.print(":");
  if(digits < 10)
    lcd.print('0');
  lcd.print(digits);
}

What did you try to do by sizeof(melody)/sizeof('NOTE_F5')??? What is the point of sizeof('NOTE_F5') specifically? What did the compiler tell you about 'NOTE_F5'?

It looks like you haven't reset your state variable turnOffAlarm after you turn off the alarm.

Since the question is tagged [code-review]

char* days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

This should be a const array of const char *, not of char *.
const char *const days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

Same goes for months.
int  b6=6;
...
const int piezoPin = 13;
...

Why some of your pins are const and others are not? I don't see any attempts or reasons to change the value of b6 in the code. Why is it not const?
int melody[] = { ... };
float noteDurations[] = { ... };

Both are supposed to be be const, apparently.
// calculates the number of elements in the melody array.
int musicLength=sizeof(melody)/sizeof('NOTE_F5');

Really? What is 'NOTE_F5'? What did your compiler tell you about it? Did you just ignore the compiler's message?
Should be
const int musicLength = sizeof melody / sizeof *melody;

I'd prefer unsigned or size_t, but let's not open this can of worms.
In a single-file sketch all global variables (i.e. the ones that really need to be global) should be declared either const or static (or placed in an anonymous namespace). Declaring a global variable that is not const or static requires a good reason for doing so.


text:
Prints to the serial monitor are being overwritten
Using esp32, Arduino IDE 1.8.9 on OSX.
My code is interspersed with Serial.println() writes to the serial monitor of various status messages.
As far as I can tell, if a println is not fully written out to the serial monitor before another println is sent, then the first println does not finish displaying properly, and appears to garbled.
I'm using baud rate 115200.
I'm guessing that there's no flow control between the serial monitor and the computer.
It's strange though because I've been doing quite a bit of Arduino IDE programming for a while now but I don't ever recall this being an issue.
Does anyone have any idea of what might be going on, and how I can ensure that messages are fully displayed on the serial monitor?

I've never had such an issue - perhaps you're doing something unusual in your code - are you able to create a minimal piece of code that produces this odd behaviour

There is no flow control. Please post code that exhibits this behaviour - perhaps you have a bug.


text:
Alternative distance-meter, HC-SR04 doesn't work very well
On door to my room there is HC-SR04 that triggers led-wave. The shorter the distance, the faster the led-wave (8 leds).
The circuit works fine in synthetic tests – moving hand or flat object towards the sensor generates gradually accelerating wave.
However, when placed on door to detect approaching persons it generates short correct (<=170 cm) impulses and the wave starts and immediately stops, again starts, etc. I guess HC-SR04 isn't good enough to detect people.
Are there any alternatives to this sensor that will correctly detect human approaching?

You should run some tests that show the calculated values. You may want to filter out any values that are extremely high (and disregard them).

Are you powering it differently in your tests vs on the door?

The typical HC-SR04 code uses pulseIn() with a default 1 second timeout. If there is nothing for the sound to reflect off in range (i.e., a wall within a couple of meters) the pulseIn() will cause massive delays in your operation.

https://arduino.stackexchange.com/questions/39388/hc-sr04-returning-incorrect-distances Use the code in this link to solve your problem.

Try to find where the error comes from.
I suggest loading up a piece of code that outputs the measurements to through the serial terminal.

You should typically filter out any values that are > 200cm (since it's out of range).
You should take the average of a few readings, to be more accurate and less error-prone.
Find why some readings are weird, is the object fuzzy (may absorb the ultrasound)?

If all fails, you may look at IR distance sensors (SHARP) like:
https://www.adafruit.com/product/164
or
https://www.adafruit.com/product/1568
Alternatively, you could use a combination of (multiple) IR and ultrasonic sensors. But I doubt you really need that mount of accuracy.
You could also go for a Raspberry Pi + camera and openCV, but that's a whole other matter.

I've had to take not average, but minimum value, from last 7 values (distances) – it looked like the sensor was returning correct distance to the moving object mixed with distance to the wall behind the person. Also, NewPing beautifully fixed pulseIn() lags

Yes, it may be that the sensor sometimes doesn't see the object, this may be of various reason, such as the sound not bouncing back into the "receiver". If the wall is at 200cm, you could filter out values that are below it, so that you automatically only sense when there is someone.
But good that you've found out a method that works for your case :D

In general the HC-SR04 is controlled using pulseIn().
When there is nothing within range for the sensor to detect it usually has to wait for pulseIn() to time out. That can take up to a second by default.  While that is happening the rest of the sketch cannot do anything.
You can reduce the timeout in the pulseIn() function, but it's still not going to be perfect - you'll still get a delay which will interrupt your LED sequences.
The ideal way will be to create a "free running" distance sensor system - use a timer to periodically start a ping, and use the Input Capture module of the ATMega to measure the time between the start and end edges of the returning pulse. Everything will happen asynchronously to the rest of your sketch then.
I am not aware of any libraries for Arduino boards, but I have one for the PIC32 based chipKIT boards that I use. It can't ever work on AVR based boards, but you can use it to see the general concepts and how things fit together.

Good points, I had a hard time distilling what the problem was, since the question isn't that clear. But this could indeed also be a problem. One should always try to make his code non-blocking :) Using hardware timers directly, may make the project unportable to other Arduino devices. You could use millis() and code based on a statemachine.

@paul You could, though you would be hard pressed to get the timing resolution you need for ultrasound work with that - you're working with microseconds, not milliseconds.

Ah, indeed, I was thinking for planning the periodical scanning. 'micros()' is also a thing, but I'd rather not?


text:
avrdude: stk500_recv(): programmer is not responding after serial
I have searched but have not found any solution to my problem so I am asking it here.  I make a program in python that makes serial communication with the Arduino. I started to upload my Arduino code but I forgot that my python program was open in the terminal (I use Ubuntu). So, I think the Arduino code and python output went to the same port which the Arduino is on. After that I couldn't upload any code into the Arduino.
Every time it prints the following error:

avrdude: stk500_recv(): programmer is not responding
  avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

and then makes more 9 attempts.
Any help?

Likely all you really need to do is exit/kill every process trying to use the Arduino, un-plug it from the USB port, and plug it back in.
This is in part because Linux doesn't really block multiple programs from trying to use the serial device at the same time, unless they take particularly efforts to claim it exclusively, but the attempted sharing may result in serial traffic that doesn't make any sense.
Another issue can be that if a still-running program was using a device that vanished, when that device is reconnected it will not be assigned to the in-use port number, but to a free one.


text:
Avoid the 10 attempts of Avrdude when programmer is not responding
Sometime I update my sketch in the Arduino environment, and when I click on the transfer arrow but forget to plug my arduino (I'm using the UART in my project so every time I need to plug/unplug some wires) it's a drama, avrdude throw this for at least 2 minutes :

avrdude: stk500_recv(): programmer is not responding
  avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x32

It's a real pain because I can't stop avrdude when this happens.
Is there a way to configure the Arduino environment to disable it?

Good question, I thought it would be an easy fix, but couldn't find anything in the AVRDude command line options (http://www.nongnu.org/avrdude/user-manual/avrdude_4.html) or the avrdude config files.

On Linux I just open a terminal and type killall avrdude and it stops it...

I didn't thought about this, good work around.

Also I use UECIDE rather than the Arduino IDE because I especially programmed a "stop" button in to get around this very problem.

Unfortunately, MAX_SYNC_ATTEMPTS is a constant in the source code, and one which appears several times.
avrdude is an open source project, so customizing and building it should be relatively straightforward.  Since it is a numeric rather than string value, and is checked in several places, simply modifying the binary is likely to be tricky.
One can of course manually kill the process, though it is annoying to have to.
Another approach could be to write a wrapper which might potentially do some sanity checking first (does any other process have the port open?) and then would launch avrdude as its child, passing through all the arguments.  By monitoring the output before passing it on, it should be possible to detect this message and terminate the avrdude instance automatically.

I had the same question and found following solution in linux: write a script,
#!/bin/bash
avrdude=`ps -C avrdude | tail -n 1 | head -c 7`
kill $avrdude

store it and connect it with a shortcut


text:
Is there a good Arduino enclosure for that works with the Olimex MIDI shield
I have a MIDI project I put together using an Arduino UNO R3 and the Olimex Shield-MIDI.

I want to install the project permanently in my Guitar rack so I want a decent enclosure, but there doesn't seem to be anything that would support the extra height that the MIDI ports have, relative to the Arduino + Ethernet enclosures.
Has anyone come up with a good solution for Arduino + MIDI projects?  A metal enclosure would be a plus.

You would need a custom enclosure, or some random enclosure with custom holes. How much do you balance cost against DIY competence? :)

By Guitar rack, do you mean something like this?

Your best bet is to 3D print the enclosure.
There are many places that will 3D print your enclosure for you and most will mail it to you as well. I would recommend Shapeways as they are fairly reasonable in price and ship worldwide.
If you are a handy DIY person you could use SketchUp or Tinkercad to design your enclosure. Also there are many Arduino enclosures on Thingiverse that you could use as a starting point.
Alternatively there are often places that will design (and then 3D print) the enclosure for you, you just have to supply your hardware. There are often a few places like this in each city.


text:
Error running the code
The error I get is as follows:
F:\Josh\GIZDUINO PROJECT\Joshua\arduino-1.8.3\libraries\arduino-ledcube-master\examples\ledcube\ledcube.pde: In function 'void loop()':

ledcube:49: error: taking address of temporary array
         cube.createFrame((byte[]) {0,6, 1,6, 2,6}, 6, 80),
                                                         ^
ledcube:50: error: taking address of temporary array
         cube.createFrame((byte[]) {0,7, 1,7, 2,7}, 6, 70),
                                                         ^
ledcube:51: error: taking address of temporary array
         cube.createFrame((byte[]) {0,8, 1,8, 2,8}, 6, 60),
                                                         ^
ledcube:52: error: taking address of temporary array
         cube.createFrame((byte[]) {0,5, 1,5, 2,5}, 6, 50),
                                                         ^
ledcube:53: error: taking address of temporary array
         cube.createFrame((byte[]) {0,2, 1,2, 2,2}, 6, 40),
                                                         ^
ledcube:54: error: taking address of temporary array
         cube.createFrame((byte[]) {0,1, 1,1, 2,1}, 6, 30),
                                                         ^
ledcube:55: error: taking address of temporary array
         cube.createFrame((byte[]) {0,0, 1,0, 2,0}, 6, 20),
                                                         ^
ledcube:56: error: taking address of temporary array
         cube.createFrame((byte[]) {0,3, 1,3, 2,3}, 6, 10)
                                                         ^
F:\Josh\GIZDUINO PROJECT\Joshua\arduino-1.8.3\libraries\arduino-ledcube-master\examples\ledcube\ledcube.pde:115:38: warning: narrowing conversion of '(((int)cube.LedCube::getLevels()) + 1)' from 'int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]
     byte planes[] = {cube.getLevels()+1,cube.getLevels(),cube.getLevels()*2,1};
                                      ^
F:\Josh\GIZDUINO PROJECT\Joshua\arduino-1.8.3\libraries\arduino-ledcube-master\examples\ledcube\ledcube.pde:115:74: warning: narrowing conversion of '(((int)cube.LedCube::getLevels()) * 2)' from 'int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]
     byte planes[] = {cube.getLevels()+1,cube.getLevels(),cube.getLevels()*2,1};
                                                                          ^

exit status 1
taking address of temporary array

Learn C syntax.

Welcome to Arduino Stack Exchange.  Please take the tour at https://arduino.stackexchange.com/Tour to see how to get the most out of this site.  You will see the difference between between how this works here and your question.  Perhaps you can edit this to make it answerable; but if not then you will be ready for next time.

Gizduino is garbage. The fact that they instruct you to install their hardware definitions to the IDE installation folder shows they lack the most basic understanding of Arduino. Send the board back for a refund.

Three remarks to your question.

Avoid using UPPERCASE as that is considered to be a typographical notation for shouting. See http://practicaltypography.com/all-caps.html
The compiler error is due to that you are using a temporary byte vector as parameter. You should declare the vector as a local or global variable and pass the reference. See https://stackoverflow.com/questions/42332229/how-to-pass-a-temporary-array or web-search for more info.
The compiler warning is due to an implicit conversion from int to byte. The conversion may result in a loss of precision thus the warning. You can use a type cast to avoid this. The type case will tell the compiler that you know what you are doing.

Cheers!


text:
Reading SD card with Sparkfun MP3 Shield
So I am using an Arduino Mega with the Sparkfun MP3 shield. And I can't seem to read the µSD card. It's formatted in FAT32 and it has a single .txt file on it. I always get this error:
SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Is there a wiring/soldering problem?
errorCode: 0x1, errorData: 0xff

I have tried chipSelect 8,9 and 10. I've seen all the other forum threads about the error but none apply here as it is a bought board and not self built, so the wiring should be correct. I've tried software that has ran on the same configuration, and I get the same error.
Thanks in advance,
Michidez
The code that I use to try the SD card (QuickStart, from the SdFat Library):
// Quick hardware test
#include <SdFat.h>
// Test with reduced SPI speed for breadboards.
// Change spiSpeed to SPI_FULL_SPEED for better performance
// Use SPI_QUARTER_SPEED for even slower SPI bus speed
const uint8_t spiSpeed = SPI_HALF_SPEED;
//------------------------------------------------------------------------------
// Normally SdFat is used in applications in place
// of Sd2Card, SdVolume, and SdFile for root.
Sd2Card card;
SdVolume volume;
SdFile root;

// Serial streams
ArduinoOutStream cout(Serial);

// input buffer for line
char cinBuf[40];
ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));

// SD card chip select
int chipSelect;

void cardOrSpeed() {
  cout << pstr(
    "Try another SD card or reduce the SPI bus speed.\n"
    "The current SPI speed is: ");
  uint8_t divisor = 1;
  for (uint8_t i = 0; i < spiSpeed; i++) divisor *= 2;
  cout << F_CPU * 0.5e-6 / divisor << pstr(" MHz\n");
  cout << pstr("Edit spiSpeed in this sketch to change it.\n");
}

void reformatMsg() {
  cout << pstr("Try reformatting the card.  For best results use\n");
  cout << pstr("the SdFormatter sketch in SdFat/examples or download\n");
  cout << pstr("and use SDFormatter from www.sdcard.org/consumer.\n");
}

void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo

  cout << pstr(
    "\nSD chip select is the key hardware option.\n"
    "Common values are:\n"
    "Arduino Ethernet shield, pin 4\n"
    "Sparkfun SD shield, pin 8\n"
    "Adafruit SD shields and modules, pin 10\n");
}

bool firstTry = true;
void loop() {
  // read any existing Serial data
  while (Serial.read() >= 0) {}

  if (!firstTry) cout << pstr("\nRestarting\n");
  firstTry = false;

  cout << pstr("\nEnter the chip select pin number: ");
  cin.readline();
  if (cin >> chipSelect) {
    cout << chipSelect << endl;
  } else {
    cout << pstr("\nInvalid pin number\n");
    return;
  }
  if (!card.init(spiSpeed, chipSelect)) {
    cout << pstr(
      "\nSD initialization failed.\n"
      "Do not reformat the card!\n"
      "Is the card correctly inserted?\n"
      "Is chipSelect set to the correct value?\n"
      "Is there a wiring/soldering problem?\n");
    cout << pstr("errorCode: ") << hex << showbase << int(card.errorCode());
    cout << pstr(", errorData: ") << int(card.errorData());
    cout << dec << noshowbase << endl;
    return;
  }
  cout << pstr("\nCard successfully initialized.\n");
  cout << endl;

  uint32_t size = card.cardSize();
  if (size == 0) {
    cout << pstr("Can't determine the card size.\n");
    cardOrSpeed();
    return;
  }
  uint32_t sizeMB = 0.000512 * size + 0.5;
  cout << pstr("Card size: ") << sizeMB;
  cout << pstr(" MB (MB = 1,000,000 bytes)\n");
  cout << endl;

  if (!volume.init(&card)) {
    if (card.errorCode()) {
      cout << pstr("Can't read the card.\n");
      cardOrSpeed();
    } else {
      cout << pstr("Can't find a valid FAT16/FAT32 partition.\n");
      reformatMsg();
    }
    return;
  }
  cout << pstr("Volume is FAT") << int(volume.fatType());
  cout << pstr(", Cluster size (bytes): ") << 512L * volume.blocksPerCluster();
  cout << endl << endl;

  root.close();
  if (!root.openRoot(&volume)) {
    cout << pstr("Can't open root directory.\n");
    reformatMsg();
    return;
  }

cout << pstr("Files found (name date time size):\n");
  root.ls(LS_R | LS_DATE | LS_SIZE);

  if ((sizeMB > 1100 && volume.blocksPerCluster() < 64)
    || (sizeMB < 2200 && volume.fatType() == 32)) {
    cout << pstr("\nThis card should be reformatted for best performance.\n");
    cout << pstr("Use a cluster size of 32 KB for cards larger than 1 GB.\n");
    cout << pstr("Only cards larger than 2 GB should be formatted FAT32.\n");
    reformatMsg();
    return;
  }
  // read any existing Serial data
  while (Serial.read() >= 0) {}
  cout << pstr("\nSuccess!  Type any character to restart.\n");
  while (Serial.read() < 0) {}
}

It would help if you actually posted code.

Any code gives me the error. Including 2 examples from SdFat: QuickStart and SdInfo. But I'll add QuickStart to the post.

Firstly, where did you get the get the SdFat library from? A quick search on GitHub returned 34 results: GitHub search of SdFat. Of those, Greiman and Adafruit were the highest results on Google.
The reason I mention this is that you could be using a library that has issues or requires something specific in the hardware. I would suggest using the Adafruit version, as that would be the most scrutinized and hence the most stable. It appears very similar to the Arduino library (mentioned below).
Arduino has a SD library that comes with the Arduino IDE. It is simply called SD. There are 6 example programs:

CardInfo: SD card test - This example shows how use the utility libraries on which the'SD library is based in order to get info about your SD card. Very useful for testing a card when you're not sure whether its working or not.
ReadWrite:  SD card read/write - shows how to read and write data to and from an SD card file.
Files: SD card basic file example - shows how to create and destroy an SD card file.
ListFiles:  Listfiles - This example shows how print out the files in a
directory on a SD card.
DumpFile:   SD card file dump - shows how to read a file from the SD card using the SD library and send it over the serial port.
Datalogger: SD card datalogger - shows how to log data from three analog sensors.

Use the CardInfo example program to verify that your setup is correct. Then progress to one of the other examples such as ListFiles or Dumpfile.