commit 7e67dcb0a0c25343767f7ec86450d73b4a6f91cd Author: Phillip Kühne Date: Thu Jun 21 16:01:21 2018 +0200 Hindernisvermeidung funktioniert diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9443843 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..434a029 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:uno] +platform = atmelavr +board = uno +lib_deps = + 1507 +framework = arduino diff --git a/platformio.sublime-project b/platformio.sublime-project new file mode 100644 index 0000000..b22daa6 --- /dev/null +++ b/platformio.sublime-project @@ -0,0 +1,104 @@ +{ + "build_systems": + [ + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "run" + ], + "name": "PlatformIO", + "variants": + [ + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "run" + ], + "name": "Build" + }, + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "run", + "--target", + "clean" + ], + "name": "Clean" + }, + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "test" + ], + "name": "Test" + }, + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "run", + "--target", + "upload" + ], + "name": "Upload" + }, + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "run", + "--target", + "program" + ], + "name": "Upload using Programmer" + }, + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "run", + "--target", + "uploadfs" + ], + "name": "Upload SPIFFS image" + }, + { + "cmd": + [ + "platformio", + "-f", "-c", "sublimetext", + "update" + ], + "name": "Update platforms and libraries" + } + ], + "working_dir": "${project_path:${folder}}", + "selector": "source.c, source.c++", + "path": "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" + } + ], + "folders": + [ + { + "path": "." + } + ], + "settings": + { + "sublimegdb_workingdir": "/home/phillipk/Code/Robotik", + "sublimegdb_exec_cmd": "-exec-continue", + "sublimegdb_commandline": "/usr/bin/platformio -f -c sublimetext debug --interface=gdb --interpreter=mi -x .pioinit" + + } +} diff --git a/platformio.sublime-workspace b/platformio.sublime-workspace new file mode 100644 index 0000000..02ba463 --- /dev/null +++ b/platformio.sublime-workspace @@ -0,0 +1,1727 @@ +{ + "auto_complete": + { + "selected_items": + [ + [ + "dis", + "distance\tint distance" + ], + [ + "loo", + "lookLeft\tint lookLeft()" + ], + [ + "ul", + "ultrasonic\tint ultrasonic(int A2, int)" + ], + [ + "set", + "setServo\tvoid setServo(int degrees)" + ], + [ + "de", + "degrees\tint degrees" + ], + [ + "Pi", + "PIN_IN1\tconst int PIN_IN1" + ], + [ + "Se", + "SERVO_PIN\tconst int SERVO_PIN" + ], + [ + "PIN", + "PIN_IN2\tconst int PIN_IN2" + ], + [ + "PIn", + "PIN_IN3\tconst int PIN_IN3" + ], + [ + "PI", + "PIN_IN4" + ], + [ + "p", + "println" + ], + [ + "P", + "PIN_IN4" + ], + [ + "di", + "digitalWrite" + ], + [ + "at", + "attributes" + ], + [ + "fun", + "function" + ], + [ + "mem", + "members" + ], + [ + "int", + "intval" + ], + [ + "json", + "json_encode" + ], + [ + "js", + "json_encode" + ], + [ + "fir", + "first" + ], + [ + "fi", + "first" + ], + [ + "first", + "firstlat" + ], + [ + "tes", + "testJson" + ], + [ + "o", + "overpassOutput" + ], + [ + "for", + "foreach\tforeach …" + ], + [ + "col-3", + "col-3 \tBootstrap 4 Class" + ], + [ + "back", + "background-color" + ], + [ + "nav", + "navbar-brand \tBootstrap 4 Class" + ], + [ + "navb", + "navbar-light \tBootstrap 4 Class" + ], + [ + "l", + "li\tTag" + ], + [ + "cont", + "container-fluid \tBootstrap 4 Class" + ], + [ + "in", + "include" + ], + [ + "cm", + "composer" + ] + ] + }, + "buffers": + [ + { + "file": "platformio.ini", + "settings": + { + "buffer_size": 444, + "encoding": "UTF-8", + "line_ending": "Unix" + } + }, + { + "file": "src/main.cpp", + "settings": + { + "buffer_size": 4700, + "encoding": "UTF-8", + "line_ending": "Unix" + } + }, + { + "file": ".piolibdeps/Ultrasonic_ID1507/README.md", + "settings": + { + "buffer_size": 4822, + "encoding": "UTF-8", + "line_ending": "Unix" + } + }, + { + "file": ".piolibdeps/Ultrasonic_ID1507/src/Ultrasonic.h", + "settings": + { + "buffer_size": 1047, + "encoding": "UTF-8", + "line_ending": "Unix" + } + }, + { + "file": ".piolibdeps/Adafruit SSD1306_ID135/Adafruit_SSD1306.h", + "settings": + { + "buffer_size": 5771, + "encoding": "UTF-8", + "line_ending": "Unix" + } + }, + { + "contents": "# Arduino library for HC-SR04 ultrasonic distance sensor.\n\nHC-SR04 is an ultrasonic sensor that measures distances from 2 to 400cm.\n\n![HC-SR04](/hcsr04.jpg)\n\nThis is a simple library for it!\n\n## Usage\nSensor is initialized by creating instance of class UltraSonicDistanceSensor and providing trigger and echo pins:\n`UltraSonicDistanceSensor sensor(triggerPin, echoPin);`.\n\nThen, to measure the distance, you just call `measureDistanceCm()`, which will return distance in centimeters (double). If distance is larger than 400cm, it will return negative value.\n\n\n## Example\n\nIn this simple example, we need to connect sensors pins like this:\n\n- vcc to 5V\n- trig to digital pin 13\n- echo to digital pin 12\n- gnd to gnd\n\n```\n#include \n\n// Initialize sensor that uses digital pins 13 and 12.\nint triggerPin = 13;\nint echoPin = 12;\nUltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);\n\nvoid setup () {\n Serial.begin(9600); // We initialize serial connection so that we could print values from sensor.\n}\n\nvoid loop () {\n // Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters.\n double distance = distanceSensor.measureDistanceCm()\n Serial.println(distance);\n delay(500);\n}\n```\n", + "file": ".piolibdeps/HCSR04_ID2968/README.md", + "file_size": 1247, + "file_write_time": 131631654060000000, + "settings": + { + "buffer_size": 1247, + "line_ending": "Unix" + } + } + ], + "build_system": "", + "build_system_choices": + [ + ], + "build_varint": "", + "command_palette": + { + "height": 221.0, + "last_filter": "", + "selected_items": + [ + [ + "Pretty", + "Pretty JSON: Format (Pretty Print) JSON" + ], + [ + "Install ", + "Package Control: Install Package" + ], + [ + "Insta", + "Package Control: Install Package" + ], + [ + "Instal", + "Package Control: Install Package" + ], + [ + "Disco", + "Package Control: Discover Packages" + ], + [ + "Inst", + "Package Control: Install Package" + ], + [ + "Prett", + "Pretty JSON: Validate" + ], + [ + "Pa", + "Package Control: Discover Packages" + ], + [ + "Pret", + "Pretty JSON: Format and Sort JSON" + ], + [ + "Pre", + "Pretty JSON: Validate" + ], + [ + "JSON", + "Set Syntax: JSON" + ], + [ + "Onst", + "Set Syntax: ActionScript" + ], + [ + "Lint ", + "SublimeLinter: Lint This View" + ], + [ + "Lint", + "SublimeLinter: Toggle Highlights" + ], + [ + "Ter", + "Terminal: Open" + ], + [ + "Install", + "Package Control: Install Package" + ], + [ + "Browse", + "View In Browser" + ], + [ + "Remove ", + "Package Control: Remove Package" + ], + [ + "Termin", + "Terminal: Open" + ], + [ + "Packa", + "Package Control: Discover Packages" + ], + [ + "Browser", + "View In Browser" + ], + [ + "Package", + "Package Control: List Packages" + ], + [ + "inst", + "Package Control: Install Package" + ], + [ + "View", + "View In Browser" + ], + [ + "Pack", + "Package Control: Install Package" + ], + [ + "Brwo", + "View In Browser" + ], + [ + "View in", + "View In Browser" + ], + [ + "Brwser", + "Browser Integration: Launch Browser" + ] + ], + "width": 413.0 + }, + "console": + { + "height": 143.0, + "history": + [ + "import urllib.request,os,hashlib; h = '6f4c264a24d933ce70df5dedcf1dcaee' + 'ebe013ee18cced0ef93d5f746d80ef60'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)" + ] + }, + "distraction_free": + { + "menu_visible": true, + "show_minimap": false, + "show_open_files": false, + "show_tabs": false, + "side_bar_visible": false, + "status_bar_visible": false + }, + "expanded_folders": + [ + "/home/phillipk/Code/Robotik", + "/home/phillipk/Code/Robotik/.piolibdeps", + "/home/phillipk/Code/Robotik/.piolibdeps/Ultrasonic_ID1507", + "/home/phillipk/Code/Robotik/.piolibdeps/Ultrasonic_ID1507/src", + "/home/phillipk/Code/Robotik/src" + ], + "file_history": + [ + "/tmp/out.json", + "/home/phillipk/Code/Robotik/src/bmesafix.sh", + "/tmp/CEFSourceIrPB9s.txt", + "/home/phillipk/Arduino/libraries/HCSR04_ultrasonic_sensor/src/HCSR04.cpp", + "/home/phillipk/Code/Robotik/portmappings.md", + "/home/phillipk/Code/Robotik/src/main.cpp", + "/home/phillipk/.zshrc", + "/home/phillipk/Code/Robotik/src/main.c", + "/home/phillipk/Code/Robotik/lib/readme.txt", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/20-1.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/20-2.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/20-3.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Aufgaben/KW21/3.hs", + "/tmp/geo.json", + "/home/phillipk/Downloads/interpreter (4)", + "/home/phillipk/Code/phptest/data2.php", + "/home/phillipk/Code/phptest/data.php", + "/home/phillipk/Code/phptest/vendor/mediasuitenz/overpass2geojson/lib/Overpass2Geojson.php", + "/home/phillipk/Downloads/interpreter (1)", + "/home/phillipk/Downloads/dietpi.log", + "/run/user/1000/gvfs/sftp:host=phillipathome.dynv6.net,user=root/mnt/dietpi_userdata/gitea/custom/conf/app.ini", + "/home/phillipk/.cache/.fr-NViqgV/Read Me !.txt", + "/tmp/nl.html", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_docker/cityfix_api/Dockerfile", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/19-1.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/19-2.hs", + "/home/phillipk/.local/share/Steam/steamapps/common/World of Goo/docs/linux-issues.txt", + "/home/phillipk/.WorldOfGoo/config.txt", + "/home/phillipk/.local/share/Steam/steamapps/common/World of Goo/properties/config.txt", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Haskell/1405a.hs", + "/home/phillipk/.config/sublime-text-3/Packages/User/Preferences.sublime-settings", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/19-0.hs", + "/home/phillipk/Downloads/interpreter", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Multimediale Webprogrammierung/mmwp_Sem04/Eigen/style.css", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Multimediale Webprogrammierung/mmwp_Sem04/Eigen/index.html", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Multimediale Webprogrammierung/mmwp_Sem04/bootstrap-4.1.0-dist/Einzufügende_Zeilen.txt", + "/home/phillipk/.config/sublime-text-3/Packages/User/Emmet.sublime-settings", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Multimediale Webprogrammierung/mmwp_Sem04/0. Ausgangsdatei/Default_Starter_HTML5.html", + "/home/phillipk/Arduino/libraries/Servo8Bit/Servo8Bit.cpp", + "/home/phillipk/Arduino/libraries/Servo8Bit/Servo8Bit.h", + "/home/phillipk/Arduino/libraries/Servo8Bit/Readme.txt", + "/home/phillipk/Arduino/libraries/Servo/src/avr/Servo.cpp", + "/home/phillipk/Arduino/libraries/Servo8Bit/example.cpp", + "/home/phillipk/Arduino/libraries/Servo/src/Servo.h", + "/home/phillipk/Arduino/libraries/Servo8Bit/Makefile", + "/home/phillipk/Arduino/libraries/Servo/src/avr/ServoTimers.h", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_docker/docker-compose.prod.yml", + "/home/phillipk/Code/Softwareprojekt/Cityfix/.gitlab-ci.yml", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Aufgaben/Serie 2/Main.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Aufgaben/Serie 2/15-1.hs", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_docker/cityfix_apache_prod/Dockerfile", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Aufgaben/Serie 2/15-2.hs", + "/home/phillipk/Arduino/libraries/readme.txt", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_frontend/frontend/package.json", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_frontend/frontend/package-lock.json", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_frontend/frontend/.gitignore", + "/home/phillipk/Downloads/samplecat/PKGBUILD", + "/home/phillipk/Downloads/samplecat-0.2.4/INSTALL", + "/home/phillipk/Downloads/Main.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/15-1.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/15-2.hs", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Fortgeschrittene Programmierung/Autotool/Interpretation.hs", + "/tmp/tmp.hs", + "/tmp/temp.hs", + "/home/phillipk/.config/sublime-text-3/Packages/BrowserIntegration/BrowserIntegration.sublime-settings", + "/home/phillipk/.config/sublime-text-3/Packages/User/Default (Linux).sublime-keymap", + "/home/phillipk/Downloads/dmesg", + "/home/phillipk/Dokumente/HTWK/Materialien/SoSe 18/Multimediale Webprogrammierung/mmwp_Sem01/Muster_minimal.html", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_docker/cityfix_frontend/Dockerfile", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_docker/cityfix_apache/Dockerfile", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_api/composer.json", + "/home/phillipk/Code/Softwareprojekt/Cityfix/code/cityfix_docker/docker-compose.yml", + "/home/phillipk/Downloads/SuperEven.vcv", + "/home/phillipk/Downloads/dmesg-card-present-during-boot", + "/home/phillipk/.config/sublime-text-3/Packages/View In Browser/View In Browser.sublime-settings" + ], + "find": + { + "height": 26.0 + }, + "find_in_files": + { + "height": 101.0, + "where_history": + [ + ] + }, + "find_state": + { + "case_sensitive": false, + "find_history": + [ + "serial", + "ntfernung", + "(PIN_IN1, OUTPUT);\n pinMode (PIN_IN2, OUTPUT);\n pinMode (PIN_IN3, OUTPUT);\n pinMode ", + "50" + ], + "highlight": true, + "in_selection": false, + "preserve_case": false, + "regex": false, + "replace_history": + [ + ], + "reverse": false, + "show_context": true, + "use_buffer2": true, + "whole_word": false, + "wrap": true + }, + "groups": + [ + { + "selected": 1, + "sheets": + [ + { + "buffer": 0, + "file": "platformio.ini", + "semi_transient": false, + "settings": + { + "buffer_size": 444, + "regions": + { + }, + "selection": + [ + [ + 443, + 443 + ] + ], + "settings": + { + "SL.13.region_keys": + [ + ], + "SL.14.region_keys": + [ + ], + "bracket_highlighter.busy": false, + "bracket_highlighter.clone": -1, + "bracket_highlighter.clone_locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + } + }, + "bracket_highlighter.clone_regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content" + ], + "bracket_highlighter.locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + } + }, + "bracket_highlighter.regions": + [ + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content" + ], + "syntax": "Packages/Text/Plain text.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "stack_index": 1, + "type": "text" + }, + { + "buffer": 1, + "file": "src/main.cpp", + "semi_transient": false, + "settings": + { + "buffer_size": 4700, + "regions": + { + }, + "selection": + [ + [ + 4476, + 4476 + ] + ], + "settings": + { + "SL.14.region_keys": + [ + ], + "SL.30.region_keys": + [ + ], + "bracket_highlighter.busy": false, + "bracket_highlighter.clone": -1, + "bracket_highlighter.clone_locations": + { + "close": + { + "1": + [ + 3802, + 3803 + ] + }, + "icon": + { + "1": + [ + "Packages/BracketHighlighter/icons/round_bracket.png", + "region.yellowish" + ] + }, + "open": + { + "1": + [ + 3796, + 3797 + ] + }, + "unmatched": + { + } + }, + "bracket_highlighter.clone_regions": + [ + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content" + ], + "bracket_highlighter.locations": + { + "close": + { + "1": + [ + 4477, + 4478 + ] + }, + "icon": + { + "1": + [ + "Packages/BracketHighlighter/icons/round_bracket.png", + "region.yellowish" + ] + }, + "open": + { + "1": + [ + 4470, + 4471 + ] + }, + "unmatched": + { + } + }, + "bracket_highlighter.regions": + [ + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content" + ], + "syntax": "Packages/C++/C++.sublime-syntax", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 2358.0, + "zoom_level": 1.0 + }, + "stack_index": 0, + "type": "text" + }, + { + "buffer": 2, + "file": ".piolibdeps/Ultrasonic_ID1507/README.md", + "semi_transient": false, + "settings": + { + "buffer_size": 4822, + "regions": + { + }, + "selection": + [ + [ + 0, + 0 + ] + ], + "settings": + { + "SL.15.region_keys": + [ + ], + "bracket_highlighter.busy": false, + "bracket_highlighter.clone": -1, + "bracket_highlighter.clone_locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + "1": + [ + 118, + 119 + ] + } + }, + "bracket_highlighter.clone_regions": + [ + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content" + ], + "bracket_highlighter.locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + "1": + [ + 118, + 119 + ] + } + }, + "bracket_highlighter.regions": + [ + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content" + ], + "markdonw_live_preview_last_run": 1527691830.38, + "syntax": "Packages/Markdown/Markdown.sublime-syntax", + "tab_size": 4, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 272.0, + "zoom_level": 1.0 + }, + "stack_index": 2, + "type": "text" + }, + { + "buffer": 3, + "file": ".piolibdeps/Ultrasonic_ID1507/src/Ultrasonic.h", + "semi_transient": false, + "settings": + { + "buffer_size": 1047, + "regions": + { + }, + "selection": + [ + [ + 965, + 965 + ] + ], + "settings": + { + "SL.16.region_keys": + [ + ], + "bracket_highlighter.busy": false, + "bracket_highlighter.clone": -1, + "bracket_highlighter.clone_locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + } + }, + "bracket_highlighter.clone_regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content" + ], + "bracket_highlighter.locations": + { + "close": + { + "1": + [ + 1020, + 1021 + ] + }, + "icon": + { + "1": + [ + "Packages/BracketHighlighter/icons/curly_bracket.png", + "region.purplish" + ] + }, + "open": + { + "1": + [ + 587, + 588 + ] + }, + "unmatched": + { + } + }, + "bracket_highlighter.regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content" + ], + "markdonw_live_preview_last_run": 1527691868.49, + "syntax": "Packages/C++/C++.sublime-syntax", + "tab_size": 4, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "stack_index": 3, + "type": "text" + }, + { + "buffer": 4, + "file": ".piolibdeps/Adafruit SSD1306_ID135/Adafruit_SSD1306.h", + "semi_transient": false, + "settings": + { + "buffer_size": 5771, + "regions": + { + }, + "selection": + [ + [ + 2074, + 2074 + ] + ], + "settings": + { + "SL.17.region_keys": + [ + ], + "SL.18.region_keys": + [ + ], + "SL.58.region_keys": + [ + ], + "bracket_highlighter.busy": false, + "bracket_highlighter.clone": -1, + "bracket_highlighter.clone_locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + "1": + [ + 725, + 731 + ] + } + }, + "bracket_highlighter.clone_regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content" + ], + "bracket_highlighter.locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + "1": + [ + 725, + 731 + ] + } + }, + "bracket_highlighter.regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content" + ], + "markdonw_live_preview_last_run": 1527687111.77, + "syntax": "Packages/C++/C++.sublime-syntax", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 1071.0, + "zoom_level": 1.0 + }, + "stack_index": 4, + "type": "text" + }, + { + "buffer": 5, + "file": ".piolibdeps/HCSR04_ID2968/README.md", + "semi_transient": false, + "settings": + { + "buffer_size": 1247, + "regions": + { + }, + "selection": + [ + [ + 0, + 0 + ] + ], + "settings": + { + "SL.18.region_keys": + [ + ], + "SL.19.region_keys": + [ + ], + "bracket_highlighter.busy": false, + "bracket_highlighter.clone": -1, + "bracket_highlighter.clone_locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + } + }, + "bracket_highlighter.clone_regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content" + ], + "bracket_highlighter.locations": + { + "close": + { + }, + "icon": + { + }, + "open": + { + }, + "unmatched": + { + } + }, + "bracket_highlighter.regions": + [ + "bh_c_define", + "bh_c_define_center", + "bh_c_define_open", + "bh_c_define_close", + "bh_c_define_content", + "bh_square", + "bh_square_center", + "bh_square_open", + "bh_square_close", + "bh_square_content", + "bh_single_quote", + "bh_single_quote_center", + "bh_single_quote_open", + "bh_single_quote_close", + "bh_single_quote_content", + "bh_curly", + "bh_curly_center", + "bh_curly_open", + "bh_curly_close", + "bh_curly_content", + "bh_unmatched", + "bh_unmatched_center", + "bh_unmatched_open", + "bh_unmatched_close", + "bh_unmatched_content", + "bh_double_quote", + "bh_double_quote_center", + "bh_double_quote_open", + "bh_double_quote_close", + "bh_double_quote_content", + "bh_tag", + "bh_tag_center", + "bh_tag_open", + "bh_tag_close", + "bh_tag_content", + "bh_default", + "bh_default_center", + "bh_default_open", + "bh_default_close", + "bh_default_content", + "bh_round", + "bh_round_center", + "bh_round_open", + "bh_round_close", + "bh_round_content", + "bh_regex", + "bh_regex_center", + "bh_regex_open", + "bh_regex_close", + "bh_regex_content", + "bh_angle", + "bh_angle_center", + "bh_angle_open", + "bh_angle_close", + "bh_angle_content" + ], + "markdonw_live_preview_last_run": 1527685993.81, + "syntax": "Packages/Markdown/Markdown.sublime-syntax" + }, + "translation.x": 0.0, + "translation.y": 204.0, + "zoom_level": 1.0 + }, + "stack_index": 5, + "type": "text" + } + ] + } + ], + "incremental_find": + { + "height": 26.0 + }, + "input": + { + "height": 40.0 + }, + "layout": + { + "cells": + [ + [ + 0, + 0, + 1, + 1 + ] + ], + "cols": + [ + 0.0, + 1.0 + ], + "rows": + [ + 0.0, + 1.0 + ] + }, + "menu_visible": true, + "output.SublimeLinter": + { + "height": 0.0 + }, + "output.find_results": + { + "height": 0.0 + }, + "output.mdpopups": + { + "height": 0.0 + }, + "pinned_build_system": "", + "project": "platformio.sublime-project", + "replace": + { + "height": 48.0 + }, + "save_all_on_build": true, + "select_file": + { + "height": 0.0, + "last_filter": "", + "selected_items": + [ + ], + "width": 0.0 + }, + "select_project": + { + "height": 0.0, + "last_filter": "", + "selected_items": + [ + ], + "width": 0.0 + }, + "select_symbol": + { + "height": 0.0, + "last_filter": "", + "selected_items": + [ + ], + "width": 0.0 + }, + "selected_group": 0, + "settings": + { + }, + "show_minimap": true, + "show_open_files": false, + "show_tabs": true, + "side_bar_visible": true, + "side_bar_width": 237.0, + "status_bar_visible": true, + "template_settings": + { + } +} diff --git a/portmappings.md b/portmappings.md new file mode 100644 index 0000000..348c200 --- /dev/null +++ b/portmappings.md @@ -0,0 +1,10 @@ +## Mappings + +**PWM ist rückwärts invertiert** + +| Pin | Bedeutung | +|-----|-----| +|PIN_IN1| PWM Motor rechts | +|PIN_IN2| Richtung Motor Rechts (LOW: Vorwärts, HIGH: Rückwärts)| +|PIN_IN3| PWM Motor Links | +|PIN_IN2| Richtung Motor Rechts (LOW: Vorwärts, HIGH: Rückwärts)| \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..1ed37ce --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,199 @@ +#include +#include + +//// Adafruit Display +#include +#include +#include +#include + +#define OLED_RESET 4 +Adafruit_SSD1306 display(OLED_RESET); +#define NUMFLAKES 10 +#define XPOS 0 +#define YPOS 1 +#define DELTAY 2 + +#if (SSD1306_LCDHEIGHT != 64) +#error("Height incorrect, please fix Adafruit_SSD1306.h!"); +#endif + +const int PIN_ENA = 0; +const int PIN_ENB = 1; +const int PIN_IN1 = 3; +const int PIN_IN2 = 5; +const int PIN_IN3 = 9; +const int PIN_IN4 = 10; + +const int SERVO_PIN = 7; + +Ultrasonic ultrasonic(A2,A3); +int distance = 21; + + +// put your setup code here, to run once: + +void setup() { + Serial.begin(9600); + pinMode(PIN_ENA,OUTPUT); + pinMode(PIN_ENB, OUTPUT); + pinMode(PIN_IN1, OUTPUT); + pinMode(PIN_IN2, OUTPUT); + pinMode(PIN_IN3, OUTPUT); + pinMode(PIN_IN4, OUTPUT); + pinMode(SERVO_PIN, OUTPUT); + digitalWrite(PIN_ENA, HIGH); + digitalWrite(PIN_ENB, HIGH); + + // Display Initialisieren + display.begin(SSD1306_SWITCHCAPVCC, 0x3C); + display.clearDisplay(); + display.setTextSize(2); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println("2WD China Bots"); + //display.setTextSize(3); + display.println("HTWK-"); + display.setTextSize(2); + display.println("Leipzig"); + display.display(); +} +/** + * @param leftMotor -255 bis 255, Stärke + * @param rightMotor -255 bis 255, Stärke + */ +void setMotors(int leftMotor, int rightMotor) { + if (rightMotor>=0) + { + analogWrite(PIN_IN2, rightMotor); + digitalWrite(PIN_IN1, LOW); + } else { + analogWrite(PIN_IN2, rightMotor); + digitalWrite(PIN_IN1, HIGH); + } + + if (leftMotor>=0) + { + analogWrite(PIN_IN4, leftMotor); + digitalWrite(PIN_IN3, LOW); + } else { + analogWrite(PIN_IN4, leftMotor); + digitalWrite(PIN_IN3, HIGH); + } +} + +void stopMotors() { + digitalWrite(PIN_IN1,LOW); + digitalWrite(PIN_IN2,LOW); + digitalWrite(PIN_IN3,LOW); + digitalWrite(PIN_IN4,LOW); + digitalWrite(PIN_ENA,LOW); + digitalWrite(PIN_ENB,LOW); +} + +void enableHigh() { + digitalWrite(PIN_ENA,HIGH); + digitalWrite(PIN_ENB,HIGH); +} + +void setServo(int degrees) { + int lenMicroSecondsOfPulse = (float) degrees/ 90.0 * 1000 + 300; + int lenMicroSecondsOfPeriod = 20 * 1000; // 20 milliseconds (ms) + for (int i = 0; i < 200; ++i) { + digitalWrite(SERVO_PIN, HIGH); + // Delay for the length of the pulse + delayMicroseconds(lenMicroSecondsOfPulse); + + // Turn the voltage low for the remainder of the pulse + digitalWrite(SERVO_PIN, LOW); + + // Delay this loop for the remainder of the period so we don't + // send the next signal too soon or too late + delayMicroseconds(lenMicroSecondsOfPeriod - lenMicroSecondsOfPulse); + + } + +} + +int lookLeft(){ + setServo(180); + delay(1000); + return ultrasonic.distanceRead(); +} + +int lookRight(){ + setServo(0); + delay(1000); + return ultrasonic.distanceRead(); +} + + +void loop() { + enableHigh(); + setServo(90); + distance = ultrasonic.distanceRead(); + display.clearDisplay(); + display.setTextSize(2); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println("Abstand: "); + display.setTextSize(3); + display.print(distance); + display.setTextSize(2); + display.println(" cm"); + display.display(); + Serial.println(distance); + if (distance<30 && distance>0) { + setMotors(0, 0); + if(lookLeft()>lookRight()){ + setServo(90); + while(distance<50) { + distance = ultrasonic.distanceRead(); + display.clearDisplay(); + display.setTextSize(2); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println("Abstand (turning left): "); + display.setTextSize(3); + display.print(distance); + display.setTextSize(2); + display.println(" cm"); + display.display(); + Serial.println("Turning left: "); + Serial.println(distance); + setMotors(-120,0); + delay(10); + } + delay(500); + } else { + setServo(90); + while(distance<50) { + distance = ultrasonic.distanceRead(); + display.clearDisplay(); + display.setTextSize(2); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println("Abstand (turning right): "); + display.setTextSize(3); + display.print(distance); + display.setTextSize(2); + display.println(" cm"); + display.display(); + Serial.println("Turning right: "); + Serial.println(distance); + setMotors(0,-120); + delay(10); + } + delay(500); + } + + } else { + if((distance>215)||(distance<=0)){ + setMotors(255, 255); + } else { + setMotors(distance+70, distance+70); + } + } + delay(10); + +} \ No newline at end of file