Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- int mapX = 50;
- int mapY = 50;
- int mapArray[50][50];
- int pos = 0; // variable to store the servo position
- int currPos;
- const int trigPin = 9;
- const int echoPin = 10;
- bool mapMade;
- long duration;
- int distanceCm;
- //=========================== SETUP ===========================
- void setup() {
- myservo.attach(4); // attaches the servo on pin 9 to the servo object
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- Serial.begin(9600);
- }
- //======================= MAKE WAVEMAP ========================
- void makeMap(){
- if(!mapMade){
- Serial.print("Printing ");
- Serial.print(mapX);
- Serial.print(" x ");
- Serial.print(mapY);
- Serial.println(" map/grid");
- Serial.println("=======================================================================================================");
- Serial.print("int customArray[");
- Serial.print(mapX);
- Serial.print("][");
- Serial.print(mapY);
- Serial.print("] = ");
- Serial.println("{");
- for (int y = 0; y < mapY; y++){ //Takes the first y-axis line
- Serial.print("{");
- for (int x = 0; x < mapX; x++){ //Then print all the entries on the x-axis, REPEAT^
- Serial.print(mapArray[x][y]);
- Serial.print(",");
- }
- Serial.print("},");
- Serial.println();
- }
- Serial.println("};");
- Serial.println("=======================================================================================================");
- Serial.println();
- Serial.println("Here you go.");
- Serial.println("Remember arrays start at 0 ;)");
- mapMade = true;
- }
- }
- //=========================== LOOP ============================
- void loop() {
- makeMap();
- }
- //===================== DISTANCE SENSOR =======================
- void distanceSensor(){
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distanceCm= duration*0.034/2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement