Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array

Dependencies:   USBDevice mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Wed Jul 16 23:33:12 2014 +0000
Revision:
1:d913e0afb2ac
Parent:
tls1410r.cpp@0:5acbbe3f4cf4
Before removing time/frequency limit on reading the plunger sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 0:5acbbe3f4cf4 1 #include "mbed.h"
mjr 1:d913e0afb2ac 2 #include "tsl1410r.h"
mjr 0:5acbbe3f4cf4 3
mjr 1:d913e0afb2ac 4 TSL1410R::TSL1410R(PinName siPort, PinName clockPort, PinName aoPort)
mjr 0:5acbbe3f4cf4 5 : si(siPort), clock(clockPort), ao(aoPort)
mjr 0:5acbbe3f4cf4 6 {
mjr 0:5acbbe3f4cf4 7 // clear out power-on noise by clocking through all pixels twice
mjr 0:5acbbe3f4cf4 8 clear();
mjr 0:5acbbe3f4cf4 9 clear();
mjr 0:5acbbe3f4cf4 10 }
mjr 0:5acbbe3f4cf4 11
mjr 1:d913e0afb2ac 12 void TSL1410R::clear()
mjr 0:5acbbe3f4cf4 13 {
mjr 0:5acbbe3f4cf4 14 // clock in an SI pulse
mjr 0:5acbbe3f4cf4 15 si = 1;
mjr 0:5acbbe3f4cf4 16 clock = 1;
mjr 0:5acbbe3f4cf4 17 clock = 0;
mjr 0:5acbbe3f4cf4 18 si = 0;
mjr 0:5acbbe3f4cf4 19
mjr 0:5acbbe3f4cf4 20 // clock out all pixels
mjr 0:5acbbe3f4cf4 21 for (int i = 0 ; i < nPix+1 ; ++i) {
mjr 0:5acbbe3f4cf4 22 clock = 1;
mjr 0:5acbbe3f4cf4 23 clock = 0;
mjr 0:5acbbe3f4cf4 24 }
mjr 0:5acbbe3f4cf4 25 }
mjr 0:5acbbe3f4cf4 26
mjr 1:d913e0afb2ac 27 void TSL1410R::read(uint16_t *pix, int n, int integrate_us)
mjr 0:5acbbe3f4cf4 28 {
mjr 0:5acbbe3f4cf4 29 // Start an integration cycle - pulse SI, then clock all pixels. The
mjr 0:5acbbe3f4cf4 30 // CCD will integrate light starting 18 clocks after the SI pulse, and
mjr 0:5acbbe3f4cf4 31 // continues integrating until the next SI pulse, which cannot occur
mjr 0:5acbbe3f4cf4 32 // until all pixels have been clocked.
mjr 0:5acbbe3f4cf4 33 si = 1;
mjr 0:5acbbe3f4cf4 34 clock = 1;
mjr 0:5acbbe3f4cf4 35 clock = 0;
mjr 0:5acbbe3f4cf4 36 si = 0;
mjr 0:5acbbe3f4cf4 37 for (int i = 0 ; i < nPix+1 ; ++i) {
mjr 0:5acbbe3f4cf4 38 clock = 1;
mjr 0:5acbbe3f4cf4 39 clock = 0;
mjr 0:5acbbe3f4cf4 40 }
mjr 0:5acbbe3f4cf4 41
mjr 0:5acbbe3f4cf4 42 // delay by the specified additional integration time
mjr 0:5acbbe3f4cf4 43 wait_us(integrate_us);
mjr 0:5acbbe3f4cf4 44
mjr 0:5acbbe3f4cf4 45 // end the current integration cycle and hold the integrated values
mjr 0:5acbbe3f4cf4 46 si = 1;
mjr 0:5acbbe3f4cf4 47 clock = 1;
mjr 0:5acbbe3f4cf4 48 clock = 0;
mjr 0:5acbbe3f4cf4 49 si = 0;
mjr 0:5acbbe3f4cf4 50
mjr 0:5acbbe3f4cf4 51 // figure how many pixels to skip on each read
mjr 0:5acbbe3f4cf4 52 int skip = nPix/n - 1;
mjr 0:5acbbe3f4cf4 53
mjr 0:5acbbe3f4cf4 54 // read the pixels
mjr 0:5acbbe3f4cf4 55 for (int src = 0, dst = 0 ; src < nPix ; ++src)
mjr 0:5acbbe3f4cf4 56 {
mjr 0:5acbbe3f4cf4 57 // read this pixel
mjr 1:d913e0afb2ac 58 pix[dst++] = ao.read_u16();
mjr 0:5acbbe3f4cf4 59
mjr 0:5acbbe3f4cf4 60 // clock in the next pixel
mjr 0:5acbbe3f4cf4 61 clock = 1;
mjr 0:5acbbe3f4cf4 62 clock = 0;
mjr 0:5acbbe3f4cf4 63
mjr 0:5acbbe3f4cf4 64 // clock skipped pixels
mjr 1:d913e0afb2ac 65 for (int i = 0 ; i < skip ; ++i, ++src) {
mjr 0:5acbbe3f4cf4 66 clock = 1;
mjr 0:5acbbe3f4cf4 67 clock = 0;
mjr 0:5acbbe3f4cf4 68 }
mjr 0:5acbbe3f4cf4 69 }
mjr 0:5acbbe3f4cf4 70
mjr 0:5acbbe3f4cf4 71 // clock out one extra pixel to make sure the device is ready for another go
mjr 0:5acbbe3f4cf4 72 clock = 1;
mjr 0:5acbbe3f4cf4 73 clock = 0;
mjr 0:5acbbe3f4cf4 74 }