int distance2 = 0;
int analogPin0 = 0;
int analogPin2 = 1;
int rood = 11;
int blauw = 10;
int groen = 9;
int blue2 = 5;
int red2 = 6;
int green2 = 3;
zweven redVal = 0.;
zweven blueVal = 0.;
zweven greenVal = 0.;
zweven red2Val = 0.;
zweven blue2Val = 0.;
zweven green2Val = 0.;
VOID Setup {}
pinMode (analogPin0, INPUT);
pinMode (analogPin2, INPUT);
pinMode(red,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(green,OUTPUT);
pinMode(red2,OUTPUT);
pinMode(blue2,OUTPUT);
pinMode(green2,OUTPUT);
Serial.begin(9600); Stel de seriële communicatie.
}
void loop {}
afstand = analogRead(analogPin0);
distance2 = analogRead(analogPin2);
Serial.Print ("waarde afstand:");
Serial.Print ("distnace waarde 2:");
Serial.println(distance);
Serial.println(distance2);
int redInt = 0;
int blueInt = 0;
int greenInt = 0;
int red2Int = 0;
int blue2Int = 0;
int green2Int = 0;
int fadevalue = 0;
Als (afstand < = 350 & & afstand > = 0) {}
blueVal = (350 - afstand) * (255/350.);
blueInt = blueVal (int);
}
else {}
digitalWrite(blue,LOW);
}
Als (afstand < = 300 & & afstand > = 50) {}
greenVal = (afstand - 50.) * (255/250.);
greenInt = greenVal (int);
}
anders als (> 300 afstand & & afstand < = 500) {}
greenVal = (500 - afstand) * (255/200.);
greenInt = greenVal (int);
}
else {}
digitalWrite (groen, lage);
}
Als (afstand < = 650 & & afstand > = 300) {}
redVal = (afstand - 300.) * (255/350.);
redInt = redVal (int);
}
else {}
digitalWrite (rood, laag);
}
Als (distance2 < = 350 & & distance2 > = 0) {}
blue2Val = (350 - distance2) * (255/350.);
blue2Int = blue2Val (int);
}
else {}
digitalWrite(blue2,LOW);
}
Als (distance2 < = 300 & & distance2 > = 50) {}
green2Val = (distance2 - 50.) * (255/250.);
green2Int = green2Val (int);
}
anders als (distance2 > 300 & & distance2 < = 500) {}
green2Val = (500 - distance2) * (255/200.);
green2Int = green2Val (int);
}
else {}
digitalWrite (green2, laag);
}
Als (distance2 < = 650 & & distance2 > = 300) {}
red2Val = (distance2 - 300.) * (255/350.);
red2Int = red2Val (int);
}
else {}
digitalWrite (red2, laag);
}
analogWrite (rood, redInt);
analogWrite (blauw, blueInt);
analogWrite (groen, greenInt);
analogWrite (red2, red2Int);
analogWrite (blue2, blue2Int);
analogWrite (green2, green2Int);
}