Advertisement
Guest User

arduino testcode 1.5 rohan

a guest
Oct 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C Compiler.
  4. Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdbool.h>
  11.  
  12. int main()
  13. {
  14.  
  15. //GPS declarations
  16. double courseToBeacon = 340.00;
  17.  
  18. double currentDistance = 0.00;
  19.  
  20. double maxDistanceToBeacon = 100.00;
  21.  
  22. double normalizedDistance = currentDistance / maxDistanceToBeacon;
  23. // printf(" start normalizedDistance = %f", normalizedDistance);
  24.  
  25. //semicircle partitions, use a multiple of 2 & n > 6
  26. int n = 6;
  27.  
  28. double westLowerBound = 270.0;
  29. double westUpperBound = 270.0 + (90.0 / n);
  30.  
  31. double northLowerBound = 360.0 - (90.0 / n);
  32. double northUpperBound = 0.0 + (90.0 / n);
  33.  
  34. double eastLowerBound = 90.0 - (90.0 / n);
  35. double eastUpperBound = 90.0;
  36.  
  37. bool isSouth = ((eastUpperBound < courseToBeacon) && (courseToBeacon < westLowerBound));
  38.  
  39. while ((normalizedDistance < 0.95)) {
  40. // printf(" + normalizedDistance 1 = %f", normalizedDistance);
  41. printf(" courseToBeacon 1 = %f", courseToBeacon);
  42. // cardinal directions
  43.  
  44. // 345 < x & x <= 15
  45. bool isNorth = ((northLowerBound < courseToBeacon) || (courseToBeacon <= northUpperBound));
  46.  
  47. // 75 < x & x <= 90
  48. bool isEast = ((eastLowerBound < courseToBeacon) && (courseToBeacon <= eastUpperBound));
  49.  
  50. // 90 < x & x <= 270
  51. bool isSouth = ((eastUpperBound < courseToBeacon) && (courseToBeacon <= westLowerBound));
  52.  
  53. // 270 < x & x <= 285
  54. bool isWest = ((westLowerBound < courseToBeacon) && (courseToBeacon <= westUpperBound));
  55.  
  56. // 285 < x & x < 345
  57. bool isNorthWest = ((westUpperBound < courseToBeacon) && (courseToBeacon <= northLowerBound));
  58.  
  59. // 15 < x & x <= 75
  60. bool isNorthEast = ((northUpperBound < courseToBeacon) && (courseToBeacon <= eastLowerBound));
  61.  
  62.  
  63. if (isWest) {
  64. printf(" + isWest");
  65. }
  66. else if (isEast) {
  67. printf(" + isEast");
  68. }
  69. else if (isNorth) {
  70. printf(" + isNorth");
  71. }
  72. // northwest / northeast
  73. else if (isNorthWest) {
  74. printf(" + isNorthWest");
  75. }
  76. else if (isNorthEast) {
  77. printf(" + isNorthEast");
  78. } else {
  79. printf(" + wrong");
  80. }
  81.  
  82.  
  83. // testing if currentDistance updates
  84. currentDistance += 100.0;
  85. // printf(" + currentDistance = %f", currentDistance);
  86.  
  87. // testing if courseToBeacon updates
  88. courseToBeacon += 15.0;
  89. printf(" + courseToBeacon2 = %f", courseToBeacon);
  90.  
  91. // get new normalized Distance
  92. normalizedDistance = currentDistance / maxDistanceToBeacon;
  93. // printf(" + normalizedDistance = %f + end + .", normalizedDistance);
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement