MULTIFUNCIÓN SHIELD

MÓDULO MULTIFUNCIÓN EL0496
(ojo: "trabaja en lógica negativa")

ÍNDICE:
0.- CARACTERÍSTICAS
1.- PRÁCTICAS




0.- CARACTERÍSTICAS DEL MÓDULO
http://www.sniff.org.uk/2015/04/arduino-multifunction-shield.html

EL0496 SHIELD MULTIFUNCIÓN PLACA EXPANSIÓN

  • Montaje a anodo (positivo comun): los elementos se activan con señal LOW
  • Tres PULSADORES  PULLUP: PIN_A1,A2,A3 (activación con LOW)
  • Un POTENCIÓMETRO 10K: PIN_A0
  • Un Piezo BUZZER: PIN_D3
  • Cuatro LEDES: PIN_D10(pwm), D11(pwm), D12, D13
  • Un DISPLAY 4x7segmentos via dos chips serie 74HC595: PIN_D4, D7, D8
  • Un socket TEMPERATURA (TM35/D180B20): PIN_A4
  • Un socket IR: PIN_2
  • Cuatro pines para conexión de módulos serie: A5, D5, D6, D9
  • Dos pines macho  salidas: GND y 5v.





1.-PRÁCTICAS CON EL MÓDULO MULTIFUNCIÓN.


//LED INTERMITENTE (sin librería).
int led = 13;
void setup(){
pinMode(led, OUTPUT);
}
void loop(){
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}



//CUATRO LEDES (sin librería)
int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(1000);
}


//DOS BOTONES Y CUATRO LEDES (sin librería)
const byte LED[] = {13,12,11,10};
#define BUTTON1 A1
#define BUTTON2 A2
void setup(){
pinMode(LED[0], OUTPUT);
pinMode(LED[1], OUTPUT);
pinMode(LED[2], OUTPUT);
pinMode(LED[3], OUTPUT);
}
void loop(){
if(!digitalRead(BUTTON1)){
  digitalWrite(LED[0], HIGH);
  digitalWrite(LED[1], HIGH);
  digitalWrite(LED[2], HIGH);
  digitalWrite(LED[3], HIGH);
  }
 if(!digitalRead(BUTTON2)){
  digitalWrite(LED[0], LOW);
  digitalWrite(LED[1], LOW);
  digitalWrite(LED[2], LOW);
  digitalWrite(LED[3], LOW);
  }
}


//POTENCIOMETRO (sin librería)
#define Pot1 0
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print("Potentiometer reading: ");
Serial.println(analogRead(Pot1));
delay(500);
}

//POTENCIOMETRO Y LEDES (sin librerías)
const byte LED[] = {13,12,11,10};
#define Pot1 0
void setup(){
Serial.begin(9600);
pinMode(LED[0], OUTPUT);
pinMode(LED[1], OUTPUT);
pinMode(LED[2], OUTPUT);
pinMode(LED[3], OUTPUT);
}
void loop(){
int PotValue;
PotValue = analogRead(Pot1);
if(PotValue < 400){
  digitalWrite(LED[0], LOW);
  digitalWrite(LED[1], LOW);
  digitalWrite(LED[2], LOW);
  digitalWrite(LED[3], LOW);
  Serial.print("Potentiometer: ");
  Serial.println(PotValue);
  }
else {
  digitalWrite(LED[0], HIGH);
  digitalWrite(LED[2], HIGH);
  digitalWrite(LED[3], HIGH);
  Serial.print("Potentiometer: ");
  Serial.println(PotValue);
  }
delay(500);
}

//POTENCIÓMETRO (con la librería del módulo)
/*This sketch demonstrates how the value of the preset pot is read and displayed on the multi-function shield.*/
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
void setup() {
 Timer1.initialize();
 MFS.initialize(&Timer1);    // inicializa la librería del módulo multifunción.
}
void loop() {
  MFS.write(analogRead(POT_PIN));
  delay(100);
}


//LEDES (con librerías).
/*Although it isn’t strictly necessary to use the multi-function shield library to control the LED lights of the shield, support is provided in cases where your application needs the LEDs to perform basic blink operations. Blinking is managed in the background using interrupts.*/
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
void setup() {
  Timer1.initialize();
  MFS.initialize(&Timer1);    // initialize multi-function shield library
  MFS.writeLeds(LED_ALL, ON);
  delay(2000);
  MFS.blinkLeds(LED_1 | LED_2, ON);
  delay(2000);
  MFS.blinkLeds(LED_1 | LED_2, OFF);
  MFS.blinkLeds(LED_3 | LED_4, ON);
  delay(2000);
  MFS.blinkLeds(LED_ALL, ON);
  delay(2000);
  MFS.blinkLeds(LED_ALL, OFF);
  MFS.writeLeds(LED_ALL, OFF);
}
void loop() {
 }




