الكود
void setup() {
pinMode(A0, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
int vm = analogRead(A0);
float tm = (vm / 1024.0) * 500.0;
if (tm < 5) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8,LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if (5 < tm && tm < 10) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8,LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if (10 < tm && tm < 15) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8,LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if (15 < tm && tm < 20) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8,LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if (20 < tm && tm < 25) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8,LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if (25 < tm && tm < 30) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8,LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if ( 30 < tm && tm < 35 ) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8,HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else if ( 35 < tm && tm < 40 ) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8,HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
}
else if ( 40 < tm && tm < 45 ) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8,HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
else if ( 45 < tm ) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8,HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
delay(100);
}
delay(1);
}
No comments:
Post a Comment