camera class
Camera.cpp@1:25f7955d754f, 2017-03-13 (annotated)
- Committer:
- zamatthews
- Date:
- Mon Mar 13 20:06:31 2017 +0000
- Revision:
- 1:25f7955d754f
- Parent:
- 0:cae20a12e706
- Child:
- 2:3a515d43f59d
added waits to lower clock speed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zamatthews | 0:cae20a12e706 | 1 | #include "Camera.h" |
zamatthews | 0:cae20a12e706 | 2 | |
zamatthews | 0:cae20a12e706 | 3 | Camera::Camera(PinName digOut, PinName clock, PinName AnIn ): OUT(digOut), CLK(clock) |
zamatthews | 0:cae20a12e706 | 4 | { |
zamatthews | 0:cae20a12e706 | 5 | IN = new AnalogIn(AnIn); |
zamatthews | 0:cae20a12e706 | 6 | } |
zamatthews | 0:cae20a12e706 | 7 | |
zamatthews | 0:cae20a12e706 | 8 | /* |
zamatthews | 0:cae20a12e706 | 9 | Captures a line and fills an array with its values |
zamatthews | 0:cae20a12e706 | 10 | */ |
zamatthews | 0:cae20a12e706 | 11 | void Camera::capture() |
zamatthews | 0:cae20a12e706 | 12 | { |
zamatthews | 0:cae20a12e706 | 13 | DigitalOut out(OUT); |
zamatthews | 0:cae20a12e706 | 14 | DigitalOut clk(CLK); |
zamatthews | 0:cae20a12e706 | 15 | |
zamatthews | 0:cae20a12e706 | 16 | out = 1; //out high |
zamatthews | 1:25f7955d754f | 17 | wait_us(3); |
zamatthews | 0:cae20a12e706 | 18 | clk = 1; //clock high |
zamatthews | 1:25f7955d754f | 19 | wait_us(3); |
zamatthews | 0:cae20a12e706 | 20 | out = 0; //out low |
zamatthews | 1:25f7955d754f | 21 | wait_us(3); |
zamatthews | 0:cae20a12e706 | 22 | clk = 0; //clock low |
zamatthews | 1:25f7955d754f | 23 | wait_us(3); |
zamatthews | 0:cae20a12e706 | 24 | for(int i = 0; i < 128; i++) |
zamatthews | 0:cae20a12e706 | 25 | { |
zamatthews | 0:cae20a12e706 | 26 | clk = 1; |
zamatthews | 1:25f7955d754f | 27 | wait_us(1); |
zamatthews | 0:cae20a12e706 | 28 | clk = 0; |
zamatthews | 1:25f7955d754f | 29 | wait_us(1); |
zamatthews | 0:cae20a12e706 | 30 | } |
zamatthews | 0:cae20a12e706 | 31 | |
zamatthews | 0:cae20a12e706 | 32 | for(int i=0; i<128; i++) |
zamatthews | 0:cae20a12e706 | 33 | { |
zamatthews | 0:cae20a12e706 | 34 | clk = 1; |
zamatthews | 1:25f7955d754f | 35 | wait_us(2); |
zamatthews | 0:cae20a12e706 | 36 | imageData[i] = IN->read()*100; //reads scales the values to be used as an integer percentage of whiteness |
zamatthews | 0:cae20a12e706 | 37 | clk = 0; |
zamatthews | 1:25f7955d754f | 38 | wait_us(2); |
zamatthews | 0:cae20a12e706 | 39 | } |
zamatthews | 0:cae20a12e706 | 40 | return; |
zamatthews | 0:cae20a12e706 | 41 | } |