//DISPLAY 7SEGMENTOS  (sin librerías)

#define L 4 //puerto de comunicación
#define C 7 //puerto para reloj
#define D 8 //puerto de datos
const byte MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
const byte POSICION[] = {0xF1,0xF2,0xF4,0xF8};
void setup (){
pinMode(L,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
}
void loop(){
Escribe(0 , 0);
Escribe(1 , 1);
Escribe(2 , 2);
Escribe(3 , 3);
}

void Escribe(byte Segmento, byte Valor){
digitalWrite(L,LOW); 
shiftOut(D, C, MSBFIRST, MAP[Valor]);
shiftOut(D, C, MSBFIRST, POSICION[Segmento] );
digitalWrite(L,HIGH);
}



//POTENCIOMETRO Y DISPLAY (sin libreías)
//Botones
#define BUTTON1 A1
#define BUTTON2 A2
#define BUTTON3 A3
//Buzzer
#define BUZZER_DIO 3
//Estados para los LED y el Buzzer
#define OFF HIGH
#define ON LOW
//LED
const byte LED[] = {13,12,11,10};
//Control del display
#define LATCH_DIO 4
#define CLK_DIO 7
#define DATA_DIO 8
//Numeros display
const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
//Potenciometro
#define PotPin 0
void setup() {
  pinMode(BUZZER_DIO, OUTPUT);
  digitalWrite(BUZZER_DIO, OFF);
  pinMode(LED[0], OUTPUT);
  pinMode(LED[1], OUTPUT);
  pinMode(LED[2], OUTPUT);
  pinMode(LED[3], OUTPUT);
  digitalWrite(LED[0], OFF);
  digitalWrite(LED[1], OFF);
  digitalWrite(LED[2], OFF);
  digitalWrite(LED[3], OFF);
  pinMode(LATCH_DIO,OUTPUT);
  pinMode(CLK_DIO,OUTPUT);
  pinMode(DATA_DIO,OUTPUT);
}
void loop() {
  if(!digitalRead(BUTTON1)) {
    digitalWrite(LED[0], ON);
    digitalWrite(LED[1], OFF);
    digitalWrite(LED[2], OFF);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF);
  }
   if(!digitalRead(BUTTON2)) {
    digitalWrite(LED[0], OFF);
    digitalWrite(LED[1], ON);
    digitalWrite(LED[2], OFF);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF);
  }
  if(!digitalRead(BUTTON3)){
    digitalWrite(LED[0], OFF);
    digitalWrite(LED[1], OFF);
    digitalWrite(LED[2], ON);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF);
  }
  WriteNumber(analogRead(PotPin));
}

void WriteNumber(int Number){
  WriteNumberToSegment(0 , Number/1000);
  WriteNumberToSegment(1 , (Number/100)%10);
  WriteNumberToSegment(2 , (Number/10)%10);
  WriteNumberToSegment(3 , Number%10);
}

void WriteNumberToSegment(byte Segment, byte Value){
  digitalWrite(LATCH_DIO,LOW);
  shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
  shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
  digitalWrite(LATCH_DIO,HIGH);   
}




//DISPLAY (con librerías)
/*The management of the multi-function shield’s digit display is performed in the background using interrupts, which means your application can continue to focus on performing its main task.*/
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
void setup() {
  Timer1.initialize();
  MFS.initialize(&Timer1);    // initialize multi-function shield library
  MFS.write("Hi");  //ejemlo  con string
  delay(2000);
  MFS.write(-273);  //ejemplo con entero negativo
  delay(2000);
  MFS.write(3.141, 2);  // ejemplo float con dos  decimales.
  delay(2000);
}
int counter=0;
byte ended = false;
void loop() {
   if (counter < 200){
    MFS.write((int)counter);
    counter++;
  }
  else if (!ended)  {
    ended = true;
    MFS.write("End");
    MFS.blinkDisplay(DIGIT_ALL, ON);
  }
  delay(50);
}


