Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@3:564463c06ffa, 2016-11-02 (annotated)
- Committer:
- FatCookies
- Date:
- Wed Nov 02 13:20:08 2016 +0000
- Revision:
- 3:564463c06ffa
- Parent:
- 1:a4883d9c75ec
- Child:
- 4:968036e0940b
updated to work, send image and centre point
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| maximusismax | 0:566127ca8048 | 1 | #include "mbed.h" |
| maximusismax | 0:566127ca8048 | 2 | #include "TFC.h" |
| FatCookies | 3:564463c06ffa | 3 | #define CAM_THRESHOLD 128 |
| maximusismax | 0:566127ca8048 | 4 | |
| maximusismax | 0:566127ca8048 | 5 | |
| maximusismax | 0:566127ca8048 | 6 | DigitalOut myled(LED1); |
| FatCookies | 3:564463c06ffa | 7 | Serial pc(USBTX,USBRX); |
| FatCookies | 3:564463c06ffa | 8 | char curr_line[128]; |
| FatCookies | 3:564463c06ffa | 9 | |
| FatCookies | 3:564463c06ffa | 10 | uint8_t curr_left; |
| FatCookies | 3:564463c06ffa | 11 | uint8_t curr_right; |
| FatCookies | 3:564463c06ffa | 12 | |
| FatCookies | 3:564463c06ffa | 13 | uint8_t right; |
| FatCookies | 3:564463c06ffa | 14 | uint8_t left; |
| FatCookies | 3:564463c06ffa | 15 | uint8_t measured_value; |
| maximusismax | 0:566127ca8048 | 16 | |
| maximusismax | 0:566127ca8048 | 17 | int main() { |
| maximusismax | 0:566127ca8048 | 18 | TFC_Init(); |
| FatCookies | 3:564463c06ffa | 19 | pc.baud(57600); |
| maximusismax | 0:566127ca8048 | 20 | |
| FatCookies | 3:564463c06ffa | 21 | uint32_t i = 0; |
| maximusismax | 0:566127ca8048 | 22 | while(1) { |
| FatCookies | 3:564463c06ffa | 23 | |
| maximusismax | 0:566127ca8048 | 24 | //If we have an image ready |
| FatCookies | 3:564463c06ffa | 25 | if(TFC_LineScanImageReady>0) { |
| FatCookies | 3:564463c06ffa | 26 | |
| FatCookies | 3:564463c06ffa | 27 | left = 0; |
| FatCookies | 3:564463c06ffa | 28 | right = 0; |
| FatCookies | 3:564463c06ffa | 29 | for(i = 63; i > 0; i--) { |
| FatCookies | 3:564463c06ffa | 30 | curr_left = (int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF; |
| FatCookies | 3:564463c06ffa | 31 | if(curr_left < CAM_THRESHOLD) { |
| FatCookies | 3:564463c06ffa | 32 | left = i; |
| FatCookies | 3:564463c06ffa | 33 | break; |
| maximusismax | 0:566127ca8048 | 34 | } |
| FatCookies | 3:564463c06ffa | 35 | } |
| FatCookies | 3:564463c06ffa | 36 | |
| FatCookies | 3:564463c06ffa | 37 | for(i = 64; i < 128; i++) { |
| FatCookies | 3:564463c06ffa | 38 | curr_right = (int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF; |
| FatCookies | 3:564463c06ffa | 39 | if(curr_right < CAM_THRESHOLD) { |
| FatCookies | 3:564463c06ffa | 40 | right = i; |
| FatCookies | 3:564463c06ffa | 41 | break; |
| FatCookies | 3:564463c06ffa | 42 | } |
| FatCookies | 3:564463c06ffa | 43 | } |
| FatCookies | 3:564463c06ffa | 44 | |
| FatCookies | 3:564463c06ffa | 45 | pc.putc('H'); |
| FatCookies | 3:564463c06ffa | 46 | for(i = 0; i < 128; i++) { |
| FatCookies | 3:564463c06ffa | 47 | pc.putc((int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF); |
| FatCookies | 3:564463c06ffa | 48 | } |
| FatCookies | 3:564463c06ffa | 49 | |
| FatCookies | 3:564463c06ffa | 50 | measured_value = (64 - ((left+right)/2))/64.f; |
| FatCookies | 3:564463c06ffa | 51 | |
| FatCookies | 3:564463c06ffa | 52 | |
| FatCookies | 3:564463c06ffa | 53 | //Reset image ready flag |
| FatCookies | 3:564463c06ffa | 54 | TFC_LineScanImageReady=0; |
| FatCookies | 3:564463c06ffa | 55 | wait(0.05); |
| FatCookies | 3:564463c06ffa | 56 | } |
| maximusismax | 0:566127ca8048 | 57 | } |
| maximusismax | 0:566127ca8048 | 58 | } |