
Again my Partner this week was Laura Ciporen.
When we first reached out for this week's task we realized that our projects while different, could share identical code. We wanted to separate the analog values into ranges that would assign different outputs to each range.
In my case, I wanted to build a device that would measure the amount of finger pressure required to open a jar.
-A jar that is loose would register as Yellow.
-A jar that is the proper tightness would register as Green
-A jar that is too tight would glow Red.
Here is the code.
# define YelLED 2
# define GreLED 3
# define RedLED 4
# define HandSens 5
int HandVAL = 0;
void setup()
{
pinMode (YelLED,OUTPUT);
pinMode (GreLED,OUTPUT);
pinMode (RedLED,OUTPUT);
beginSerial(9600);
} //end setup
void loop()
{
HandVAL=analogRead(HandSens);
HandVAL=HandVAL/4; // converting value from 10bit to 8bit
Serial.println(HandVAL);
if (HandVAL <= 85)
{
analogWrite(YelLED,HandVAL+85);
digitalWrite(GreLED,LOW);
digitalWrite(RedLED,LOW);
}// end if
else if (HandVAL >= 85 && HandVAL <= 170)
{
digitalWrite(YelLED,LOW);
analogWrite(GreLED,HandVAL);
digitalWrite(RedLED,LOW);
}
else if (HandVAL >= 170)
{
digitalWrite(YelLED,LOW);
digitalWrite(GreLED,LOW);
analogWrite(RedLED,HandVAL);
}
else
{
digitalWrite(YelLED,HIGH);
digitalWrite(GreLED,HIGH);
digitalWrite(RedLED,HIGH);
}
delay(10);
}//end loop
You will see that we were hoping for each LED to ramp up in brightness as the analog value increased.
On our first observation the 1st LED in the analog range did not light up at all. The middle one seemed to show a visible varience in brightness and the third was bright with no ramping.
We realized that the by tying the output value to the sensor value HandVAL=analogRead(HandSens)
the lowest range would not be visible. So we added to the value
HandVAL+85
In an effort to "boost" it's brightness.
After further observation, it was determined that the lowest value LED did not even reach the threshold for lighting until the sensor was already through half of it's range. We tried remapping the values so that the threshold was the baseline.
This solution bore no fruit.
If the issue was one purely of computational origin the "boost" in the value should have resolved the issue. Since it did not, we began to look for other potential factors.
Since the LED was on a Digital Switch any brightness variance would need to be achieved using PWM. At the same time the LED has a minimum current (sustained current) to cross the junction within it.
We tried decoupling the 1:1 ratio of the sensor value to the LED output using various mathematical functions to try and give a better spread for the PWM but none of it seemed to produce any visible change in the brightness.
1- PWM is not good enough to display a difference?
2-perhaps there is a mathematical function that will solve this?
issue:
Middle LED seems to be the only with dynamic range (through very small)
1st and 3rd LEDs in series seem Binary.
How to Decouple brightness range from if/else switch range.
Hypotheses
1- PWM is not good enough to display a difference?
2-perhaps there is a mathematical function that will solve this?
Dap-O-Meter from Brian Jones on Vimeo.
FINAL
Untitled from Brian Jones on Vimeo.
No comments:
Post a Comment