//PITIDOS (con librerías)
/* The actual timing and sounding of the beeper is controlled in the background using interrupts, which means your application can continue to focus on performing its main task */
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
void setup() {
Timer1.initialize();
MFS.initialize(&Timer1); // initialize multi-function shield library
// NOTE beep control is performed in the background, i.e. beep() is non blocking.
MFS.beep(); //200ms
delay(1000);
// duracion x10ms,silencio x10ms,Nºbeeps,Nºveces,esperar x10ms
MFS.beep(6, 3, 5, 3, 50 );
}
void loop() {
}







??Counting pulses
The multi-function shield library has support for counting pulses (up to 500Hz) applied to an input pin of the Arduino. The counting of pulses is managed in the background using interrupts, which allows your application to focus on performing its main task. After uploading this sketch, repeatedly press button 1 to generate the pulses and see a reading of the press rate on the digit display.
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
void setup() {
  Timer1.initialize();
  MFS.initialize(&Timer1);  // initialize multi-function shield library
  MFS.initPulseInCounter(
      BUTTON_1_PIN,      // use button 1 as means of generating pulses.
      1500,              // the number of milliseconds to wait for a pulse, before resetting pulse in period to 0.
      LOW                // trigger pulse on LOW input.
  );
}

void loop() {
  // Get the period of the most recent pulse (in milliseconds).
  // NOTE: pulse measurements are actually performed using interrupts.
  unsigned int pulsePeriodMs = MFS.getPulseInPeriod();
  if (pulsePeriodMs == 0) {
    MFS.write(0.0, 1);
  }
  else  {
    MFS.write(1000.0 / pulsePeriodMs, 1);  // calculate pulses per second. Display to 1 decimal place.
  }
}





//SENSOR TEMPERATURA LM35 (con librerías)
/*ASEGURARSE de conectar el sensor correctamente, de lo contrario se puede dañar el arduino.*/

#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
//ASEGURARSE de quitar el jumper J1 y conectar LM35 correctamente.

void setup() {
  Timer1.initialize();
  MFS.initialize(&Timer1);  // initialize multi-function shield library
  // Initialize using a low pass filter.
  // Choose either: SMOOTHING_NONE, SMOOTHING_MODERATE or SMOOTHING_STRONG
  MFS.initLM35(SMOOTHING_MODERATE);
}
void loop() {
  int tempCentigrade = MFS.getLM35Data(); // get centigrade in 1/10 of degree.
  MFS.write((float)tempCentigrade / 10, 1);  // display temp to 1 decimal place.
  delay(100);
}



//SÓNAR HC SR04 (con librerías)
/* The library  offers three levels of filtering for smoothing the readings from the sonar module. The trigger and echo pins of the sonar module are connected to Arduino pins 5 and 6 respectively.*/
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
const int TrigPin = 5;
const int EchoPin = 6;
void setup() {
  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);
  Timer1.initialize();
  MFS.initialize(&Timer1);
  // initialize with low pass filter: SMOOTHING_NONE, SMOOTHING_MODERATE or SMOOTHING_STRONG
  MFS.initSonar(SMOOTHING_MODERATE);
}
void loop() {
  MFS.write((int)MFS.getSonarDataCm(TrigPin, EchoPin));
  delay(100);
}


//SONAR CON DISPLAY Y BEEP
/*The sonar ranger application uses the HC SR04 sonar module to measure distance between the module and a solid object up to 5 meters away. This application works in a way similar to the obstacle sensor of some vehicles that assist the driver in parking manoeuvres. As an obstacle nears the sonar module, the beeper is sounded at shorter and shorter intervals. The shield’s button 1 is used for engaging or disengaging the sonar module.The trigger and echo pins of the sonar module are connected to Arduino pins 5 and 6 respectively, which are exposed on the multi-function shield. After powering on the Arduino, place a solid object at different distances away from the sonar module.*/
#include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
const int TrigPin = 5;
const int EchoPin = 6;
enum sonarModeValues {
  MODE_SONAR_OFF,
  MODE_SONAR_ON
};
byte sonarMode = MODE_SONAR_OFF;
void setup() {
  //Serial.begin(9600);
  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);
  Timer1.initialize();
  MFS.initialize(&Timer1);
  MFS.write("off");
}
void loop() {
  byte btn = MFS.getButton();
  switch (sonarMode)
    case MODE_SONAR_OFF:
        if (btn == BUTTON_1_PRESSED) {
          sonarMode = MODE_SONAR_ON;
          MFS.beep(5, 95, 1,0,0);
          MFS.write("on");
        }
        break;
    case MODE_SONAR_ON:
        if (btn == BUTTON_1_PRESSED) {
          sonarMode = MODE_SONAR_OFF;
          MFS.beep(0);
          MFS.write("off");
          MFS.blinkDisplay(DIGIT_ALL, OFF);
          MFS.initSonar();
        }
        else  {
          int distance = MFS.getSonarDataCm(TrigPin, EchoPin);
          if (distance != 0 && distance < 2000) {
            int offPeriod = distance - 6;           
            if (offPeriod < 0) {
              offPeriod = 0;
            }           
            MFS.write(distance);
            MFS.setBeepOffPeriod(offPeriod);           
            MFS.blinkDisplay(DIGIT_ALL, distance < 11);
          }
          delay(100);
        }
        break;
  }
}






