Mouse code for the MacroRat
irpair.cpp@15:b80555a4a8b9, 2017-05-14 (annotated)
- Committer:
- kyleliangus
- Date:
- Sun May 14 04:45:21 2017 +0000
- Revision:
- 15:b80555a4a8b9
- Parent:
- 9:1d8e4da058cd
- Child:
- 29:ec2c5a69acd6
Created PID for encoder based on difference of speed rotations.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kyleliangus | 6:3d68fedd6fd9 | 1 | #include "irpair.h" |
kyleliangus | 4:b5b7836ca2b0 | 2 | #include "mbed.h" |
kyleliangus | 4:b5b7836ca2b0 | 3 | |
kyleliangus | 6:3d68fedd6fd9 | 4 | void IRPair::calibrateSensor() { |
kyleliangus | 4:b5b7836ca2b0 | 5 | |
kyleliangus | 9:1d8e4da058cd | 6 | ir.write( 1 ); |
kyleliangus | 9:1d8e4da058cd | 7 | |
kyleliangus | 4:b5b7836ca2b0 | 8 | for (int i = 0; i < samplesToTake; ++i) |
kyleliangus | 5:7e1e4cc19044 | 9 | sensorAvg += recv.read(); |
kyleliangus | 4:b5b7836ca2b0 | 10 | |
kyleliangus | 9:1d8e4da058cd | 11 | ir.write( 0 ); |
kyleliangus | 4:b5b7836ca2b0 | 12 | sensorAvg /= samplesToTake; |
kyleliangus | 4:b5b7836ca2b0 | 13 | } |
kyleliangus | 4:b5b7836ca2b0 | 14 | |
kyleliangus | 6:3d68fedd6fd9 | 15 | float IRPair::getSamples( int samples ) |
kyleliangus | 4:b5b7836ca2b0 | 16 | { |
kyleliangus | 4:b5b7836ca2b0 | 17 | float z = 0; |
kyleliangus | 5:7e1e4cc19044 | 18 | ir.write( 1 ); |
kyleliangus | 4:b5b7836ca2b0 | 19 | for( int i = 0; i < samples; ++i ) |
kyleliangus | 5:7e1e4cc19044 | 20 | z += recv.read(); |
kyleliangus | 5:7e1e4cc19044 | 21 | ir.write( 0 ); |
kyleliangus | 4:b5b7836ca2b0 | 22 | return z / samples; |
kyleliangus | 15:b80555a4a8b9 | 23 | } |