reedit

Dependencies:   TSL_1401 mbed

Committer:
andrey001207
Date:
Wed Mar 28 12:48:00 2018 +0000
Revision:
0:e8239da79e45
edit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrey001207 0:e8239da79e45 1 #include "mbed.h"
andrey001207 0:e8239da79e45 2
andrey001207 0:e8239da79e45 3 #define SI_pin p12
andrey001207 0:e8239da79e45 4 #define CLK_pin p13
andrey001207 0:e8239da79e45 5 #define AO_pin p15
andrey001207 0:e8239da79e45 6
andrey001207 0:e8239da79e45 7 #define HIGH 0x1
andrey001207 0:e8239da79e45 8 #define LOW 0x0
andrey001207 0:e8239da79e45 9
andrey001207 0:e8239da79e45 10
andrey001207 0:e8239da79e45 11 DigitalOut SI (SI_pin);
andrey001207 0:e8239da79e45 12 DigitalOut CLK (CLK_pin);
andrey001207 0:e8239da79e45 13 AnalogIn AO(p15);
andrey001207 0:e8239da79e45 14 AnalogIn AC(p18);
andrey001207 0:e8239da79e45 15
andrey001207 0:e8239da79e45 16 float data[128];
andrey001207 0:e8239da79e45 17 int line[128];
andrey001207 0:e8239da79e45 18 Serial pc(USBTX, USBRX, 115200);
andrey001207 0:e8239da79e45 19
andrey001207 0:e8239da79e45 20 void CamInit();
andrey001207 0:e8239da79e45 21 void ScanFrame();
andrey001207 0:e8239da79e45 22
andrey001207 0:e8239da79e45 23 int main() {
andrey001207 0:e8239da79e45 24 pc.printf("Starting...\n");
andrey001207 0:e8239da79e45 25 CamInit();
andrey001207 0:e8239da79e45 26 // SI = HIGH;
andrey001207 0:e8239da79e45 27 // CLK = HIGH;
andrey001207 0:e8239da79e45 28 while(1) {
andrey001207 0:e8239da79e45 29 ScanFrame();
andrey001207 0:e8239da79e45 30 /*for (int i = 0; i < 128; i+=2)
andrey001207 0:e8239da79e45 31 {
andrey001207 0:e8239da79e45 32 pc.printf("%i ", (int)(data[i] * 4096 / 100));
andrey001207 0:e8239da79e45 33 } */
andrey001207 0:e8239da79e45 34 for (int i = 0; i < 128; i++)
andrey001207 0:e8239da79e45 35 if (data[i] < AC)
andrey001207 0:e8239da79e45 36 pc.printf("O");
andrey001207 0:e8239da79e45 37 else
andrey001207 0:e8239da79e45 38 pc.printf(" ");
andrey001207 0:e8239da79e45 39 // wait_ms(0);
andrey001207 0:e8239da79e45 40 pc.printf("\n");
andrey001207 0:e8239da79e45 41
andrey001207 0:e8239da79e45 42 }
andrey001207 0:e8239da79e45 43 }
andrey001207 0:e8239da79e45 44
andrey001207 0:e8239da79e45 45 void CamInit()
andrey001207 0:e8239da79e45 46 {
andrey001207 0:e8239da79e45 47 SI = HIGH;
andrey001207 0:e8239da79e45 48 CLK = HIGH;
andrey001207 0:e8239da79e45 49 wait_us(5);
andrey001207 0:e8239da79e45 50 SI = LOW;
andrey001207 0:e8239da79e45 51 CLK = LOW;
andrey001207 0:e8239da79e45 52 wait_us(5);
andrey001207 0:e8239da79e45 53
andrey001207 0:e8239da79e45 54 for (int i = 0; i < 128; i++)
andrey001207 0:e8239da79e45 55 {
andrey001207 0:e8239da79e45 56 CLK = HIGH;
andrey001207 0:e8239da79e45 57 wait_us(5);
andrey001207 0:e8239da79e45 58 CLK = LOW;
andrey001207 0:e8239da79e45 59 wait_us(5);
andrey001207 0:e8239da79e45 60 }
andrey001207 0:e8239da79e45 61 }
andrey001207 0:e8239da79e45 62
andrey001207 0:e8239da79e45 63 void ScanFrame()
andrey001207 0:e8239da79e45 64 {
andrey001207 0:e8239da79e45 65 SI = HIGH;
andrey001207 0:e8239da79e45 66 CLK = HIGH;
andrey001207 0:e8239da79e45 67 wait_us(5);
andrey001207 0:e8239da79e45 68 SI = LOW;
andrey001207 0:e8239da79e45 69 CLK = LOW;
andrey001207 0:e8239da79e45 70 wait_us(5);
andrey001207 0:e8239da79e45 71
andrey001207 0:e8239da79e45 72 for (int i = 0;i < 128; i++)
andrey001207 0:e8239da79e45 73 {
andrey001207 0:e8239da79e45 74 data[i] = AO;
andrey001207 0:e8239da79e45 75 CLK = HIGH;
andrey001207 0:e8239da79e45 76 wait_us(5);
andrey001207 0:e8239da79e45 77 CLK = LOW;
andrey001207 0:e8239da79e45 78 wait_us(5);
andrey001207 0:e8239da79e45 79 }
andrey001207 0:e8239da79e45 80 }
andrey001207 0:e8239da79e45 81
andrey001207 0:e8239da79e45 82
andrey001207 0:e8239da79e45 83
andrey001207 0:e8239da79e45 84