The circuit diagrams (one made on digital environment, the other one is the implemented) can be seen below:
|
Digital Drawed Circuit
|
|
Implemented Circuit
|
Here is a video available to see the outputs and how the system works:
Arduino Code :
/*
Can KAVALOĞLU
*/
int LEDRed = 9;
int LEDGreen = 10;
int LEDBlue = 11;
int sensePin = 0;
int val;
void setup(){
pinMode(LEDRed, OUTPUT);
pinMode(LEDGreen, OUTPUT);
pinMode(LEDBlue, OUTPUT);
pinMode(sensePin, INPUT);
Serial.begin(9600);
}
void loop(){
val = analogRead(sensePin);
Serial.println(val);
if(val < 10){
analogWrite(LEDRed, 0);
analogWrite(LEDBlue,0);
analogWrite(LEDGreen,0);
}
else if (val<100) {
analogWrite(LEDRed,0);
analogWrite(LEDBlue,128);
analogWrite(LEDGreen,128);
} else if (val<200) {
analogWrite(LEDRed,map(val,100,200,0,128));
analogWrite(LEDBlue,map(val,100,200,128,0));
analogWrite(LEDGreen,128);
} else if (val<300) {
analogWrite(LEDRed,128);
analogWrite(LEDBlue,0);
analogWrite(LEDGreen,128);
} else if (val<400) {
analogWrite(LEDRed,128);
analogWrite(LEDBlue,map(val,200,400,0,128));
analogWrite(LEDGreen,map(val,200,400,128,0));
} else if (val<500) {
analogWrite(LEDRed,128);
analogWrite(LEDBlue,128);
analogWrite(LEDGreen,0);
} else if (val<800) {
analogWrite(LEDRed,map(val,400,800,128,0));
analogWrite(LEDBlue,128);
analogWrite(LEDGreen,map(val,800,400,0,128));
}
}
Hiç yorum yok:
Yorum Gönder