camera class

Dependents:   Car2 Car3

Committer:
zamatthews
Date:
Mon Mar 13 22:51:20 2017 +0000
Revision:
2:3a515d43f59d
Parent:
1:25f7955d754f
Child:
3:818084edee42
v rough start on code

Who changed what in which revision?

UserRevisionLine numberNew 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 2:3a515d43f59d 32 wait_ms(10);
zamatthews 2:3a515d43f59d 33 out = 1;
zamatthews 2:3a515d43f59d 34 wait_us(3);
zamatthews 2:3a515d43f59d 35 clk = 1;
zamatthews 2:3a515d43f59d 36 wait_us(3);
zamatthews 2:3a515d43f59d 37 out = 0;
zamatthews 2:3a515d43f59d 38 wait_us(3);
zamatthews 2:3a515d43f59d 39 clk = 0;
zamatthews 2:3a515d43f59d 40 wait_us(3);
zamatthews 2:3a515d43f59d 41
zamatthews 0:cae20a12e706 42 for(int i=0; i<128; i++)
zamatthews 2:3a515d43f59d 43 {
zamatthews 2:3a515d43f59d 44 imageData[i] = IN->read()*100; //reads scales the values to be used as an integer percentage of whiteness
zamatthews 0:cae20a12e706 45 clk = 1;
zamatthews 1:25f7955d754f 46 wait_us(2);
zamatthews 0:cae20a12e706 47 clk = 0;
zamatthews 1:25f7955d754f 48 wait_us(2);
zamatthews 0:cae20a12e706 49 }
zamatthews 0:cae20a12e706 50 return;
zamatthews 0:cae20a12e706 51 }