arduino mega 2560 lcd display code factory

Spice up your Arduino project with a beautiful large touchscreen display shield with built in microSD card connection. This TFT display is big (5" diagonal) bright (12 white-LED backlight) and colorful 480x272 pixels with individual pixel control. As a bonus, this display has a capacitive touch panel attached on screen by default.

The shield is fully assembled, tested and ready to go. No wiring, no soldering! Simply plug it in and load up our library - you"ll have it running in under 10 minutes! Works best with any classic Arduino Mega 2560.

This display shield has a controller built into it with RAM buffering, so that almost no work is done by the microcontroller. You can connect more sensors, buttons and LEDs.

Of course, we wouldn"t just leave you with a datasheet and a "good luck!" - we"ve written a full open source graphics library at the bottom of this page that can draw pixels, lines, rectangles, circles and text. We also have a touch screen library that detects x,y and z (pressure) and example code to demonstrate all of it. The code is written for Arduino but can be easily ported to your favorite microcontroller!

If you"ve had a lot of Arduino DUEs go through your hands (or if you are just unlucky), chances are you’ve come across at least one that does not start-up properly.The symptom is simple: you power up the Arduino but it doesn’t appear to “boot”. Your code simply doesn"t start running.You might have noticed that resetting the board (by pressing the reset button) causes the board to start-up normally.The fix is simple,here is the solution.

arduino mega 2560 lcd display code factory

This is a very popular LCD Keypad shield for Arduino or Freeduino board. It includes a 2x16 LCD display and 6 momentary push buttons. Pins 4, 5, 6, 7, 8, 9 and 10 are used to interface with the LCD. Analog Pin 0 is used to read the push buttons. The LCD shield supports contrast adjustment and backlit on/off functions. It also expands analog pins for easy analog sensor reading and display.

The LCD Keypad shield is developed for Arduino compatible boards, to provide a user-friendly interface that allows users to go through the menu, make selections etc. It consists of a 1602 white character blue backlight LCD. The keypad consists of 5 keys — select, up, right, down and left. To save the digital IO pins, the keypad interface uses only one ADC channel. The key value is read through a 5 stage voltage divider.

Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function"s parameters. for example:

Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display. begin() needs to be called before any other LCD library commands.for example:

The J1-J8 include the both the user interface, i.e. Analog pins, APC220(Serial) pins, Digital pins, and the pins connected with the lower Arduino card, e.g. Uno/ Leonardo. Here is a simple mapping picture.

It works well if uploaded by Arduino 1.5.3 version, however, the latest 1.6.* have discard pin Definition for Edison. So you have to add pinMode(); into the setup() like this:

arduino mega 2560 lcd display code factory

Using a display is a common need to have data visualization for projects including mobile screen. I2C 16X2 Liquid Crystal Character LCD Display is one of most used device and can be interfaced to Arduino Uno by using Arduino IDE

Liquid crystal display is an important part of a system and it helps to display the different constraints of the project. There are many types of LCD displays are available in the market and they can be easily identified by the interface; most of the LCD displays have ten pin interfaces and require appropriate cabling and code. The I2C LCD display has compatible driver circuitry of PCF8574 I2C chip which make simpler the cabling phase.

The most common family of LCD is 16×2 characters LCD which has sixteen columns and two rows of the characters and these can be effectively programmed in an Arduino environment. The pictorial view of the 16×2 LCD is shown in the figure.

In this tutorial, the focus of the work is character LCD. The word characters mean that alphabets (A, B, C… Z, a, b, … z and symbols) and decimals (1,2,3) can be displayed on this LCD. Other graphics like graphs, waveforms are not able to be displayed on it.

I2C LCD contains 4 pins, which are VCC, GND, SCL and SDA. SCL and SDA are dedicated to i2C communication. Every microcontroller has dedicated pins of I2C. For Arduino Uno are A4 (SDA) and A5 (SCL).

Connect your PC to Arduino and open Arduino IDE. For the very first steps, you can refer to Connecting Connecting Windows PC with Arduino tutorial. Download the “arduinoLCD” code and library from this link

Extract the folder from your PC. You will have a folder named “arduinoLCD” containing a file named “arduinoLCD.ino”. Open this file with your Arduino IDE.

This is the section before setup which is used for globe variables defining and libraries additions. Wire.h is the library for I2C two-wire communication, Liquid_crystal_I2C is an LCD library that communicates in the I2C communication protocol. Child of the library is created in the third line, which defines 0x27 as the i2c address, 16 are the columns while 2 are the rows. If you have a 20X4 LCD, just write down 20 by replacing 16 and 4 by changing 2.

This is the setup section in which LCD is initialised by lcd.begin() command, while LCD contains a light that can be turned on and off. When lcd.backlight is initialised, it turns ON the LCD lights. Character LCD comes in blue and yellow backlights.

In the loop section, LCD cursors are defined at which character needs to be written, lcd.setCursor (0,0) means cursor should be at the location of column 0 and row 0. lcd.print(“Seconds”) deals the seconds as a string and directly print it. If what is written is lcd.print(seconds), without double commas, the code will consider it as a variable, which should be defined.

Lcd.print(millis()/1000) where millis() is the time of the program when the Arduino board started, dividing by 1000 means milliseconds converted to seconds.

From your Arduino IDE, compile the code. Once compile operation has finished successfully, load it in your Arduino and the LCD Display will start showing with Arduino as in the following picture:

arduino mega 2560 lcd display code factory

Quantity and quality are both important here in Elegoo MEGA starter kit. The most essential parts in this kit are MEGA controller board and expansion board, which is a perfect clone with excellent product finish Compatible with Arduino projects. Besides, we offer other over 60 kinds of components and sensors from small parts like LED diodes, resistors and potentiometer to big parts like LCD1602, RFID module and 830 tie-points breadboard, which meet your demands for your different projects either it is simple or complex.

Sturdy quality is definitely the most important thing to Elegoo even with so many components provided we never compromised on the quality. Instead we keep improving our product quality in our own factory and we produce the products by ourselves under high standards and strict quality control. Pins and wires on some of the parts like LCD16502 and motors have been pre-soldered which is very convenient and saves your time.

arduino mega 2560 lcd display code factory

Arduino (open-source hardware and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices. Its hardware products are licensed under a CC BY-SA license, while software is licensed under the GNU Lesser General Public License (LGPL) or the GNU General Public License (GPL),manufacture of Arduino boards and software distribution by anyone. Arduino boards are available commercially from the official website or through authorized distributors.

Arduino board designs use a variety of microprocessors and controllers. The boards are equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to various expansion boards ("shields") or breadboards (for prototyping) and other circuits. The boards feature serial communications interfaces, including Universal Serial Bus (USB) on some models, which are also used for loading programs. The microcontrollers can be programmed using the C and C++ programming languages, using a standard API which is also known as the Arduino language, inspired by the Processing language and used with a modified version of the Processing IDE. In addition to using traditional compiler toolchains, the Arduino project provides an integrated development environment (IDE) and a command line tool developed in Go.

The Arduino project began in 2005 as a tool for students at the Interaction Design Institute Ivrea, Italy,sensors and actuators. Common examples of such devices intended for beginner hobbyists include simple robots, thermostats and motion detectors.

The name Arduino comes from a bar in Ivrea, Italy, where some of the founders of the project used to meet. The bar was named after Arduin of Ivrea, who was the margrave of the March of Ivrea and King of Italy from 1002 to 1014.

The Arduino project was started at the Interaction Design Institute Ivrea (IDII) in Ivrea, Italy.BASIC Stamp microcontroller at a cost of $50. In 2003 Hernando Barragán created the development platform Casey Reas. Casey Reas is known for co-creating, with Ben Fry, the Processing development platform. The project goal was to create simple, low cost tools for creating digital projects by non-engineers. The Wiring platform consisted of a printed circuit board (PCB) with an ATmega128 microcontroller, an IDE based on Processing and library functions to easily program the microcontroller.Arduino.

Following the completion of the platform, lighter and less expensive versions were distributed in the open-source community. It was estimated in mid-2011 that over 300,000 official Arduinos had been commercially produced,

At the end of 2008, Gianluca Martino"s company, Smart Projects, registered the Arduino trademark in Italy and kept this a secret from the other co-founders for about two years. This was revealed when the Arduino company tried to register the trademark in other areas of the world (they originally registered only in the US), and discovered that it was already registered in Italy. Negotiations with Martino and his firm to bring the trademark under control of the original Arduino company failed. In 2014, Smart Projects began refusing to pay royalties. They then appointed a new CEO, Federico Musto, who renamed the company Arduino SRL and created the website arduino.org, copying the graphics and layout of the original arduino.cc. This resulted in a rift in the Arduino development team.

At the World Maker Faire in New York on 1 October 2016, Arduino LLC co-founder and CEO Massimo Banzi and Arduino SRL CEO Federico Musto announced the merger of the two companies.

In April 2017, Wired reported that Musto had "fabricated his academic record... On his company"s website, personal LinkedIn accounts, and even on Italian business documents, Musto was, until recently, listed as holding a PhD from the Massachusetts Institute of Technology. In some cases, his biography also claimed an MBA from New York University." Wired reported that neither university had any record of Musto"s attendance, and Musto later admitted in an interview with Wired that he had never earned those degrees.open source licenses, schematics, and code from the Arduino website, prompting scrutiny and outcry.

By 2017 Arduino AG owned many Arduino trademarks. In July 2017 BCMI, founded by Massimo Banzi, David Cuartielles, David Mellis and Tom Igoe, acquired Arduino AG and all the Arduino trademarks. Fabio Violante is the new CEO replacing Federico Musto, who no longer works for Arduino AG.

In October 2017, Arduino announced its partnership with ARM Holdings (ARM). The announcement said, in part, "ARM recognized independence as a core value of Arduino ... without any lock-in with the ARM architecture". Arduino intends to continue to work with all technology vendors and architectures.

Under Violante"s guidance, the company started growing again and releasing new designs. The Genuino trademark was dismissed and all products were branded again with the Arduino name. As of February 2020, the Arduino community included about 30 million active users based on the IDE downloads.

In August 2018, Arduino announced its new open source command line tool (arduino-cli), which can be used as a replacement of the IDE to program the boards from a shell.

Arduino is open-source hardware. The hardware reference designs are distributed under a Creative Commons Attribution Share-Alike 2.5 license and are available on the Arduino website. Layout and production files for some versions of the hardware are also available.

Although the hardware and software designs are freely available under copyleft licenses, the developers have requested the name Arduino to be exclusive to the official product and not be used for derived works without permission. The official policy document on use of the Arduino name emphasizes that the project is open to incorporating work by others into the official product.-duino.

An early Arduino boardRS-232 serial interface (upper left) and an Atmel ATmega8 microcontroller chip (black, lower right); the 14 digital I/O pins are at the top, the 6 analog input pins at the lower right, and the power connector at the lower left.

Most Arduino boards consist of an Atmel 8-bit AVR microcontroller (ATmega8,ATmega328, ATmega1280, or ATmega2560) with varying amounts of flash memory, pins, and features.Arduino Due, based on the Atmel SAM3X8E was introduced in 2012.shields. Multiple and possibly stacked shields may be individually addressable via an I2C serial bus. Most boards include a 5 V linear regulator and a 16 MHz crystal oscillator or ceramic resonator. Some designs, such as the LilyPad,

Arduino microcontrollers are pre-programmed with a boot loader that simplifies uploading of programs to the on-chip flash memory. The default bootloader of the Arduino Uno is the Optiboot bootloader.RS-232 logic levels and transistor–transistor logic (TTL) level signals. Current Arduino boards are programmed via Universal Serial Bus (USB), implemented using USB-to-serial adapter chips such as the FTDI FT232. Some boards, such as later-model Uno boards, substitute the FTDI chip with a separate AVR chip containing USB-to-serial firmware, which is reprogrammable via its own ICSP header. Other variants, such as the Arduino Mini and the unofficial Boarduino, use a detachable USB-to-serial adapter board or cable, Bluetooth or other methods. When used with traditional microcontroller tools, instead of the Arduino IDE, standard AVR in-system programming (ISP) programming is used.

The Arduino board exposes most of the microcontroller"s I/O pins for use by other circuits. The Diecimila,Duemilanove,Unopulse-width modulated signals, and six analog inputs, which can also be used as six digital I/O pins. These pins are on the top of the board, via female 0.1-inch (2.54 mm) headers. Several plug-in application shields are also commercially available. The Arduino Nano, and Arduino-compatible Bare Bones Boardbreadboards.

Many Arduino-compatible and Arduino-derived boards exist. Some are functionally equivalent to an Arduino and can be used interchangeably. Many enhance the basic Arduino by adding output drivers, often for use in school-level education,

Arduino and Arduino-compatible boards use printed circuit expansion boards called shields, which plug into the normally supplied Arduino pin headers.3D printing and other applications, GNSS (satellite navigation), Ethernet, liquid crystal display (LCD), or breadboarding (prototyping). Several shields can also be made do it yourself (DIY).

Some shields offer stacking headers which allows multiple shields to be stacked on top of an Arduino board. Here, a prototyping shield is stacked on two Adafruit motor shield V2s.

A program for Arduino hardware may be written in any programming language with compilers that produce binary machine code for the target processor. Atmel provides a development environment for their 8-bit AVR and 32-bit ARM Cortex-M based microcontrollers: AVR Studio (older) and Atmel Studio (newer).

The Arduino integrated development environment (IDE) is a cross-platform application (for Microsoft Windows, macOS, and Linux) that is written in the Java programming language. It originated from the IDE for the languages brace matching, and syntax highlighting, and provides simple one-click mechanisms to compile and upload programs to an Arduino board. It also contains a message area, a text console, a toolbar with buttons for common functions and a hierarchy of operation menus. The source code for the IDE is released under the GNU General Public License, version 2.

The Arduino IDE supports the languages C and C++ using special rules of code structuring. The Arduino IDE supplies a software library from the Wiring project, which provides many common input and output procedures. User-written code only requires two basic functions, for starting the sketch and the main program loop, that are compiled and linked with a program stub main() into an executable cyclic executive program with the GNU toolchain, also included with the IDE distribution. The Arduino IDE employs the program avrdude to convert the executable code into a text file in hexadecimal encoding that is loaded into the Arduino board by a loader program in the board"s firmware.

From version 1.8.12, Arduino IDE windows compiler supports only Windows 7 or newer OS. On Windows Vista or older one gets "Unrecognized Win32 application" error when trying to verify/upload program. To run IDE on older machines, users can either use version 1.8.11, or copy "arduino-builder" executable from version 11 to their current install folder as it"s independent from IDE.

Most Arduino boards contain a light-emitting diode (LED) and a current-limiting resistor connected between pin 13 and ground, which is a convenient feature for many tests and program functions.Hello, World!, is "blink", which repeatedly blinks the on-board LED integrated into the Arduino board. This program uses the functions pinMode(), digitalWrite(), and delay(), which are provided by the internal libraries included in the IDE environment.

The open-source nature of the Arduino project has facilitated the publication of many free software libraries that other developers use to augment their projects.

arduino mega 2560 lcd display code factory

// Include Libraries#include "Arduino.h"#include "DS18B20.h"#include "LiquidCrystal_PCF8574.h"#include "SoilMoisture.h"#include "Pump.h"// Pin Definitions#define DS18B20_PIN_DQ 3#define SOILMOISTURE5V_PIN_SIG A10#define WATERPUMP_PIN_COIL1 2// Global variables and defines// There are several different versions of the LCD I2C adapter, each might have a different address.// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints.// To find your LCD address go to: http://playground.arduino.cc/Main/I2cScanner and run example.#define LCD_ADDRESS 0x3F//#define LCD_ADDRESS 0x27// Define LCD characteristics#define LCD_ROWS 4#define LCD_COLUMNS 20#define SCROLL_DELAY 150#define BACKLIGHT 255// object initializationDS18B20 ds18b20(DS18B20_PIN_DQ);LiquidCrystal_PCF8574 lcd20x4;SoilMoisture soilMoisture5v(SOILMOISTURE5V_PIN_SIG);Pump waterpump(WATERPUMP_PIN_COIL1);// define vars for testing menuconst int timeout = 10000; //define timeout of 10 secchar menuOption = 0;long time0;// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.void setup(){// Setup Serial which is useful for debugging// Use the Serial Monitor to view printed messagesSerial.begin(9600);while (!Serial) ; // wait for serial port to connect. Needed for native USBSerial.println("start");// initialize the lcdlcd20x4.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT);menuOption = menu();}// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.void loop(){if(menuOption == "1") {// DS18B20 1-Wire Temperature Sensor - Test Code// Read DS18B20 temp sensor value in degrees celsius. for degrees fahrenheit use ds18b20.ReadTempF()float ds18b20TempC = ds18b20.readTempC();Serial.print(F("Temp: ")); Serial.print(ds18b20TempC); Serial.println(F(" [C]"));}else if(menuOption == "2") {// LCD Display 20x4 I2C - Test Code// The LCD Screen will display the text of your choice.lcd20x4.clear(); // Clear LCD screen.lcd20x4.selectLine(2); // Set cursor at the begining of line 2lcd20x4.print(" Circuito.io "); // Print print String to LCD on first linelcd20x4.selectLine(3); // Set cursor at the begining of line 3lcd20x4.print(" Rocks! "); // Print print String to LCD on second linedelay(1000);}else if(menuOption == "3") {// Soil Moisture Sensor - Test Codeint soilMoisture5vVal = soilMoisture5v.read();Serial.print(F("Val: ")); Serial.println(soilMoisture5vVal);}else if(menuOption == "4") {// Submersible Pool Water Pump 240L/H - Test Code// The water pump will turn on and off for 2000ms (4 sec)waterpump.on(); // 1. turns ondelay(2000); // 2. waits 500 milliseconds (0.5 sec).waterpump.off();// 3. turns offdelay(2000); // 4. waits 500 milliseconds (0.5 sec).}if (millis() - time0 > timeout){menuOption = menu();}}// Menu function for selecting the components to be tested// Follow serial monitor for instrcutionschar menu(){Serial.println(F("\nWhich component would you like to test?"));Serial.println(F("(1) DS18B20 1-Wire Temperature Sensor"));Serial.println(F("(2) LCD Display 20x4 I2C"));Serial.println(F("(3) Soil Moisture Sensor"));Serial.println(F("(4) Submersible Pool Water Pump 240L/H"));Serial.println(F("(menu) send anything else or press on board reset button\n"));while (!Serial.available());// Read data from serial monitor if receivedwhile (Serial.available()){char c = Serial.read();if (isAlphaNumeric(c)){if(c == "1")Serial.println(F("Now Testing DS18B20 1-Wire Temperature Sensor"));else if(c == "2")Serial.println(F("Now Testing LCD Display 20x4 I2C"));else if(c == "3")Serial.println(F("Now Testing Soil Moisture Sensor"));else if(c == "4")Serial.println(F("Now Testing Submersible Pool Water Pump 240L/H"));else{Serial.println(F("illegal input!"));return 0;}time0 = millis();return c;}}}/******************************************************** Circuito.io is an automatic generator of schematics and code for off* the shelf hardware combinations.* Copyright (C) 2016 Roboplan Technologies Ltd.* This program is free software: you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation, either version 3 of the License, or* (at your option) any later version.* This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.* You should have received a copy of the GNU General Public License* along with this program. If not, see .* In addition, and without limitation, to the disclaimers of warranties* stated above and in the GNU General Public License version 3 (or any* later version), Roboplan Technologies Ltd. ("Roboplan") offers this* program subject to the following warranty disclaimers and by using* this program you acknowledge and agree to the following:* THIS PROGRAM IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS, AND* WITHOUT WARRANTIES OF ANY KIND EITHER EXPRESS OR IMPLIED. ROBOPLAN* HEREBY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT* NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS* FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND THOSE ARISING BY* STATUTE OR FROM A COURSE OF DEALING OR USAGE OF TRADE.* YOUR RELIANCE ON, OR USE OF THIS PROGRAM IS AT YOUR SOLE RISK.* ROBOPLAN DOES NOT GUARANTEE THAT THE PROGRAM WILL BE FREE OF, OR NOT* SUSCEPTIBLE TO, BUGS, SECURITY BREACHES, OR VIRUSES. ROBOPLAN DOES* NOT WARRANT THAT YOUR USE OF THE PROGRAM, INCLUDING PURSUANT TO* SCHEMATICS, INSTRUCTIONS OR RECOMMENDATIONS OF ROBOPLAN, WILL BE SAFE* FOR PERSONAL USE OR FOR PRODUCTION OR COMMERCIAL USE, WILL NOT* VIOLATE ANY THIRD PARTY RIGHTS, WILL PROVIDE THE INTENDED OR DESIRED* RESULTS, OR OPERATE AS YOU INTENDED OR AS MAY BE INDICATED BY ROBOPLAN.* YOU HEREBY WAIVE, AGREE NOT TO ASSERT AGAINST, AND RELEASE ROBOPLAN,* ITS LICENSORS AND AFFILIATES FROM, ANY CLAIMS IN CONNECTION WITH ANY OF* THE ABOVE.********************************************************/

arduino mega 2560 lcd display code factory

//Author Danny van den brande.#include "DHT.h"#include // Core graphics library#include // Hardware-specific library#include // BEGIN CLOCK#include //clock module DS1302#include //Need for clock module#define DS1302_SCLK_PIN 21// Arduino pin for the Serial Clock//PIN 21 (SCLK_PIN) = CLK on CLOCK and SCL on arduino#define DS1302_IO_PIN 20// Arduino pin for the Data I/O//PIN 20 (IO_PIN) = DAT on CLOCK and SDA on arduino#define DS1302_CE_PIN 19// Arduino pin for the Chip Enable//PIN 19 (CE_PIN) = RST on CLOCK and TX1 on arduino for this you can define any free Digital pin.#define bcd2bin(h,l) (((h)*10) + (l))#define bin2bcd_h(x) ((x)/10)#define bin2bcd_l(x) ((x)%10)#define DS1302_SECONDS 0x80#define DS1302_MINUTES 0x82#define DS1302_HOURS 0x84#define DS1302_DATE 0x86#define DS1302_MONTH 0x88#define DS1302_DAY 0x8A#define DS1302_YEAR 0x8C#define DS1302_ENABLE 0x8E#define DS1302_TRICKLE 0x90#define DS1302_CLOCK_BURST 0xBE#define DS1302_CLOCK_BURST_WRITE 0xBE#define DS1302_CLOCK_BURST_READ 0xBF#define DS1302_RAMSTART 0xC0#define DS1302_RAMEND 0xFC#define DS1302_RAM_BURST 0xFE#define DS1302_RAM_BURST_WRITE 0xFE#define DS1302_RAM_BURST_READ 0xFF#define DS1302_D0 0#define DS1302_D1 1#define DS1302_D2 2#define DS1302_D3 3#define DS1302_D4 4#define DS1302_D5 5#define DS1302_D6 6#define DS1302_D7 7#define DS1302_READBIT DS1302_D0// READBIT=1: read instruction// Bit for clock (0) or ram (1) area,// called R/C-bit (bit in address)#define DS1302_RC DS1302_D6// Seconds Register#define DS1302_CH DS1302_D7// 1 = Clock Halt, 0 = start// Hour Register#define DS1302_AM_PM DS1302_D5// 0 = AM, 1 = PM#define DS1302_12_24 DS1302_D7// 0 = 24 hour, 1 = 12 hour// Enable Register#define DS1302_WP DS1302_D7// 1 = Write Protect, 0 = enabled#define DS1302_ROUT0 DS1302_D0#define DS1302_ROUT1 DS1302_D1#define DS1302_DS0 DS1302_D2#define DS1302_DS1 DS1302_D2#define DS1302_TCS0 DS1302_D4#define DS1302_TCS1 DS1302_D5#define DS1302_TCS2 DS1302_D6#define DS1302_TCS3 DS1302_D7// Bit for reading (bit in address)#define DS1302_READBIT DS1302_D0// READBIT=1: read instruction#define DHTPIN 16// what pin we"re connected to#define DHTTYPE DHT11// DHT 11#define DS1302_READBIT DS1302_D0// READBIT=1: read instruction#define LCD_CS A3// Chip Select goes to Analog 3#define LCD_CD A2// Command/Data goes to Analog 2#define LCD_WR A1// LCD Write goes to Analog 1#define LCD_RD A0// LCD Read goes to Analog 0#define LCD_RESET A4// Can alternately just connect to Arduino"s reset pin// Assign human-readable names to some common 16-bit color values:#define BLACK 0x0000#define BLUE 0x001F#define RED 0xF800#define GREEN 0x07E0#define CYAN 0x07FF#define MAGENTA 0xF81F#define YELLOW 0xFFE0#define WHITE 0xFFFF// OBJECTS LCD ET DHTAdafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);DHT dht(DHTPIN, DHTTYPE);float hprev, tprev, hicprev;int moisture = 0;int moisture1 = 0;int moisture2 = 0;int moisture3 = 0;int moisture4 = 0;int moisture5 = 0;int sensorValue1;int sensorValue2;int sensorValue3;int sensorValue4;int sensorValue5;int sensorValue;int relay = 35;int relay1 = 36;int relay2 = 37;int relay3 = 38;int relay4 = 39;int relay5 = 40;// Structure for the first 8 registers.// These 8 bytes can be read at once with// the "clock burst" command.// Note that this structure contains an anonymous union.// It might cause a problem on other compilers.typedef struct ds1302_struct{uint8_t Seconds:4; // low decimal digit 0-9uint8_t Seconds10:3; // high decimal digit 0-5uint8_t CH:1; // CH = Clock Haltuint8_t Minutes:4;uint8_t Minutes10:3;uint8_t reserved1:1;union{struct{uint8_t Hour:4;uint8_t Hour10:2;uint8_t reserved2:1;uint8_t hour_12_24:1; // 0 for 24 hour format} h24;struct{uint8_t Hour:4;uint8_t Hour01:1;uint8_t AM_PM:1; // 0 for AM, 1 for PMuint8_t reserved2:1;uint8_t hour_12_24:1; // 1 for 12 hour format} h12;};uint8_t Date:4; // Day of month, 1 = first dayuint8_t Date10:2;uint8_t reserved3:2;uint8_t Month:4; // Month, 1 = Januaryuint8_t Month10:1;uint8_t reserved4:3;uint8_t Day:3; // Day of week, 1 = first day (any day)uint8_t reserved5:5;uint8_t Year:4; // Year, 0 = year 2000uint8_t Year10:4;uint8_t reserved6:7;uint8_t WP:1; // WP = Write Protect};void setup(){ds1302_struct rtc;Serial.begin(9600);// Serial.println(F("BLUECORE TECH"));pinMode (relay, OUTPUT);pinMode (relay1, OUTPUT);pinMode (relay2, OUTPUT);pinMode (relay3, OUTPUT);pinMode (relay4, OUTPUT);pinMode (relay5, OUTPUT);// digitalWrite (relay, HIGH);#ifdef USE_ADAFRUIT_SHIELD_PINOUT// Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));#else// Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));#endif// Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());//tft.reset();uint16_t identifier = tft.readID();if(identifier == 0x9325) {// Serial.println(F("Found ILI9325 LCD driver"));} else if(identifier == 0x9327) {// Serial.println(F("Found ILI9327 LCD driver"));} else if(identifier == 0x9328) {// Serial.println(F("Found ILI9328 LCD driver"));} else if(identifier == 0x7575) {// Serial.println(F("Found HX8347G LCD driver"));} else if(identifier == 0x9341) {// Serial.println(F("Found ILI9341 LCD driver"));} else if(identifier == 0x8357) {// Serial.println(F("Found HX8357D LCD driver"));} else if(identifier == 0x0154) {// Serial.println(F("Found S6D0154 LCD driver"));}tft.begin(identifier);iniText();dht.begin();//CLOCK MODULE START// Start by clearing the Write Protect bit// Otherwise the clock data cannot be written// The whole register is written,// but the WP-bit is the only bit in that register.DS1302_write (DS1302_ENABLE, 0);// Disable Trickle Charger.DS1302_write (DS1302_TRICKLE, 0x00);// Remove the next define,// after the right date and time are set.// #define SET_DATE_TIME_JUST_ONCE //= 300)digitalWrite (relay, HIGH); //TURN ON/OFF OFF RELAY 0 for watering pumpelsedigitalWrite (relay, LOW);//SENSOR 1 set your sensor here!}// OPTIONAL SENSORS PLACES FOR VALUES ON SCREEN BEGINif (sensorValue) {tft.setTextSize(2);tft.setCursor(98, 127);tft.setTextColor(GREEN);tft.fillRect(93,117,67,34,BLACK);tft.println (moisture1/1.01);if (sensorValue1 >= 300)digitalWrite (relay1, HIGH); //TURN ON/OFF OFF RELAY 1 for watering pumpelsedigitalWrite (relay1, LOW);//SENSOR 2 set your sensor here!}if (sensorValue) {tft.setTextSize(2);tft.setCursor(98, 164);tft.setTextColor(GREEN);tft.fillRect(93,154,67,34,BLACK);tft.println (moisture2/1.01);if (sensorValue2 >= 300)digitalWrite (relay2, HIGH); //TURN ON/OFF OFF RELAY 2 for watering pumpelsedigitalWrite (relay2, LOW);//SENSOR 3 set your sensor here!} // BEGIN SECTION 2 - right sectionif (sensorValue) {tft.setCursor(10,60);tft.setTextSize(2);//tft.println ("BODEM VOCHT%");tft.setCursor(256, 90);tft.setTextColor(GREEN);tft.fillRect(250,80,67,34,BLACK);tft.println (moisture3/1.01);if (sensorValue3 >= 300)digitalWrite (relay3, HIGH); //TURN ON/OFF OFF RELAY 3 for watering pumpelsedigitalWrite (relay3, LOW);//SENSOR 4 set your sensor here!}if (sensorValue) {tft.setCursor(10,60);tft.setTextSize(2);//tft.println ("BODEM VOCHT%");tft.setCursor(256, 127);tft.setTextColor(GREEN);tft.fillRect(250,117,67,34,BLACK);tft.println (moisture4/1.01);if (sensorValue4 >= 300)digitalWrite (relay4, HIGH); //TURN ON/OFF OFF RELAY 4 for watering pumpelsedigitalWrite (relay4, LOW);//SENSOR 5 set your sensor here!}if (sensorValue) {tft.setCursor(10,60);tft.setTextSize(2);//tft.println ("BODEM VOCHT%");tft.setCursor(256, 164);tft.setTextColor(GREEN);tft.fillRect(250,154,67,34,BLACK);tft.println (moisture5/1.01);if (sensorValue5 >= 300)digitalWrite (relay5, HIGH); //TURN ON/OFF OFF RELAY 5 for watering pumpelsedigitalWrite (relay5, LOW);//SENSOR 6 set your sensor here!}// OPTIONAL SENSORS PLACES ON SCREEN ENDif (hprev != h) {tft.setCursor(10, 25);tft.setTextSize(3);tft.setTextColor(CYAN);tft.fillRect(3,25,103,25,BLACK);tft.print(h);hprev = h;}if (tprev != t) {tft.setCursor(118, 25);tft.setTextSize(3);tft.setTextColor(RED);tft.fillRect(111,25,101,25,BLACK);tft.print(t);tprev = t;}if (hicprev != hic) {tft.setCursor(225, 25);tft.setTextSize(3);tft.setTextColor(YELLOW);tft.fillRect(217,25,100,25,BLACK);tft.print(hic);hicprev = hic;}ds1302_struct rtc;char buffer[80]; // the code uses 70 characters.// Read all clock data at once (burst mode).DS1302_clock_burst_read( (uint8_t *) &rtc);//+++++++++++ BEGIN TEXT CLOCK TEXT+++++++++++tft.setTextSize(2);tft.setTextColor(GREEN);tft.setCursor(13, 220);tft.fillRect(3,215,115,25,BLACK);sprintf( buffer, "%02d:%02d:%02d ", \bcd2bin( rtc.h24.Hour10, rtc.h24.Hour), \bcd2bin( rtc.Minutes10, rtc.Minutes), \bcd2bin( rtc.Seconds10, rtc.Seconds));tft.print(buffer);tft.setTextSize(1);tft.setTextColor(BLACK);tft.setCursor(127, 218);tft.fillRect(122,215,195,25,GREEN);sprintf(buffer, "%d,%d," \"Dag %d van week,%d", \bcd2bin( rtc.Date10, rtc.Date), \bcd2bin( rtc.Month10, rtc.Month), \rtc.Day, \2000 + bcd2bin( rtc.Year10, rtc.Year));tft.println( buffer);tft.setTextSize(1);tft.setTextColor(BLACK);tft.setCursor(127, 230);// tft.fillRect(122,215,194,25,GREEN);sprintf(buffer, "%d,%d," \"Day %d of week,%d", \bcd2bin( rtc.Month10, rtc.Month), \bcd2bin( rtc.Date10, rtc.Date), \rtc.Day, \2000 + bcd2bin( rtc.Year10, rtc.Year));tft.println( buffer);//+++++++++++ EINDE CLOCK +++++++++++if(timeStatus() != timeSet) {tft.setTextSize(1.5);tft.setTextColor(BLACK);tft.setCursor(28, 198);///ERROR TEXT need to be coded correctlytft.fillRect(3,191,157,19,RED);//tft.print(F("CLOCK ERROR: SYNC!"));// return micros() - start;delay(1000);}}unsigned long iniText() {// unsigned long start = micros();tft.fillScreen(BLACK);tft.setRotation(3);tft.setTextSize(1);tft.setTextColor(WHITE);tft.setCursor(15,5);tft.println("Humidity %");tft.setCursor(119,10);tft.println("Temperature oC");tft.setCursor(235,5);tft.println("Heat Index"); //Gevoels temperatuurtft.setCursor(122,2);tft.println ("BlueCore TECH"); //Put your NAME here COMPANY NAMEtft.setCursor(190,198);tft.println ("ArduinoSensors.NL"); //Put your NAME here COMPANY NAME website//TEXT SENSORStft.setCursor(10,90);tft.setTextColor(WHITE);tft.println ("SENSOR:1");tft.setCursor(10,127);tft.println ("SENSOR:2");tft.setCursor(10,164);tft.println ("SENSOR:3");tft.setCursor(170,90);tft.println ("SENSOR:4");tft.setCursor(170,127);tft.println ("SENSOR:5");tft.setCursor(170,164);tft.println ("SENSOR:6");// end TEXT SENSORS//Interface DESIGN BEGINtft.fillRect(0,0,345,1,WHITE); //Top line header whitetft.fillRect(0,19,345,2,WHITE); //Top line header 2 whitetft.fillRect(0,20,345,5,BLACK); //Top line header blacktft.fillRect(106,0,5,50,WHITE); //center vertical line header lefttft.fillRect(212,0,5,50,WHITE); //center vertical line header righttft.fillRect(0,50,345,5,WHITE); //bottom line header.tft.fillRect(160,78,5,135,WHITE);//center vertical linetft.fillRect(317,0,5,240,WHITE);//center vertical line righttft.fillRect(0,0,3,240,WHITE);//center vertical line lefttft.fillRect(0,210,345,5,WHITE);//BOTTOM LINE Footertft.fillRect(118,215,4,25,WHITE);//BOTTOM LINE Footer2 vertical smalltft.fillRect(0,210,345,5,WHITE);//BOTTOM LINE Footertft.fillRect(0,78,345,2,WHITE);//top line center screentft.fillRect(0,115,345,2,WHITE);//line 2 center screentft.fillRect(0,152,345,2,WHITE);//line 3 center screentft.fillRect(0,189,345,2,WHITE);//line 4 center screen//Interface DESIGN END// return micros() - start;}void DS1302_clock_burst_read( uint8_t *p)///BEGIN CLOCK MODULE PART2{int i;_DS1302_start();// Instead of the address,// the CLOCK_BURST_READ command is issued// the I/O-line is released for the data_DS1302_togglewrite( DS1302_CLOCK_BURST_READ, true);for( i=0; i<8; i++){*p++ = _DS1302_toggleread();}_DS1302_stop();}// --------------------------------------------------------// DS1302_clock_burst_write//// This function writes 8 bytes clock data in burst mode// to the DS1302.//// This function may be called as the first function,// also the pinMode is set.//void DS1302_clock_burst_write( uint8_t *p){int i;_DS1302_start();// Instead of the address,// the CLOCK_BURST_WRITE command is issued.// the I/O-line is not released_DS1302_togglewrite( DS1302_CLOCK_BURST_WRITE, false);for( i=0; i<8; i++){// the I/O-line is not released_DS1302_togglewrite( *p++, false);}_DS1302_stop();}// --------------------------------------------------------// DS1302_read//// This function reads a byte from the DS1302// (clock or ram).//// The address could be like "0x80" or "0x81",// the lowest bit is set anyway.//// This function may be called as the first function,// also the pinMode is set.//uint8_t DS1302_read(int address){uint8_t data;// set lowest bit (read bit) in addressbitSet( address, DS1302_READBIT);_DS1302_start();// the I/O-line is released for the data_DS1302_togglewrite( address, true);data = _DS1302_toggleread();_DS1302_stop();return (data);}// --------------------------------------------------------// DS1302_write//// This function writes a byte to the DS1302 (clock or ram).//// The address could be like "0x80" or "0x81",// the lowest bit is cleared anyway.//// This function may be called as the first function,// also the pinMode is set.//void DS1302_write( int address, uint8_t data){// clear lowest bit (read bit) in addressbitClear( address, DS1302_READBIT);_DS1302_start();// don"t release the I/O-line_DS1302_togglewrite( address, false);// don"t release the I/O-line_DS1302_togglewrite( data, false);_DS1302_stop();}// --------------------------------------------------------// _DS1302_start//// A helper function to setup the start condition.//// An "init" function is not used.// But now the pinMode is set every time.// That"s not a big deal, and it"s valid.// At startup, the pins of the Arduino are high impedance.// Since the DS1302 has pull-down resistors,// the signals are low (inactive) until the DS1302 is used.void _DS1302_start( void){digitalWrite( DS1302_CE_PIN, LOW); // default, not enabledpinMode( DS1302_CE_PIN, OUTPUT);digitalWrite( DS1302_SCLK_PIN, LOW); // default, clock lowpinMode( DS1302_SCLK_PIN, OUTPUT);pinMode( DS1302_IO_PIN, OUTPUT);digitalWrite( DS1302_CE_PIN, HIGH); // start the sessiondelayMicroseconds( 4); // tCC = 4us}// --------------------------------------------------------// _DS1302_stop//// A helper function to finish the communication.//void _DS1302_stop(void){// Set CE lowdigitalWrite( DS1302_CE_PIN, LOW);delayMicroseconds( 4); // tCWH = 4us}// --------------------------------------------------------// _DS1302_toggleread//// A helper function for reading a byte with bit toggle//// This function assumes that the SCLK is still high.//uint8_t _DS1302_toggleread( void){uint8_t i, data;data = 0;for( i = 0; i <= 7; i++){// Issue a clock pulse for the next databit.// If the "togglewrite" function was used before// this function, the SCLK is already high.digitalWrite( DS1302_SCLK_PIN, HIGH);delayMicroseconds( 1);// Clock down, data is ready after some time.digitalWrite( DS1302_SCLK_PIN, LOW);delayMicroseconds( 1); // tCL=1000ns, tCDD=800ns// read bit, and set it in place in "data" variablebitWrite( data, i, digitalRead( DS1302_IO_PIN));}return( data);}// --------------------------------------------------------// _DS1302_togglewrite//// A helper function for writing a byte with bit toggle//// The "release" parameter is for a read after this write.// It will release the I/O-line and will keep the SCLK high.//void _DS1302_togglewrite( uint8_t data, uint8_t release){int i;for( i = 0; i <= 7; i++){// set a bit of the data on the I/O-linedigitalWrite( DS1302_IO_PIN, bitRead(data, i));delayMicroseconds( 1); // tDC = 200ns// clock up, data is read by DS1302digitalWrite( DS1302_SCLK_PIN, HIGH);delayMicroseconds( 1); // tCH = 1000ns, tCDH = 800nsif( release && i == 7){// If this write is followed by a read,// the I/O-line should be released after// the last bit, before the clock line is made low.// This is according the datasheet.// I have seen other programs that don"t release// the I/O-line at this moment,// and that could cause a shortcut spike// on the I/O-line.pinMode( DS1302_IO_PIN, INPUT);// For Arduino 1.0.3, removing the pull-up is no longer needed.// Setting the pin as "INPUT" will already remove the pull-up.// digitalWrite (DS1302_IO, LOW); // remove any pull-up}else{digitalWrite( DS1302_SCLK_PIN, LOW);delayMicroseconds( 1); // tCL=1000ns, tCDD=800ns}}///////////////////////////// END CLOCK MODULE part 2}