Arduino Shield
Arduino Ethernet Shield W5100
close


This is a Ethernet shield based on the Wiznet W5100 ethernet chip,compatible with Arduino Ethernet Shield,added support to Arduino Mega. The different between with Arduino Ethernet Shield just Layout of Ethernet port location. It is based on the Wiznet W5100 ethernet chip providing a network (IP) stack capable of both TCP and UDP. The Arduino Ethernet Shield supports up to four simultaneous socket connections. Use theEthernet library to write sketches which connect to the internet using the shield.

The latest revision of the shield adds a micro-SD card slot, which can be used to store files for serving over the network. It is compatible with the Arduino Duemilanove and Mega (using the Ethernet library coming in Arduino 0022). An SD card library is not yet included in the standard Arduino distribution, but the sdfatlib by Bill Greiman works well. See this tutorial from Adafruit Industries for instructions (thanks Limor!). 

Documents:


MAC Adress: " 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED "

Sample Test code: 

Test Code:
/*
* Web Server
*
* A simple web server that shows the value of the
analog input pins.
*/
#include
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 15 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we have gotten to the end of the line (received a
newline
// character) and the line is blank, the http request
has ended,
// so we can send a reply
if (c == "n" && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
client.print("welcome to B2CQSHOP");
client.println("
");
client.print
("//*************************************");
client.println("
");
client.print("");
client.println("
");
client.print
("//*************************************");
client.println("
");
for (int i = 0; i < 6; i++) {
client.print("analog input ");
client.print(i);
client.print(" is ");
client.print(analogRead(i));
client.println("
");
}
break;
}
if (c == "n") {
// we are starting a new line
current_line_is_blank = true;
} else if (c != "r") {
// we have gotten a character on the current line
current_line_is_blank = false;
}
}
}
client.stop();
}
}

 

Tutorial: 

 

 

 

Get familiar

Before you do this tutorial you willl want to get familiar with what you are working on. This is not a beginner tutorial, its best used by those who already have quite a bit Arduino or microcontroller experience and are "fluent" in C/C++/Java!

Also, read up on how to use the Ethernet shield and Ethernet library . Then review the notes on SD card usage and installing the library you will be using

You should have already gotten the Ethernet shield working with your network setup, too.

 You can download the latest code from GitHub (click Download Source in the top right)

Initializing Micro-SD card on an Ethernet shield

 

The latest Arduino Ethernet shield comes with a handy MicroSD card slot so that you can store and retrieve data through the shield. Very handy! Lets show how to talk to the card.

Be sure to have the very latest version of SdFatLib , as you"ll need some of the newer capabilities!

First thing to note is that the SS (Slave Select) pin for the card is digital 4 (although as of the writing of this mini-tutorial, the schematic hasn"t been updated)

Open up the SdFatInfo example sketch and change the line in loop() from

 uint8_t r = card.init(SPI_HALF_SPEED); 

To:

 pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
uint8_t r = card.init(SPI_HALF_SPEED, 4); // Use digital 4 as the SD SS line

Be sure to add those two extra lines right before-hand! They Enable the SPI interface. If you are on a Mega, use pin 53 instead of 10

Now upload and test the card, you should see something like this:

 

Indicating you talked to the card all right

List files

Put some text files on your SD card, using a computer, so that you have data to read. Make sure they are in the root directory, and not in a folder

Then run the SdFatLs example sketch from the SdFat library, you should see it list all the files you have on the card, again, you will have to make the changes from above to update the card.init() part to the new SS pin

 

For example, the card we will be using has two files on it from some previous datalogging.

Merge WebServer + SdFatLs

We will begin by combining WebServer (the example sketch that comes with the Ethernet lib) and SdFatLs to make a web server that lists the files on the SD card.You can download the file here (you will need to copy&paste it, do so carefully!)then follow along!

Part one is the Ethernet and SD card objects and a simple error function (void error_P(const char* str)) that prints out errors and halts the program if there are serious problems.

You should, of cousre, set your mac and ip as necessary, use the ip and mac that worked from your previous Ethernet shield explorations!

The cardvolume, and root are objects that help us traverse the complex structure of an SD card

The error function is not too exciting, it just prints out the error and sits in a while(1); loop forever

/*
* This sketch will list all files in the root directory and
* then do a recursive list of all directories on the SD card.
*
*/
 
#include
#include
#include
 
/%%**%%%%**%%%%**%%%%**%%%%**%%%%**%% ETHERNET STUFF %%**%%%%**%%%%**%%%%**%%%%**%%%%**%%/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
Server server(80);
 
/%%**%%%%**%%%%**%%%%**%%%%**%%%%**%% SDCARD STUFF %%**%%%%**%%%%**%%%%**%%%%**%%%%**%%/
Sd2Card card;
SdVolume volume;
SdFile root;
 
// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
 
void error_P(const char* str) {
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode()) {
PgmPrint("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(",");
Serial.println(card.errorData(), HEX);
}
while(1);
}

Part 2 is the setup() function. It sets up the Serial object so we can debug the connection in real time. It then prints out the RAM usage. You will need aAtmega328Arduino for this experiment, and you should see at leat 1000 bytes of RAM free. Once this gets to under 250 bytes, you may be running too low!

Then we do the trick where we make the hardware SS pin #10 to an OUTPUT and HIGH to disable the wiznet chip while we check the card contents. If you are on a Mega, change this to 53. Then we initialize the card which should go fine since you already tested this before

Then we verify the card structure, print out all the files, and print "Done!". Finally we stuck the Ethernet initialization code at the end here! Now we have both the Ethernet and SD card working

void setup() {
Serial.begin(9600);
 
PgmPrint("Free RAM: ");
Serial.println(FreeRam());
 
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
 
if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");
 
// initialize a FAT volume
if (!volume.init(&card)) error("vol.init failed!");
 
PgmPrint("Volume is FAT");
Serial.println(volume.fatType(),DEC);
Serial.println();
 
if (!root.openRoot(&volume)) error("openRoot failed");
 
// list file in root with date and size
PgmPrintln("Files found in root:");
root.ls(LS_DATE | LS_SIZE);
Serial.println();
 
// Recursive list of all directories
PgmPrintln("Files found in all dirs:");
root.ls(LS_R);
 
Serial.println();
PgmPrintln("Done");
 
// Debugging complete, we start the server!
Ethernet.begin(mac, ip);
server.begin();
}

We will skip ahead to the loop() where we wait for clients (checking via server.available()) and then read the client request before responding. This is basically copy-and-pasted from the Webserver example sketch that comes with the Ethernet library (well, the first and last parts of the loop are at least).

There is a little trick where to simplify the code, the writer of this sketch doesn"t actually check to see what file the web browser wants, it always spits out the same thing. In this case, we are going to have it spit out the files by using a helper function called ListFiles(client, 0) which we skipped over but will show next. The 0 in the second argument to the function just tells the function whether to print out the file sizes

void loop()
{
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we have gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == " " && current_line_is_blank   Videos Will be available Soon........

Arduino USB-SD MP3 Shield
close

This shield is more powerful and flexible. It supports both wave and mp3 format. Both SD card and U-disk are supported directly. Also there is an on-board 64Mbit flash which could store music files.There is a standard 3.5mm headset jacket on the shield. You could connect with a standard earphone. We also integrate an audio amplifier on the shield. You could

There is a standard 3.5mm headset jacket on the shield. You could connect with a standard earphone. We also integrate an audio amplifier on the shield. You could connect loudspeaker directly.

Features

  • Plug in and play for Arduino
  • Control by Serial UART interface or keys onboard.
  • Directly drive 32ohm headset.
  • On-board Audio Amplifier to drive 3W/4Ω external loudspeaker.
  • 32 levels adjustable volume.
  • Support FAT16/FAT32 file system.
  • Support both SD/SDHC card and U-Disk.
  • On board 64MBit SPI-FLASH.
  • Support copying audio files from SD card or U-Disk to SPI-FLASH.
  • Supporting Sleep Mode.
  • Support 16K~320Kbps MP3 files and 8K~44.1KHz sampling rate WAV files (SPI-FLASH only supports MP3 format)

Connection

Plug in and play.

Dimension

Download

Product list

  • Arduino MP3 Shield x1

Note: SD card or U-disk is not contained in the product list.

 

PROTOSHIELD V3 + MINI PROTOBOARD FOR ARDUINO MEGA
close

Specifications:

Dimensions (cm) 10.2 x 5.5 x 2
Weight (kg) 0.045

Free Shipping To buy Arduino MEGA Prototype Shield ProtoShield V3 Expansion Board with Mini Bread Board


Features:

MEGA ProtoShield V3 Prototype Shield Gold PCB processing technology, motherboards, small gold square pad spacing, welding components easier. SOP28 SMD component package to be more handy electronics enthusiasts will not be directly insert bound components. The board can not only receive MEGA seamless plug controller, directly soldered to the above components to complete a variety of prototype circuit, you can paste Mini bread 
board, through the 7-color jumper to complete a variety of circuit experiment, board integrated power indicator and status lights, and reset buttons, easy to learn MEGA 
preferred prototype controller expansion board. Full Compatible with Mega ATmega.

 

Packing include:

1 x Arduino MEGA Prototype Shield ProtoShield V3 Expansion Board with Mini Bread Board

PROTOSHIELD + MINI PROTOBOARD FOR ARDUINO UNO
close

 

  • 100% brand new and high quality
  • Arduino protoshield prototype with 170 mini breadboard.
  • 1 reset button, 1 general use button, and 2 LED circuits can be used directly.
  • The mini breadboard has 170 tie points.
  • Features:

    • 100% brand new and high quality
    • Arduino protoshield prototype with 170 mini breadboard.
    • 1 reset button, 1 general use button, and 2 LED circuits can be used directly.
    • The mini breadboard has 170 tie points.

    Specification:

    • Color: blue + black + white (as the picture show)
    • Prototype size: About 2.72*2.09*0.71" (69*53*18mm)
    • Mini breadboard size: About 1.85*1.38*0.35" (47*35*9mm)

    Package Included:

    • Arduino Proto Shield with Breadboard

    Wiring Picture:

    • dsds

Arduino Stepper Motor/Servo/DC Motor Shield
close

Arduino is a great starting point for electronics, and with a motor shield it can also be a nice tidy platform for robotics and mechatronics. Here is a design for a full-featured motor shield that will be able to power many simple to medium-complexity projects.

  • 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution dedicated timer - no jitter!
  • Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5% resolution)
  • Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil, interleaved or micro-stepping.
  • 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal shutdown protection, 4.5V to 25V
  • Pull down resistors keep motors disabled during power-up
  • Big terminal block connectors to easily hook up wires (10-22AWG) and power
  • Arduino reset button brought up top
  • 2-pin terminal block to connect external power, for seperate logic/motor supplies
  • Tested compatible with UNO, Mega, Diecimila, & Duemilanove
    2237992158_d1be17779d_b.jpg

Schematics & Layout

You can grab the latest Schematic, Layout files (EagleCAD format from github. Click the ZIP download button at top middle to download the entire zip.

Firmware

  • Arduino Stepper/Servo software library with microstepping support.
    To install, click on Downloads in the middle of the page, select Download as zip and uncompress the folder. 
     
    Rename the folder to AFmotor (check that the renamed folder contains the .cpp and .h files) and install into the Arduinosketches/libraries folder. For information how to use and install libraries, see our tutorial! This version now works with with the Mega. Public domain!
  • AccelStepper library with AFMotor support. This library allows for advanced stepper control including accelleration and decelleration, and concurrent stepper control! You still need AFmotor above!
    To install, click on Download in the middle of the page, select Download as zip and uncompress the folder. 
    Rename the folder to AccelStepper (check that the renamed folder contains the .cpp and .h files) and install into the Arduinosketches/libraries folder. For information how to use and install libraries, see our tutorial!

arduino IO expansion shield (V5) support xbee, sd card, RS485, PWM
close

Extended 14 digital IO ports (12 Servo Interface) and power;

6 analog IO ports and power;

Description:

 

Extended 14 digital IO ports (12 Servo Interface) and power;

6 analog IO ports and power;

An the digital port external power supply terminal;

The digital port external power supply and power automatic switch-board;

An external power supply input terminal and an input pin;

RS485 interface;

Reset button;

XBee / Bluetooh Bee Bluetooth wireless data transmission interface;

APC220/Bluetooh V3 Bluetooth wireless data transmission interface;

The interface IIC/I2C/TWI;

3.3V output port;

SD card module interface

Overview

The IO expansion board is evolving, this latest V5 IO expansion shield is now supporting Xbee.
It combines popular Xbee shield with IO expansion shield(V4). It even supports SD card which 
provides the ultimate functional expansion for Arduino so far. As its predecessor, it supports
RS485, APC220, Bluetooth communication, servo control.

Specification

  • Support RS485
  • Support Xbee (Xbee pro)
  • Support Bluetooth
  • Support APC220
  • Support SD card read/write

RS485

It uses an SP485CN chip to handle comms.

The screw terminals (assuming that the three jumpers are set to '485') marked 'A' and 'B' go
directly to the IC 'A' and 'B' pins (6 & 7 respectively).

The screw terminal marked VCC goes to the IC VCC pin (8), and also to the board's
+5V line (i.e. the Arduino's +5V rail).

The screw terminal marked GND goes to the IC GND pin (5), and also to the board's
GND line (i.e. the Arduino's 0V rail).

The chip's DI (Data Input?) pin (4) is connected to the Arduino's Digital Pin 1 (TX).

The chip's RO (Data Output?) pin (1) is connected to the Arduino's Digital Pin 0 (RX), 
with a resistor pull-up to the +5V rail.

The chip's DE (output enable) pin (3) is connected (via a resistor) to the Arduino's Digital 
Pin 2 - this is active high.

This DE pin is also connected to the chip's RE bar (receiver enable) pin (2) and therefore 
controlled by the Arduino's Digital pin 2 too - this is active low.

Arduino Digital Pin 2 = Rx/Tx 'Enable'; High to Transmit, Low to Receive

So, to transmit data from Arduino Digital Pin 1 you need to take Digital pin 2 high, and to receive
data to Arduino Digital Pin 0 you need to take Arduino Digital pin 2 low.

Pin Out

IO Expansion Shield For Arduino(V5) (SKU: DFR0088)

Shield functions & pins usage

Shield pin usage(SKU: DFR0088)

Sample Code

RS485 Transmit Data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int EN = 2; //RS485 has a enable/disable pin to transmit or receive data. Arduino Digital Pin 2 = Rx/Tx 'Enable'; High to Transmit, Low to Receive
 
void setup()
{
  pinMode(EN, OUTPUT);
  Serial.begin(19200);
}
 
void loop()
{
// send data
  digitalWrite(EN, HIGH);//Enable data transmit
  Serial.print('A');
  delay(1000);
  Videos Will be available Soon........

EMG ECG Arduino Shield with Electrode Prob
close

This is an ECG/EMG shield which allows Arduino like boards to capture Electrocardiography Electromiography signals. The shield opens new possibilities to experiment with bio feedback. You can monitor your heartbeat and log

 Manual: https://www.olimex.com/Products/Duino/Shields/SHIELD-EKG-EMG/resources/SHIELD-EKG-EMG.pdf

- See more at: http://www.ewallpk.com/home/1223-emg-ekg-eeg-shield.html?search_query=A1114&results=1#sthash.9baLG4lu.dpuf

This is an ECG/EMG shield which allows Arduino like boards to capture Electrocardiography Electromiography signals. The shield opens new possibilities to experiment with bio feedback. You can monitor your heartbeat and log your pulse, recognize gestures by monitoring and analize the muscule activity as it is done in this project.

 

ECG EMG EKG EEG Shield Kits:

1. ECG EMG EKG EEG Shield 1 pcs

2. Electrode sensor 3 pcs

3. Tree lead wire ECG cable

  • Stackable headers up to 6 channels may be stacked and wired to A0-A6 analogue inputs
  • Calibration signal generation by D4/D9 digital output
  • Precise Trimmer potentiometer for calibration (all boards are shipped completely assembled, tested and calibrated so that you don't have to do this unless you want to see how things works)
  • Input connector for normal or Active electrodes
  • Works with both 3.3V and 5V Arduino boards

software:

Electric guru monitoring software, created by Rob Sacks

Arduino example for EKG capture and interface to Electric Guru for /Arduino boards

 

- See more at: http://www.ewallpk.com/home/1223-emg-ekg-eeg-shield.html?search_query=A1114&results=1#sthash.9baLG4lu.dpuf

30A Dual H-bridge Monster Moto Shield VNH2SP30
close

Features:

  • Voltage max: 16V
  • Maximum current rating: 30 A
  • Practical Continuous Current: 14 A
  • Current sensing available to Arduino analog pin
  • MOSFET on-resistance: 19 mΩ (per leg)
  • Maximum PWM frequency: 20 kHz
  • Thermal Shutdown
  • Undervoltage and Overvoltage shutdown

Documents:

Note: When using this board in extreme high-demand applications it may be necessary to improve thermal performance with a heat-sink or fan and to solder the wires directly to the board instead of using a screw terminal (in addition to the myriad other complications present in a high-current system) However, when using the board at currents up to 6A the chips will barely become noticeably warm.

 

TF SD Card Arduino shield
close

This SD card shield is a standard SD card / TF card break out board for Arduino. The SD card shield adds storage to your Arduino project. It supports SD, SDHC, or Micro SD/TF cards. It just uses the SPI ports of Arduino, and you can plug more other shield on it. 
Arduino compatible SD card, Micro SD card and SDHC card supportable 
Prototype expand Arduino Library support 

This SD card shield is a standard SD card / TF card break out board for Arduino. The SD card shield adds storage to your Arduino project. It supports SD, SDHC, or Micro SD/TF cards. It just uses the SPI ports of Arduino, and you can plug more other shield on it. 
Features: 
Arduino compatible SD card, Micro SD card and SDHC card supportable 
Prototype expand Arduino Library support 
Size: 53mm x 47mm 
Weight: 35g 
Pin of Arduino With SD Card 5V 
VCC --------------3v3 
GND-------------- GND 
D13---------------SD_CLK 
D12-------------- SD_OUT 
D11-------------- SD_IN 
D10-------------- SD_CS

Yun Shield for Arduino ( Linux, WiFi, Ethernet, USB, All-in-one Shield)
close

Yun Shield is one of the most powerful shields for Arduino Board. Yun Shield is designed to solve the Internet connectivity and storage issue for Arduino Board. It provides a linux system, WiFi, Ethernet and USB (can used for camara, storage, 3G etc) to Arduino

 

INTRODUCTION

Yun Shield is one of the most powerful shields for Arduino Board. Yun Shield is designed to solve the Internet connectivity and storage issue for Arduino Board. It provides a linux system, WiFi, Ethernet and USB (can used for camara, storage, 3G etc) to Arduino.

Yun Shield runs Open Source OpenWrt system (Same system as runs in Arduino Yun) and it is fully compatible with Arduino IDE v1.5.4 or later. Yun Shield is the ideally choice for Arduino Projects which require various internet connections and more storage.

Basically, Yun Shield + Leonardo equally to the official Arduino Yun, but Yun Shield is more flexible because it can works with other Arduino board such as Uno, Duemilanove, Mega etc. And Yun Shield use external wifi antenna which provides stability and possibility for various environments.

FEATURES

  • Open source Linux (OpenWrt) inside
  • Low power consumption
  • Compatible with Arduino IDE 1.5.4 or later, user can program, debug or upload sketch to Arduino board via Arduino IDE.
  • Managed by Web GUI, SSH via LAN or WiFi
  • Software upgradable via network
  • Built-in web server
  • Support internet connection via LAN port, WiFi or 3G dongle.
  • Support USB flash to provide storage for Arduino projects.
  • Failsafe design provides robustly system.
  • Compatible with Arduino Leonardo, Uno , Duemilanove, Diecimila, Mega.

SPECIFICATIONS

  • Processor: 400MHz, 24K MIPS
  • Flash: 16MBytes
  • RAM: 64MBytes
  • Power Input: 4.75v ~ 23v via Arduino VIN pin
  • 1 x 10M/100M RJ45 connector
  • 150M WiFi 802.11 b/g/n
  • External Antenna via I-Pex connector
  • 1 x USB 2.0 host connector, used for USB storage or 3G connection
  • 1 x Reset button
  • Compatible with 3.3v or 5v I/O Arduino.

Links to Documents:

Quick Start Guide

User manual

Hardware Source

 
 

Gamepads JoyStick Keypad Shield for Arduino nRF24L01 Nk 5110 LCD I2C 3.3V Controller Board Module
close

Specifications:
 
nRF24L01 RF interface
for Nokia 5110 LCD interface
bluetooth interface
I2C interface
for one PS2 toystick
working voltage: 3.3V or 5V eg. STM32
 
Package includes:
1 x Gamepads Joystick Shield

ARDUINO LCD 1602 (16x2)KEYPAD SHIELD (BLUE LCD)
close

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 pushbuttons. The LCD shield supports contrast adjustment and backlit on/off functions. It also expands analog pins for easy analog sensor reading and display.

Introduction

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 pushbuttons. The LCD shield supports contrast adjustment and backlit on/off functions. It also expands analog pins for easy analog sensor reading and display.

 

Specification

  • Operating Voltage:5V
  • 6 Push buttons
  • Expanded Analog Pinout with  standard DFRobot configuration

 

Documents

Tutorial:

Introduction

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.

Note: Version 1.1 main updates are the button values, which have being updated on the example code. For older version
check the comments and edit, or use the Enhanced V1.0 library 


Diagram

LCD&Keypad Shield Diagram
Pin Out Diagram

 

Pin Allocation

Pin Function
Analog 0 Button (select, up, right, down and left)
Digital 4 DB4
Digital 5 DB5
Digital 6 DB6
Digital 7 DB7
Digital 8 RS (Data or Signal Display Selection)
Digital 9 Enable
Digital 10 Backlit Control

 

Sample Code

Example use of LiquidCrystal library

 
//Sample using LiquidCrystal library
#include
 
/*******************************************************
 
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
 
********************************************************/
 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 // For V1.1 us this threshold
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 250)  return btnUP;
 if (adc_key_in < 450)  return btnDOWN;
 if (adc_key_in < 650)  return btnLEFT;
 if (adc_key_in < 850)  return btnSELECT; 
 
 // For V1.0 comment the other threshold and use the one below:
/*
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;  
*/
 
 
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("Push the buttons"); // print a simple message
}
  
void loop()
{
 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up
 
 
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP: