This is my followup question based on a serie of one project. Go my to profile to read 'm all.
So I'm building something which includes a function that has a count (1000) that decreases over time, but by pressing a soft pot meter the count increases. By every increment of 200 one LED is lit. So if the count is 837 4 LEDs are burning.
In my previous question I had issues lighting the LEDs, because they didn't burn even when the code was, as far as I could see correct. Instead it did the opposite of what I coded. Now I changed my code the opposite direction,
writing:
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
Which actually set the LED to bright. While is I'd write it 'HIGH' it would dim.
So my actual question is: How could my LED be lit if it's set to 'low', while you have to set it to 'high' to be actually popping off light?
My complete code:
int cleanCount = 1000;
int IsItWorkingLED = 13;
int softpotPin = A0; //analog pin 0
int LED1 = 1;
int LED2 = 2;
int LED3 = 4;
int LED4 = 5;
int LED5 = 7;
void setup () {
Serial.begin(9600);
digitalWrite(softpotPin, HIGH); //enable pullup resistor
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (HIGH is the voltage level)
}
void loop() {
int softpotReading = analogRead(softpotPin);
if (softpotReading < 980) { // IF TOUCHED
digitalWrite(IsItWorkingLED, HIGH);
++cleanCount;
Serial.println(cleanCount);
delay(8); // Increase 5 times as fast
}
else if (softpotReading > 980) { // IF NOT TOUCHED
digitalWrite(IsItWorkingLED, LOW);
--cleanCount;
Serial.println(cleanCount);
delay(32); // Decrease slowly
}
else { // If there is something wrong..
Serial.println("Something wrong!");
digitalWrite(IsItWorkingLED, HIGH);
delay(250);
digitalWrite(IsItWorkingLED, LOW);
delay(250);
}
if (cleanCount <= 200) {
Serial.println("Knal 1 LED aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 201 && cleanCount <= 400) {
Serial.println("Knal 2 LEDs aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 401 && cleanCount <= 600) {
Serial.println("Knal 3 LEDs aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 601 && cleanCount <= 800) {
Serial.println("Knal 4 LEDs aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 801 && cleanCount <= 1000) {
Serial.println("Knal 5 LEDs aan");
digitalWrite(1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(4, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(5, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(7, LOW); // turn the LED on (LOW is the voltage level)
}
else {
Serial.println("Just..do nothing");
}
}