Advertisement
Guest User

MakeMatrixMap

a guest
Mar 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo; // create servo object to control a servo
  4.  
  5. int mapX = 50;
  6. int mapY = 50;
  7. int mapArray[50][50];
  8. int pos = 0; // variable to store the servo position
  9. int currPos;
  10. const int trigPin = 9;
  11. const int echoPin = 10;
  12.  
  13. bool mapMade;
  14.  
  15. long duration;
  16. int distanceCm;
  17.  
  18. //=========================== SETUP ===========================
  19.  
  20. void setup() {
  21. myservo.attach(4); // attaches the servo on pin 9 to the servo object
  22.  
  23. pinMode(trigPin, OUTPUT);
  24. pinMode(echoPin, INPUT);
  25.  
  26. Serial.begin(9600);
  27.  
  28.  
  29. }
  30.  
  31.  
  32. //======================= MAKE WAVEMAP ========================
  33. void makeMap(){
  34.  
  35. if(!mapMade){
  36. Serial.print("Printing ");
  37. Serial.print(mapX);
  38. Serial.print(" x ");
  39. Serial.print(mapY);
  40. Serial.println(" map/grid");
  41. Serial.println("=======================================================================================================");
  42. Serial.print("int customArray[");
  43. Serial.print(mapX);
  44. Serial.print("][");
  45. Serial.print(mapY);
  46. Serial.print("] = ");
  47. Serial.println("{");
  48. for (int y = 0; y < mapY; y++){ //Takes the first y-axis line
  49. Serial.print("{");
  50. for (int x = 0; x < mapX; x++){ //Then print all the entries on the x-axis, REPEAT^
  51. Serial.print(mapArray[x][y]);
  52. Serial.print(",");
  53. }
  54. Serial.print("},");
  55. Serial.println();
  56. }
  57. Serial.println("};");
  58. Serial.println("=======================================================================================================");
  59. Serial.println();
  60. Serial.println("Here you go.");
  61. Serial.println("Remember arrays start at 0 ;)");
  62. mapMade = true;
  63. }
  64. }
  65.  
  66. //=========================== LOOP ============================
  67. void loop() {
  68. makeMap();
  69. }
  70. //===================== DISTANCE SENSOR =======================
  71. void distanceSensor(){
  72. digitalWrite(trigPin, LOW);
  73. delayMicroseconds(2);
  74. digitalWrite(trigPin, HIGH);
  75. delayMicroseconds(10);
  76. digitalWrite(trigPin, LOW);
  77. duration = pulseIn(echoPin, HIGH);
  78. distanceCm= duration*0.034/2;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement