Source code for the Curilights Controller. See http://www.saccade.com/writing/projects/CuriController/ for details.
Dependencies: FatFileSystem mbed
This is the source code for the Curilights controller. This lets you interactively control a string of Curilights. It provides a simple click-wheel user interface for changing colors, brightness and behavior. It responds to movement and lighting.
Finished Controller
System Block Diagram
RotaryEncoder.cpp@2:965388eecf95, 2012-01-16 (annotated)
- Committer:
- isonno
- Date:
- Mon Jan 16 06:33:34 2012 +0000
- Revision:
- 2:965388eecf95
- Parent:
- 0:6da5625a6946
Experiment with MODSERIAL - just hung....
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
isonno |
0:6da5625a6946 | 1 | // Rotary Encoder |
isonno |
0:6da5625a6946 | 2 | // Support for the rotary encoder control |
isonno |
0:6da5625a6946 | 3 | |
isonno |
0:6da5625a6946 | 4 | #include "RotaryEncoder.h" |
isonno |
0:6da5625a6946 | 5 | |
isonno |
0:6da5625a6946 | 6 | RotaryEncoder::RotaryEncoder( PinName a, PinName b, PinMode mode ) |
isonno |
0:6da5625a6946 | 7 | : fPinA( a ), fPinB( b, mode ) |
isonno |
0:6da5625a6946 | 8 | { |
isonno |
0:6da5625a6946 | 9 | fPinA.mode( mode ); |
isonno |
0:6da5625a6946 | 10 | fPinB.setSampleFrequency( 3000 ); |
isonno |
0:6da5625a6946 | 11 | |
isonno |
0:6da5625a6946 | 12 | fPinB.attach_asserted( this, &RotaryEncoder::bRise ); |
isonno |
0:6da5625a6946 | 13 | } |
isonno |
0:6da5625a6946 | 14 | |
isonno |
0:6da5625a6946 | 15 | void RotaryEncoder::debug( const char * where ) |
isonno |
0:6da5625a6946 | 16 | { |
isonno |
0:6da5625a6946 | 17 | // printf("%s: as: %d, bs: %d: aCh: %c, bCh: %c\r\n", |
isonno |
0:6da5625a6946 | 18 | // where, aState, bState, aChanged ? 'T' : 'F', bChanged ? 'T' : 'F' ); |
isonno |
0:6da5625a6946 | 19 | } |
isonno |
0:6da5625a6946 | 20 | |
isonno |
0:6da5625a6946 | 21 | |
isonno |
0:6da5625a6946 | 22 | void RotaryEncoder::bRise() |
isonno |
0:6da5625a6946 | 23 | { |
isonno |
0:6da5625a6946 | 24 | // The status of the A channel on the B channel's rising edge |
isonno |
0:6da5625a6946 | 25 | // determines which way the shaft is turning. |
isonno |
0:6da5625a6946 | 26 | if (fPinA.read()) |
isonno |
0:6da5625a6946 | 27 | fCallback.call( 1 ); |
isonno |
0:6da5625a6946 | 28 | else |
isonno |
0:6da5625a6946 | 29 | fCallback.call( -1 ); |
isonno |
0:6da5625a6946 | 30 | } |