| Line | |
|---|
| 1 | #ifndef DEMO_H |
|---|
| 2 | #define DEMO_H |
|---|
| 3 | |
|---|
| 4 | // Define each mode with the following interface for a loop and modePress |
|---|
| 5 | // function that will be called during the main loop and if the mode button |
|---|
| 6 | // was pressed respectively. It's up to each mode implementation to fill |
|---|
| 7 | // these in and add their logic. |
|---|
| 8 | class Demo { |
|---|
| 9 | public: |
|---|
| 10 | virtual ~Demo() {} |
|---|
| 11 | |
|---|
| 12 | virtual void loop() = 0; |
|---|
| 13 | virtual void modePress() = 0; |
|---|
| 14 | }; |
|---|
| 15 | |
|---|
| 16 | // Linear interpolation function is handy for all the modes to use. |
|---|
| 17 | float lerp(float x, float xmin, float xmax, float ymin, float ymax) { |
|---|
| 18 | if (x >= xmax) { |
|---|
| 19 | return ymax; |
|---|
| 20 | } |
|---|
| 21 | if (x <= xmin) { |
|---|
| 22 | return ymin; |
|---|
| 23 | } |
|---|
| 24 | return ymin + (ymax-ymin)*((x-xmin)/(xmax-xmin)); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | #endif |
|---|
Note: See
TracBrowser
for help on using the repository browser.