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.
Dependencies: mbed
main.cpp@1:044238f7bdda, 2019-02-22 (annotated)
- Committer:
- el17cd
- Date:
- Fri Feb 22 12:57:19 2019 +0000
- Revision:
- 1:044238f7bdda
- Parent:
- 0:efb5eec6b8ea
- Child:
- 2:a5bc7b3779f7
Face class implemented, creating rasturizator class
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17cd | 0:efb5eec6b8ea | 1 | /* |
| el17cd | 0:efb5eec6b8ea | 2 | ELEC2645 Embedded Systems Project |
| el17cd | 0:efb5eec6b8ea | 3 | School of Electronic & Electrical Engineering |
| el17cd | 0:efb5eec6b8ea | 4 | University of Leeds |
| el17cd | 0:efb5eec6b8ea | 5 | Name: Christopher Doel |
| el17cd | 0:efb5eec6b8ea | 6 | Username: el17cd |
| el17cd | 0:efb5eec6b8ea | 7 | Student ID Number: 201146223 |
| el17cd | 0:efb5eec6b8ea | 8 | Date: 22/02/19 |
| el17cd | 0:efb5eec6b8ea | 9 | */ |
| el17cd | 0:efb5eec6b8ea | 10 | |
| el17cd | 0:efb5eec6b8ea | 11 | #include "mbed.h" |
| el17cd | 1:044238f7bdda | 12 | #include "N5110.h" |
| el17cd | 1:044238f7bdda | 13 | #include <vector> |
| el17cd | 1:044238f7bdda | 14 | |
| el17cd | 1:044238f7bdda | 15 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17cd | 0:efb5eec6b8ea | 16 | |
| el17cd | 0:efb5eec6b8ea | 17 | int main() |
| el17cd | 0:efb5eec6b8ea | 18 | { |
| el17cd | 1:044238f7bdda | 19 | lcd.init(); |
| el17cd | 1:044238f7bdda | 20 | |
| el17cd | 1:044238f7bdda | 21 | while(1) { |
| el17cd | 1:044238f7bdda | 22 | lcd.clear(); |
| el17cd | 1:044238f7bdda | 23 | for(int i = 0; i<5; i++){ |
| el17cd | 1:044238f7bdda | 24 | float points[4][2] = {{rand()%20,rand()%20},{20+rand()%20, rand()%20}, {20+rand()%20,20+rand()%20}, {rand()%20,20+rand()%20}}; |
| el17cd | 1:044238f7bdda | 25 | |
| el17cd | 1:044238f7bdda | 26 | float length = sqrt(pow((double)(points[0][0]-points[1][0]),2.0) + pow((double)(points[0][1]-points[1][1]),2)); |
| el17cd | 1:044238f7bdda | 27 | float length1 = sqrt(pow((double)(points[2][0]-points[3][0]),2.0) + pow((double)(points[2][1]-points[3][1]),2)); |
| el17cd | 1:044238f7bdda | 28 | |
| el17cd | 1:044238f7bdda | 29 | int diffX1 = points[0][0]-points[1][0]; |
| el17cd | 1:044238f7bdda | 30 | int diffY1 = points[0][1]-points[1][1]; |
| el17cd | 1:044238f7bdda | 31 | int diffX2 = points[2][0]-points[3][0]; |
| el17cd | 1:044238f7bdda | 32 | int diffY2 = points[2][1]-points[3][1]; |
| el17cd | 1:044238f7bdda | 33 | |
| el17cd | 1:044238f7bdda | 34 | if (abs(diffX1) > abs(diffX2)){ |
| el17cd | 1:044238f7bdda | 35 | |
| el17cd | 1:044238f7bdda | 36 | float step = (float)diffY1/(float)diffX1; |
| el17cd | 1:044238f7bdda | 37 | float stepSmall1 = (float)diffX2/(float)diffX1; |
| el17cd | 1:044238f7bdda | 38 | float stepSmall2 = (float)diffY2/(float)diffX1; |
| el17cd | 1:044238f7bdda | 39 | lcd.printString("top",0,0); |
| el17cd | 1:044238f7bdda | 40 | for(int s = 0; s<= abs(diffX1)-1; s++){ |
| el17cd | 1:044238f7bdda | 41 | lcd.drawLine(points[0][0]+s, rint(points[0][1]+step*s), rint(points[3][0]-stepSmall1*s), rint(points[3][1]-stepSmall2*s), 0); |
| el17cd | 1:044238f7bdda | 42 | lcd.drawLine(points[0][0]+s+1, rint(points[0][1]+step*s), rint(points[3][0]-stepSmall1*s-1), rint(points[3][1]-stepSmall2*s), 0); |
| el17cd | 1:044238f7bdda | 43 | } |
| el17cd | 1:044238f7bdda | 44 | lcd.printString("a",10,0); |
| el17cd | 1:044238f7bdda | 45 | } |
| el17cd | 1:044238f7bdda | 46 | else{ |
| el17cd | 1:044238f7bdda | 47 | lcd.printString("bottom",0,0); |
| el17cd | 1:044238f7bdda | 48 | float step = (float)diffY2/(float)diffX2; |
| el17cd | 1:044238f7bdda | 49 | float stepSmall1 = (float)diffX1/(float)diffX2; |
| el17cd | 1:044238f7bdda | 50 | float stepSmall2 = (float)diffY1/(float)diffX2; |
| el17cd | 1:044238f7bdda | 51 | |
| el17cd | 1:044238f7bdda | 52 | for(int s = 0; s<= abs(diffX2)-1; s++){ |
| el17cd | 1:044238f7bdda | 53 | lcd.drawLine(points[0][0]-stepSmall1*s, rint(points[0][1]-stepSmall2*s),rint(points[3][0]+s), rint(points[3][1]+step*s), 0); |
| el17cd | 1:044238f7bdda | 54 | lcd.drawLine(points[0][0]-stepSmall1*s-1, rint(points[0][1]-stepSmall2*s),rint(points[3][0]+s+1), rint(points[3][1]+step*s), 0); |
| el17cd | 1:044238f7bdda | 55 | } |
| el17cd | 1:044238f7bdda | 56 | } |
| el17cd | 1:044238f7bdda | 57 | for (int i = 0; i < 3; i++){ |
| el17cd | 1:044238f7bdda | 58 | lcd.drawLine(points[i][0], |
| el17cd | 1:044238f7bdda | 59 | points[i][1], |
| el17cd | 1:044238f7bdda | 60 | points[i+1][0], |
| el17cd | 1:044238f7bdda | 61 | points[i+1][1], |
| el17cd | 1:044238f7bdda | 62 | 1); |
| el17cd | 1:044238f7bdda | 63 | } |
| el17cd | 1:044238f7bdda | 64 | lcd.drawLine(points[0][0], |
| el17cd | 1:044238f7bdda | 65 | points[0][1], |
| el17cd | 1:044238f7bdda | 66 | points[3][0], |
| el17cd | 1:044238f7bdda | 67 | points[3][1], |
| el17cd | 1:044238f7bdda | 68 | 1); |
| el17cd | 1:044238f7bdda | 69 | } |
| el17cd | 1:044238f7bdda | 70 | lcd.refresh(); // refresh the LCD so the pixels appear |
| el17cd | 1:044238f7bdda | 71 | wait_ms(1000/1); // this gives a refresh rate of 10 frames per second |
| el17cd | 0:efb5eec6b8ea | 72 | } |
| el17cd | 0:efb5eec6b8ea | 73 | } |