//PIR  MPU6050
/* The multi-function shield does not expose the hardware I2C pins of some Arduino boards, such as the Leonardo. The following sketch uses the shield library to read raw values from the MPU6050 sensor, using either the Wire library or a software implementation of I2C. Download the full source code to upload the sketch to an Arduino, after which press button 1 on the shield to toggle reporting of sensor data, and press button 2 to cycle through acceleration, gyro and temperature values.*/
#define _SOFTI2C_H
#include <SoftI2CMaster.h>
#include <Wire.h>
#include <TimerOne.h>
#include <MultiFuncShield.h>
#include "SoftwareI2C.h"
#include "I2C.h"
#include "MPU6050.h"
#define SOFTWARE_I2C
MPU6050 MPU;
void displayHeading(byte mode);
void setup() {
  Serial.begin(9600);
  Timer1.initialize();
#if defined (SOFTWARE_I2C)
  // Use software I2C
  // Uno and Leonardo, use pin 5 for SCL and 6 for SDA. Mega2560, use pin A5 for SDA.
  SoftI2C1.initialize();
  MPU.initialize(&SoftI2C1, MPU_DEFAULT_ADDRESS << 1);
#else
  // Use hardware I2C
  Wire.begin();
  I2C1.initialize(&Wire);
  MPU.initialize(&I2C1, MPU_DEFAULT_ADDRESS);
#endif
  MFS.initialize(&Timer1);
  MFS.write("Acc");
}
byte displayValues = true;
byte displayMode = 0;
void loop() {
  byte btn = MFS.getButton();
  // Use button 1 to toggle reporting of sensor values.
  if (btn == BUTTON_1_PRESSED) {
    displayValues = !displayValues;
    if (displayValues)    {
      displayHeading(displayMode);
    }
    else    {
      MFS.write("Off");
    }
  }
  if (displayValues)  {
    // Use button 2 to cycle though the display modes.
    if (btn == BUTTON_2_PRESSED)
    {
      displayMode++;
      if (displayMode == 3)   {
        displayMode = 0;
      }
      displayHeading(displayMode);
    }
  
    if (displayMode == 0) {
      // display raw acceleration values.
      MPU.getAccelRaw();
      Serial.print((float)MPU.accel_X_Raw / MPU.accelScaleValue);
      Serial.print("\t");
      Serial.print((float)MPU.accel_Y_Raw / MPU.accelScaleValue);
      Serial.print("\t");
      Serial.print((float)MPU.accel_Z_Raw / MPU.accelScaleValue);
      Serial.print("\t\n");
    }
    else if (displayMode == 1)  {
      // display raw gyrovalues
      MPU.getGyroRaw();
      Serial.print((float)MPU.gyro_X_Raw / MPU.gyroScaleValue);
      Serial.print("\t");
      Serial.print((float)MPU.gyro_Y_Raw / MPU.gyroScaleValue);
      Serial.print("\t");
      Serial.print((float)MPU.gyro_Z_Raw / MPU.gyroScaleValue);
      Serial.print("\t\n");
    }
    else if (displayMode == 2)    {
      // display temperature value.
      Serial.println((float)MPU.getTemp10th() / 10);
    }
  }
  delay(50);
}
void displayHeading(byte mode) {
  if (mode == 0)  {
    Serial.println("Acceleration in g (1g = 9.8 m/s/s)");
    Serial.println("X\tY\tZ");
    MFS.write("Acc");
  }
  else if (mode == 1)  {
    Serial.println("Gyro angular velocity in degrees / second");
    Serial.println("X\tY\tZ");
    MFS.write("Gyro");
  }
  else if (mode == 2)  {
    Serial.println("Temperature in degrees celsius.");
    MFS.write("Te");
  }
}




