– all LEDs are flickering after plugging my Arduino UNO to the USB port
- at the moment they also turn on and off if they have the same values
Because of this:
else
{
blink(5, 10, 10);
blink(6, 10, 10);
blink(7, 10, 10);
}
Remove this code if you want nothing to happen when the values are the same.
There are some improvements that could be made to the code that Rob posted (which was based on yours initially, so it is not his fault).
int lightLevel1 = analogRead(flexPin1);
int lightLevel2 = analogRead(flexPin2);
How do you get light level from a flex sensor? Meaningful names are very useful for writing code that does not require a lot of thinking to decipher/create.
I mean that there is nothing stopping you from writing:
int lightLevel1 = analogRead(flexPin1);
int q = analogRead(flexPin2);
But, of course, that makes little sense when you then subtract q from lightLevel1. Your names are only a little less confusing, since flex sensors and light are unrelated.
Unless you have actually written 1 and 2 on the sensors, names that reflect the physical arrangement of the sensors make more sense, too.
(for example: flexPin1 gives me a value of 270, flexPin2 a value of 225 -> difference of 25 -> LED 7 should blink)
There are no Serial.print() statements in the code that indicate that you know what the actual values are. Normally, I don't like to see commented out code in code that is posted, but commented out Serial.print() statements are an exception. With them present but commented out, it is easy to see that you do know how to debug code and that you have facts to support your suppositions.
Without them, we have no way of knowing what actual values you are reading from each sensor, or that you are even reading each sensor correctly.