SHOW:
|
|
- or go back to the newest paste.
1 | #include <math.h> | |
2 | ||
3 | int ledPin=13; | |
4 | int potPin=A0; | |
5 | ||
6 | void setup() | |
7 | { | |
8 | Serial.begin(38400); | |
9 | pinMode(potPin, INPUT); | |
10 | pinMode(ledPin, OUTPUT); | |
11 | } | |
12 | ||
13 | void loop() | |
14 | { | |
15 | int potPin=A0; | |
16 | int potVal1=analogRead(potPin); | |
17 | delay(640); | |
18 | int potVal2=analogRead(potPin); | |
19 | ||
20 | - | int rSpeed=potVal1-potVal2; |
20 | + | int rSpeed=potVal2-potVal1; |
21 | ||
22 | Serial.print("Velocity over last 690ms: "); | |
23 | Serial.println(rSpeed); | |
24 | Serial.print("Current Pot Position: "); | |
25 | Serial.println(potVal2); | |
26 | ||
27 | isIncreasing(potVal1, potVal2, ledPin); | |
28 | } | |
29 | ||
30 | void isIncreasing(int potVal1, int potVal2, int ledPin) | |
31 | { | |
32 | if (potVal2<potVal1) | |
33 | { | |
34 | boolean isIncreasing=true; | |
35 | digitalWrite(ledPin, HIGH); | |
36 | } | |
37 | else | |
38 | { | |
39 | boolean isIncreasing=false; | |
40 | digitalWrite(ledPin, LOW); | |
41 | } | |
42 | } |