Skip to content

Commit

Permalink
Merge pull request #4 from 1411vi14/master
Browse files Browse the repository at this point in the history
Added alternative readSwitchesX3 method
  • Loading branch information
Dirk- authored Jan 20, 2019
2 parents c641718 + 3d83a28 commit ec67320
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Asuro KEYWORD1
Init KEYWORD2
readBattery KEYWORD2
readSwitches KEYWORD2
readSwitchesX3 KEYWORD2
setSwitchFactor KEYWORD2
getSwitchFactor KEYWORD2
readOdometry KEYWORD2
Expand Down
20 changes: 20 additions & 0 deletions src/Asuro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ int Asuro::readSwitches(void)
return ((10240000L/tmp-10000L)*_switchFactor+5000L)/10000;
}

/*
Read out switches
x^3 Interpolation
returns bit field of switch value bit0 = K6, ... , bit5 = K1
*/
int Asuro::readSwitchesX3(void)
{
long tmp;
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
delayMicroseconds(10);
tmp = analogRead(switches); // 0..1023
digitalWrite(3, LOW);
//-0,1+0,5
double x = tmp;
int sw = fmax( -2.28599856254619E-07*x*x*x + 0.000682617808856135*x*x - 0.752374263864664*x + 299.852039530042, 0);

return sw;
}


/*
Returns the battery voltage
Expand Down
13 changes: 10 additions & 3 deletions src/Asuro.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class Asuro {
*/
void setSwitchFactor(long switchFactor);

/*
/*
Get the calculation factor for the switches bit field.
Standard value is 62 (decimal).
*/
long Asuro::getSwitchFactor(void);
*/
long getSwitchFactor(void);

/*
Initializes the hardware (ports, ADC, PWM)
Expand Down Expand Up @@ -113,6 +113,13 @@ class Asuro {
*/
void setFrontLED(unsigned char status);

/*
Read out switches
Interpolated x^3
returns bit field of switch value bit0 = K6, ... , bit5 = K1
*/
int readSwitchesX3(void);

/*
Read out switches
Expand Down

0 comments on commit ec67320

Please sign in to comment.