'lcd' does not name a type and other problems

I'm trying to make a program to work for a stepper driven rotary table (found on CNC zone.com) As hardware comes an Arduino Nano, a matrix 4 x4 keyboard, an LCD 4 x 20 display + backpack module and a stepper driver. Compiling and uploading the program as published gives many problems, so I started trying to make the components to work one by one. Keypad: no problem; LCD display as a single item also works, but when I combine these two,I get error messages from the LCD part in the program.

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}

byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to row pinouts
byte colPins[COLS] = {7, 6, 5, 4}; //connect to column pinouts
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
void loop()
  char key = keypad.getKey();
  if (key != NO_KEY) {
 * I2C/IIC LCD Serial Adapter Module Example
 * Tutorial by http://mklec.com
 ** Instructions at http://blog.mklec.com/how-to-use-iici2c-serial-interface-module-for-1602-lcd-display
 ** This uses the Liquid Crystal library from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads GNU General Public License, version 3 (GPL-3.0)
* Pin Connections:
*      SCL = A5
*      SDA = A4
*      VCC = 5V
*      GND = GND
LiquidCrystal_I2C  lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // 0x27 is the I2C bus address for an unmodified module

lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH
lcd.begin(20, 4);
void loop()
  lcd.setCursor(0, 0);
  lcd.setCursor(0, 1);
  lcd.print("I2C Module Demo");
  lcd.setCursor(0, 2);
  lcd.print("Geduld beloond");
  lcd.setCursor(0, 3);

Error messages: Arduino: 1.6.5 (Windows 7), Board:"Arduino Nano, ATmega328"

Bibliotheek Keypad in map: C:\Users\Thuis\Documents\Arduino\libraries\Keypad wordt gebruikt

Bibliotheek Wire in map: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire wordt gebruikt

Bibliotheek LiquidCrystal in map: C:\Users\Thuis\Documents\Arduino\libraries\LiquidCrystal (legacy) wordt gebruikt

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs -IC:\Users\Thuis\Documents\Arduino\libraries\Keypad\src -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Users\Thuis\Documents\Arduino\libraries\LiquidCrystal C:\Users\Thuis\AppData\Local\Temp\build5298228962049564241.tmp\sketch_aug16a_testLCDenKP.cpp -o C:\Users\Thuis\AppData\Local\Temp\build5298228962049564241.tmp\sketch_aug16a_testLCDenKP.cpp.o

sketch_aug16a_testLCDenKP.ino:44:1: error: 'lcd' does not name a type sketch_aug16a_testLCDenKP.ino:45:1: error: 'lcd' does not name a type sketch_aug16a_testLCDenKP.ino:46:1: error: 'lcd' does not name a type sketch_aug16a_testLCDenKP.ino:47:1: error: 'lcd' does not name a type sketch_aug16a_testLCDenKP.ino:48:1: error: expected declaration before '}' token 'lcd' does not name a type

It puzzles me why in the "stand alone" situation this error does not show, where in the combined program it gives the error. The Keypad works in both programs (on the serial monitor). I did no test with the stepper driver so far. Writing LCD in capitals gives another error message, but does not solve the problem

I do hope someone can lift a tip of the vale for me. Foden

you forgot to include the liquid Chrystal library....


actually, you can only have one loop... you have two. that's not going to work.

move all of your variables outside of the loops and setup to the very top, merge your two setups into one setup, and put everything in your loops into one loop.

You are using non-standard libraries, so it would be helpful to give the URL where the libraries can be found. I did download the Keypad library, but cannot find the Key.h or Wiring.h header files and don't know where you found them.

Thanks Qdeathstar for your reply. I understand now that writing a sketch is more than copy - paste two programs into one. Still a lot to be learned.

To econjack: The libraries used are: http://playground.arduino.cc/Code/Keypad https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads http://arduino-info.wikispaces.com/LCD-Blue-I2C#v1

The codes were published by the component supplier in the Netherlands on his website. What I did change were some pin asignments to the Nano according to the overall sketch for the Arduino Sherline Rotary Table Controler, which is to be found at: http://www.cnczone.com/forums/arduino/215402-cnc.html