//LATIDOS DEL CORAZÓN
/* This application requires a heart beat sensor similar to the one shown in the image below, which uses infrared light to detect pulses in a finger or ear lobe. When normalized, the sensor outputs an analogue signal of 2.5 volts, which rises and drops every time the blood flow changes due to a heart beat. The application works by counting every time the signal rises above 3 volts, then drops below 2.5 volts, and measures time between pulses to calculate the beats per minute. The beeper is sounded every time a heart beat is detected. The sensor output will need to be connected to Arduino pin A5 exposed on the multi-function shield.After powering on the Arduino, gently but firmly place the index finger on the sensor and wait for the display to start blinking. This indicates the sensor has normalized, after which the shield display will show the beats per minute, and the beeper will sound. If the display remains at 0 and doesn’t blink after several seconds, remove the finger, wait for a while and try again. Ensure the finger is placed with consistent pressure.Possible modification for this application is to have an LED light synchronised with each heart beat.*/
 #include <TimerOne.h>
#include <Wire.h>
#include <MultiFuncShield.h>
void initializeSensorReading();
int data[4];
byte dataIdx=0;
byte pulseDetected = false;
int lastPulseTime = -1;
void setup() {
  Timer1.initialize();
  MFS.initialize(&Timer1);
  initializeSensorReading();
  //Serial.begin(9600);
}

void loop(){
  if (MFS.getTimer() == 0)  {
    MFS.setTimer(10000);    // reset millisecond countdown timer.
    if (lastPulseTime != -1)    {
      lastPulseTime = 10000 + lastPulseTime;
    }
  }
  int sensorValue = analogRead(A5);    // read the sensor.
  if (sensorValue < 20 || sensorValue > 970)  {
    // Sensor hasn't normalized, check how long for in milliseconds.
    if (lastPulseTime != -1 && lastPulseTime - MFS.getTimer() > 700) {
      initializeSensorReading();
    }
  }
  else if (sensorValue > (3 * 1024) / 5) { // value is rising, so must be start of a pulse.
    if (!pulseDetected){
      pulseDetected = true;
      if (lastPulseTime == -1)  {
        lastPulseTime = MFS.getTimer();
      }
      else   {
        int pulsePeriod = lastPulseTime - MFS.getTimer();  // calculate time between pulses in millseconds.
        lastPulseTime = MFS.getTimer();
        int bpm = 60000 / pulsePeriod;    // calculate beats per minute.      
        if (bpm < 45 || bpm > 230)  { // bpm is outside acceptible range, so clear the data buffer.
        initializeSensorReading();
        }
        else  {
          // bpm is within range, but still need to calculate average.        
          data[dataIdx++] = bpm;
          if (dataIdx >= 4)  {
            dataIdx = 0;
          }        
          if (data[0] && data[1] && data[2] && data[3]) { // check if data buffer is full before calculating avg bpm.
            int avgBpm = (data[0] + data[1] + data[2] + data[3]) / 4;          
            MFS.blinkDisplay(DIGIT_ALL, OFF);
            MFS.write(avgBpm);
            MFS.beep();
          }
          else  {
            // buffer not full, so blink the display.
            MFS.blinkDisplay(DIGIT_ALL, ON);
          }
        }
      }
    }
  }
  else if (sensorValue < (1024 / 2)) { // value is falling, so must be end of pulse.
   pulseDetected = false;
  }
  //Serial.println(sensorValue);
  //delay(10);
}

// Initialize the read buffer and display.
void initializeSensorReading(){
  lastPulseTime = 0;
  dataIdx = 0;
  for (int i=0; i<4; i++)  {
    data[i] = 0;
  }
  MFS.write(0);
  MFS.blinkDisplay(DIGIT_ALL, OFF);
}







//POTENCIOMETRO CON LEDES, BOTON, Y BEEP.
//Botones
#define BUTTON1 A1
#define BUTTON2 A2
#define BUTTON3 A3

//Buzzer
#define BUZZER_DIO 3

//Estados para los LED y el Buzzer
#define OFF HIGH
#define ON LOW

//LED
const byte LED[] = {13,12,11,10};

//Control del display
#define LATCH_DIO 4
#define CLK_DIO 7
#define DATA_DIO 8
//Numeros display
const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};

//Potenciometro
#define PotPin 0

