Techylah,
Slowly I am getting there.
Reworked your sample idea code.
Changed some variable names.
For friday testing I created a sketch with 3 possible actions to be tested.
1] Full linear with lookuptbale
2] Full linear with lookuptable with speedstartValue included
3] Power line with X-Y turningpoints.
As far as I can test they all work for what I see happening on the display.
Only thing I ran into is that when I call void fillLookupTable() from the void loop, speedstartValue is not changed in the void loop action of the speedfinaleValue.
This new speedstartValue is only validated when I reset the Mega.
I can change the value on the fly and the display acknowledged the action that there is a new value and it is written to the EEPROM but it is not changed in void fillLookupTable().
As the switchpointXValue and switchpointYValue are in the same void fillLookupTable() I assume they also only change when I reboot the Mega.
Do I miss something that is causing the behavior of void fillLookupTable() this way.
void setup()
{
fillLookupTable(); // fill the look uptable
}
void loop()
{
// +++++++++++++++ regular speed - brake mode +++++++++++++++
// in regular mode control the outputs with output cross block function to prevent speed and brake to be ON together
sensorValue = analogRead(sensorspeedPin); // read the raw value from the linear hall sensor:
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);// apply the calibration to the sensor reading from the hall sensor
sensormappedValue = constrain (sensorValue,0,255); // keep value in range for trigger motion
//speedValue = map(sensormappedValue, 0, 255, speedstartValue, 255);
// ++++ curve section +++++++
speedValue = lookupTable[sensormappedValue];
// ++++ curve section +++++++
speedfinalValue = speedValue;
if (sensormappedValue > deathbandValue)
{
analogWrite(pwmoutspeedPin, speedfinalValue);
analogWrite(pwmoutbrakePin, 0);
digitalWrite(ledDBPin, LOW);
}
else
{
analogWrite(pwmoutspeedPin, 0);
(speedfinalValue, 0);
analogWrite(pwmoutbrakePin, brakeNValue);
digitalWrite (ledDBPin,HIGH);
}
// +++++ Write values to EEPROM when they change during operation after 3 seconds
if (speedstartValue != speedstartValueold)
{
speedstartOffTime = currentTime + 3000;
digitalWrite(ledEEWPin,HIGH);
speedstartValueold = speedstartValue;
fillLookupTable;
}
if (speedstartOffTime != 0 && currentTime > speedstartOffTime )
{
EEPROM.write(2,speedstartValue);
speedstartOffTime = 0;
digitalWrite(ledEEWPin,LOW);
}
speedstartValueold = speedstartValue;
}
// ++++++ single loop actions +++++++
void fillLookupTable()
{
//speedstartValueold = speedstartValue; //will this work here?
//switchpointXValueold = switchpointXValue; //will this work here?
//switchpointYValueold = switchpointYValue; //will this work here?
// int switchpointXValue = 80 * 255 / 100; // the switch is at 80% (default) of the full input range (0 to this is linear)
// int switchpointYValue = 60 * (255 - speedStart) / 100; // the power or speed at the switch point is lower, only 60% of the remaining power level
for (int i=0; i<256; i++)
//++ linear powerline from 0 to 255 ++
//lookupTable[i] = i; // linear powerline
//++ linear power line from speedstartValue to 255 ++
lookupTable[i] = map(i, 0, 255, speedstartValue, 255); // linear powerline with startspeed included
//++ knicked powerline at X and Y value ++
/*
if (i < switchpointXValue)
lookupTable[i] = map(i, 0, switchpointXValue, speedstartValue, switchpointYValue);
else
lookupTable[i] = map(i, switchpointXValue, 255, switchpointYValue, 255 ); // this could get replaced by a curve after all is working
*/
}
Paco