int AIO = A0; // LED connected to digital pin 9
int S0 = 4;
int S1 = 5;
int S2 = 6;
void setup() {
// nothing happens in setup
pinMode(AIO, OUTPUT);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
}
int writeSignal (const byte which)
{
// select correct MUX channel
digitalWrite (S0, (which & 1) ? HIGH : LOW); // low-order bit
digitalWrite (S1, (which & 2) ? HIGH : LOW);
digitalWrite (S2, (which & 4) ? HIGH : LOW); // high-order bit
// now read the sensor
showSignal();
//analogWrite(AIO, 255);
} // end of readSensor
void showSignal() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 25) {
// sets the value (range from 0 to 255):
analogWrite(AIO, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 25) {
// sets the value (range from 0 to 255):
analogWrite(AIO, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
void loop ()
{
// show all 8 sensor readings
for (byte i = 0; i < 8; i++)
{
Serial.print ("Sensor ");
Serial.print (i);
Serial.print (" Show Signal: ");
writeSignal(i);
}
delay (200);
} // end of loop