void setup() {
  pinMode(BUZZER_DIO, OUTPUT);
  digitalWrite(BUZZER_DIO, OFF);
  
  pinMode(LED[0], OUTPUT);
  pinMode(LED[1], OUTPUT);
  pinMode(LED[2], OUTPUT);
  pinMode(LED[3], OUTPUT);
  
  digitalWrite(LED[0], OFF);
  digitalWrite(LED[1], OFF);
  digitalWrite(LED[2], OFF);
  digitalWrite(LED[3], OFF);
  
  pinMode(LATCH_DIO,OUTPUT);
  pinMode(CLK_DIO,OUTPUT);
  pinMode(DATA_DIO,OUTPUT);
}

void loop() {
  if(!digitalRead(BUTTON1))             
  {
    digitalWrite(LED[0], ON);
    digitalWrite(LED[1], OFF);
    digitalWrite(LED[2], OFF);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF); 
  }
  
  if(!digitalRead(BUTTON2))             
  {
    digitalWrite(LED[0], OFF);
    digitalWrite(LED[1], ON);
    digitalWrite(LED[2], OFF);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF); 
  }
  
  if(!digitalRead(BUTTON3))             
  {
    digitalWrite(LED[0], OFF);
    digitalWrite(LED[1], OFF);
    digitalWrite(LED[2], ON);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF); 
  }
   
   WriteNumber(analogRead(PotPin));
}

void WriteNumber(int Number)
{
  WriteNumberToSegment(0 , Number/1000);
  WriteNumberToSegment(1 , (Number/100)%10);
  WriteNumberToSegment(2 , (Number/10)%10);
  WriteNumberToSegment(3 , Number%10);
}

void WriteNumberToSegment(byte Segment, byte Value)
{
  digitalWrite(LATCH_DIO,LOW); 
  shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
  shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
  digitalWrite(LATCH_DIO,HIGH);    
}



DISPLAY CON BOTONES, LEDS Y POT (SIN LIBRERÍA)

/*
    Tarjeta Multifuncion
    MLO
    miguel_626@hotmail.com
 
    Ejemplos de uso de los diferentes modulos de la tarjeta.
*/
//Botones
#define BUTTON1 A1
#define BUTTON2 A2
#define BUTTON3 A3
//Buzzer
#define BUZZER_DIO 3
//Estados para los LED y el Buzzer
#define OFF HIGH
#define ON LOW
//LED
const byte LED[] = {13,12,11,10};
//Control del display
#define LATCH_DIO 4
#define CLK_DIO 7
#define DATA_DIO 8
//Numeros display
const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
//Potenciometro
#define PotPin 0
void setup() {
  pinMode(BUZZER_DIO, OUTPUT);
  digitalWrite(BUZZER_DIO, OFF);
  pinMode(LED[0], OUTPUT);
  pinMode(LED[1], OUTPUT);
  pinMode(LED[2], OUTPUT);
  pinMode(LED[3], OUTPUT);
  digitalWrite(LED[0], OFF);
  digitalWrite(LED[1], OFF);
  digitalWrite(LED[2], OFF);
  digitalWrite(LED[3], OFF);
  pinMode(LATCH_DIO,OUTPUT);
  pinMode(CLK_DIO,OUTPUT);
  pinMode(DATA_DIO,OUTPUT);
}

void loop() {
  if(!digitalRead(BUTTON1))  {
    digitalWrite(LED[0], ON);
    digitalWrite(LED[1], OFF);
    digitalWrite(LED[2], OFF);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF);
  }

  if(!digitalRead(BUTTON2))  {
    digitalWrite(LED[0], OFF);
    digitalWrite(LED[1], ON);
    digitalWrite(LED[2], OFF);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF);
  }
  if(!digitalRead(BUTTON3)) {
    digitalWrite(LED[0], OFF);
    digitalWrite(LED[1], OFF);
    digitalWrite(LED[2], ON);
    digitalWrite(BUZZER_DIO, ON);
    delay(20);
    digitalWrite(BUZZER_DIO, OFF);
  }
 
   WriteNumber(analogRead(PotPin));
}

void WriteNumber(int Number){
  WriteNumberToSegment(0 , Number/1000);
  WriteNumberToSegment(1 , (Number/100)%10);
  WriteNumberToSegment(2 , (Number/10)%10);
  WriteNumberToSegment(3 , Number%10);
}
void WriteNumberToSegment(byte Segment, byte Value){
  digitalWrite(LATCH_DIO,LOW);
  shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
  shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
  digitalWrite(LATCH_DIO,HIGH);  
}



OTRAS APLICACIONES CON LA LIBRARÍA DEL MÓDULO MULTIFUNCIÓN:
http://www.cohesivecomputing.co.uk/hackatronics/arduino-multi-function-shield/part-3/