forked from dmadison/CtrlUtil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvertAxis.ino
39 lines (30 loc) · 971 Bytes
/
InvertAxis.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Project Controller Utilities Library
* @author David Madison
* @link github.com/dmadison/CtrlUtil
* @license MIT - Copyright (c) 2021 David Madison
*
* Example: InvertAxis
* Description: Takes an input value from a potentiometer connected to the board's
* analog to digital converter (ADC) and inverts it.
*/
#include <CtrlUtil.h>
const int InputPin = A0;
const int AnalogMin = 0; // min value returned from the ADC
const int AnalogMax = 1023; // max value returned from the ADC
void setup() {
Serial.begin(115200);
pinMode(InputPin, INPUT);
}
void loop() {
int value = analogRead(InputPin);
// int inverted = invertAxis(value); // using 0-1023
int inverted = invertAxis(value, AnalogMin, AnalogMax); // using custom values (set above)
Serial.print("Axis: ");
Serial.print(value);
Serial.print('\t');
Serial.print("Inverted: ");
Serial.print(inverted);
Serial.println();
delay(100);
}