/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin0 = A0; // Analog input pin that the potentiometer is attached to
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogOutPin5 = 5; // Analog output pin that the LED is attached to
const int analogOutPin6 = 6;
const int analogOutPin9 = 9;
const int analogOutPin10 = 10;
int sensorValue0 = 0; // value read from the 1-10v controller
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int outputValue5 = 0; // value output to the PWM (analog out)
int outputValue6 = 0;
int outputValue9 = 0;
int outputValue10 = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue0 = analogRead(analogInPin0);
// map it to the range of the analog out:
outputValue5 = map(sensorValue0, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin5, outputValue5);
// print the results to the serial monitor:
Serial.print("sensor 0 = " );
Serial.print(sensorValue0);
Serial.print("\t output = ");
Serial.println(outputValue5);
// wait 1000 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(1000);
sensorValue1 = analogRead(analogInPin1);
outputValue6 = map(sensorValue1, 0, 1023, 0, 255);
analogWrite(analogOutPin6, outputValue6);
Serial.print("sensor 1= " );
Serial.print(sensorValue1);
Serial.print("\t output 6= ");
Serial.println(outputValue6);
delay(1000);
sensorValue2 = analogRead(analogInPin2);
outputValue9 = map(sensorValue2, 0, 1023, 0, 255);
analogWrite(analogOutPin9, outputValue9);
Serial.print("sensor 2= " );
Serial.print(sensorValue2);
Serial.print("\t output 9= ");
Serial.println(outputValue9);
delay(1000);
sensorValue3 = analogRead(analogInPin3);
outputValue10 = map(sensorValue3, 0, 1023, 0, 255);
analogWrite(analogOutPin10, outputValue10);
Serial.print("sensor 3= " );
Serial.print(sensorValue1);
Serial.print("\t output 10= ");
Serial.println(outputValue10);
delay(1000);
}