Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array
Fork of Pinscape_Controller by
TSL1410R/tsl410r.cpp@2:c174f9ee414a, 2014-07-22 (annotated)
- Committer:
- mjr
- Date:
- Tue Jul 22 04:33:47 2014 +0000
- Revision:
- 2:c174f9ee414a
- Child:
- 6:cc35eb643e8f
Before change to ISR for accelerometer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjr | 2:c174f9ee414a | 1 | #include "mbed.h" |
mjr | 2:c174f9ee414a | 2 | #include "tsl1410r.h" |
mjr | 2:c174f9ee414a | 3 | |
mjr | 2:c174f9ee414a | 4 | TSL1410R::TSL1410R(PinName siPort, PinName clockPort, PinName aoPort) |
mjr | 2:c174f9ee414a | 5 | : si(siPort), clock(clockPort), ao(aoPort) |
mjr | 2:c174f9ee414a | 6 | { |
mjr | 2:c174f9ee414a | 7 | // clear out power-on noise by clocking through all pixels twice |
mjr | 2:c174f9ee414a | 8 | clear(); |
mjr | 2:c174f9ee414a | 9 | clear(); |
mjr | 2:c174f9ee414a | 10 | } |
mjr | 2:c174f9ee414a | 11 | |
mjr | 2:c174f9ee414a | 12 | void TSL1410R::clear() |
mjr | 2:c174f9ee414a | 13 | { |
mjr | 2:c174f9ee414a | 14 | // clock in an SI pulse |
mjr | 2:c174f9ee414a | 15 | si = 1; |
mjr | 2:c174f9ee414a | 16 | clock = 1; |
mjr | 2:c174f9ee414a | 17 | clock = 0; |
mjr | 2:c174f9ee414a | 18 | si = 0; |
mjr | 2:c174f9ee414a | 19 | |
mjr | 2:c174f9ee414a | 20 | // clock out all pixels |
mjr | 2:c174f9ee414a | 21 | for (int i = 0 ; i < nPix + 1 ; ++i) { |
mjr | 2:c174f9ee414a | 22 | clock = 1; |
mjr | 2:c174f9ee414a | 23 | clock = 0; |
mjr | 2:c174f9ee414a | 24 | } |
mjr | 2:c174f9ee414a | 25 | } |
mjr | 2:c174f9ee414a | 26 | |
mjr | 2:c174f9ee414a | 27 | void TSL1410R::read(uint16_t *pix, int n) |
mjr | 2:c174f9ee414a | 28 | { |
mjr | 2:c174f9ee414a | 29 | // Start the next integration cycle by pulsing SI and one clock. |
mjr | 2:c174f9ee414a | 30 | si = 1; |
mjr | 2:c174f9ee414a | 31 | clock = 1; |
mjr | 2:c174f9ee414a | 32 | clock = 0; |
mjr | 2:c174f9ee414a | 33 | si = 0; |
mjr | 2:c174f9ee414a | 34 | |
mjr | 2:c174f9ee414a | 35 | // figure how many pixels to skip on each read |
mjr | 2:c174f9ee414a | 36 | int skip = nPix/n - 1; |
mjr | 2:c174f9ee414a | 37 | |
mjr | 2:c174f9ee414a | 38 | // read the pixels |
mjr | 2:c174f9ee414a | 39 | for (int src = 0, dst = 0 ; src < nPix ; ++src) |
mjr | 2:c174f9ee414a | 40 | { |
mjr | 2:c174f9ee414a | 41 | // read this pixel |
mjr | 2:c174f9ee414a | 42 | pix[dst++] = ao.read_u16(); |
mjr | 2:c174f9ee414a | 43 | |
mjr | 2:c174f9ee414a | 44 | // clock in the next pixel |
mjr | 2:c174f9ee414a | 45 | clock = 1; |
mjr | 2:c174f9ee414a | 46 | clock = 0; |
mjr | 2:c174f9ee414a | 47 | |
mjr | 2:c174f9ee414a | 48 | // clock skipped pixels |
mjr | 2:c174f9ee414a | 49 | for (int i = 0 ; i < skip ; ++i, ++src) { |
mjr | 2:c174f9ee414a | 50 | clock = 1; |
mjr | 2:c174f9ee414a | 51 | clock = 0; |
mjr | 2:c174f9ee414a | 52 | } |
mjr | 2:c174f9ee414a | 53 | } |
mjr | 2:c174f9ee414a | 54 | |
mjr | 2:c174f9ee414a | 55 | // clock out one extra pixel to leave A1 in the high-Z state |
mjr | 2:c174f9ee414a | 56 | clock = 1; |
mjr | 2:c174f9ee414a | 57 | clock = 0; |
mjr | 2:c174f9ee414a | 58 | } |