/*
* LAB Name: Arduino CD74HC4067 Analog Multiplexer Example
* Author: Khaled Magdy
* For More Info Visit: www.DeepBlueMbedded.com
*/
#include <CD74HC4067.h>
#define SIG_PIN A0
#define LED0_PIN 6
#define LED1_PIN 9
#define LED2_PIN 10
#define LED3_PIN 11
CD74HC4067 my_mux(5, 4, 3, 2); // (S0, S1, S2, S3)
int LED_PINS[4] = {LED0_PIN, LED1_PIN, LED2_PIN, LED3_PIN};
void setup()
{
pinMode(LED0_PIN, OUTPUT);
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(LED3_PIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
for(int i=0; i<4; i++)
{
my_mux.channel(i);
delay(10); // For Simulation
analogWrite(LED_PINS[i], analogRead(SIG_PIN)>>2);
Serial.print(analogRead(SIG_PIN));
Serial.print(", ");
}
Serial.println("");
}