int SensorPin0 = A0; //analog pin 0
int SensorPin1 = A1; //analog pin 1
int SensorPin2 = A2; //analog pin 2
int SensorPin3 = A3; //analog pin 3
int SensorPin4 = A4; //analog pin 4
int SensorPin5 = A5; //analog pin 5
int led0 = 4; // digital pin 4
int HI_limit = 600; // ADC range wrapping
void setup() {
pinMode(led0, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read analog values
int SensorReading0 = analogRead(SensorPin0);
int SensorReading1 = analogRead(SensorPin1);
int SensorReading2 = analogRead(SensorPin2);
int SensorReading3 = analogRead(SensorPin3);
int SensorReading4 = analogRead(SensorPin4);
int SensorReading5 = analogRead(SensorPin5);
// mapping
int A0 = map(SensorReading0, 0, 1024, 0, HI_limit);
int A1 = map(SensorReading1, 0, 1024, 0, HI_limit);
int A2 = map(SensorReading2, 0, 1024, 0, HI_limit);
int A3 = map(SensorReading3, 0, 1024, 0, HI_limit);
int A4 = map(SensorReading4, 0, 1024, 0, HI_limit);
int A5 = map(SensorReading5, 0, 1024, 0, HI_limit);
// turn on led
if (A0 + A1 + A2 + A3 + A4 + A5 > 5) {
digitalWrite(led0, HIGH); // turn led on
}
else {
digitalWrite(led0, LOW); // turn led off
}
// print out
char strBuf[4*6]; // '4': length of "%03d," . '6': number of adc (A0~A5)
sprintf(strBuf,"%03d,%03d,%03d,%03d,%03d,%03d", A0,A1,A2,A3,A4,A5);
Serial.println(strBuf);
// delay
delay(100);
}