![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Coursework
Diff: main.cpp
- Revision:
- 37:323ec7d23454
- Parent:
- 36:3e975536e8d7
- Child:
- 38:71cfbdd2076d
--- a/main.cpp Tue Feb 01 22:50:27 2022 +0000 +++ b/main.cpp Wed Feb 02 20:55:23 2022 +0000 @@ -15,6 +15,8 @@ #include "string" #include "array" #include <iostream> +#include <numeric> + using namespace std; /** @@ -150,7 +152,7 @@ return false; return true; }*/ -bool areEqual(int arr1[], int arr2[], int n, int m) +bool MatchMade(int arr1[], int arr2[], int n, int m) { // If lengths of array are not equal means // array are not equal @@ -171,6 +173,7 @@ return true; } int main() { + /** *.. Intialise joystick and Lcd @@ -410,6 +413,22 @@ Decide[i]= '='; printf("No Object %c/n",Decide[i]);} } + + for (int i=0; i<5; i++){ + int box[5]= {90,90,90,90,90}; + int isBox[5]; + isBox[i] =abs(Scan1[i]-box[i]); + printf("DeBUGGING isBOX : %i\n", isBox[i]); + if (isBox[i]<=5){ + isBox[i]=0;} +else if (isBox[i]>5){ +isBox[i]=1;} +printf("DeBUGGING isBOX : %i\n", isBox[i]); +int total = accumulate(begin(isBox), end(isBox), 0, plus<int>()); +printf("DEBUGGING total %i\n", total);} + + + /** IF Statement to decide on shape to draw *.. This section of code compares the each array element with the one proceding it and makes a logical decision if higher lower or equal. @@ -1088,19 +1107,7 @@ void buttonY_isr() { g_buttonY_flag = 1; // set flag in ISR - lcd.clear(); - - ///////////////////////////////////////////////// - int arr1[] = { 3, 5, 2, 4, 2 }; - int Wall[] = { 90, 90, 90, 90, 90 }; - int n = sizeof(Scan1) / sizeof(int); - int m = sizeof(Wall) / sizeof(int); - - if (areEqual(arr1, Wall, n, m)) - printf("You are a wall"); - else - printf("Not THis Object"); ////////////////////////////////// - + lcd.clear(); lcd.printString("Button Y Pressed",0,0); lcd.refresh(); // set flag in ISR } @@ -1109,6 +1116,24 @@ { g_buttonStart_flag = 1; // set flag in ISR lcd.clear(); + ///////////////////////////////////////////////// + int arr1[5] ; + /* + * For loop required to assign array values to that of the scan value + */ + for(int i=0; i<5; i++){ + arr1[i] =Scan1[i];} + int arr2[] = { 90, 90, 90, 90, 90 }; + int n = sizeof(arr1) / sizeof(int); + int m = sizeof(arr2) / sizeof(int); + + + if(MatchMade(arr1, arr2, n, m)) + printf("You are a wall"); + else + printf("Not THis Object"); ////////////////////////////////// + + lcd.printString("Button Start Pressed",0,0); lcd.refresh(); // set flag in ISR