Skip to content
Snippets Groups Projects
Commit 4caebb79 authored by Adrian Josef Waldvogel's avatar Adrian Josef Waldvogel
Browse files

Übungsprogramm 26 abgeschlossen

parent 7b0f69e2
No related branches found
No related tags found
No related merge requests found
Showing
with 404 additions and 1 deletion
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
{
"C_Cpp_Runner.cCompilerPath": "C:/Users/adria/.platformio/packages/toolchain-atmelavr/bin/avr-gcc.exe",
"C_Cpp_Runner.cppCompilerPath": "C:/Users/adria/.platformio/packages/toolchain-atmelavr/bin/avr-g++.exe",
"C_Cpp_Runner.debuggerPath": "C:/Users/adria/.platformio/packages/toolchain-atmelavr/bin/avr-gdb.exe",
"C_Cpp_Runner.cStandard": "gnu11",
"C_Cpp_Runner.cppStandard": "gnu++11",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [
"C:/Users/adria/Documents/Schule/OST/Repositories/praktika-grulait/Pruefungsvorbereitung/Programme/Uebungsprogramm26/include",
"C:/Users/adria/Documents/Schule/OST/Repositories/praktika-grulait/Pruefungsvorbereitung/Programme/Uebungsprogramm26/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/cores/arduino",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/variants/standard",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/HID/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
""
],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
\ No newline at end of file
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
; 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
; https://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = Servo
#include "Door.h"
/******************************************************************
Helper Functions
******************************************************************/
String createIdentifierFor(String name) {
return "[" + name + "] ";
}
/******************************************************************
Public Functions
******************************************************************/
Door::Door(String name, int buttonPin, int servoPin, int openPos, int closePos)
: name{name}, buttonPin{buttonPin}, servoPin{servoPin}, openPos{openPos}, closePos{closePos}
{
state = T_CLOSING;
position = closePos;
lastPosition = position;
};
void Door::begin() {
doorDrive.attach(servoPin, 1000, 2000);
pinMode(buttonPin, INPUT);
}
void Door::loop() {
switch (state) {
case S_OPEN:
if (!digitalRead(buttonPin)) {
enterTransition(T_CLOSING, "Closing");
}
break;
case T_OPENING:
open();
if (position >= openPos) {
enterState(S_OPEN, "OPEN");
}
break;
case S_CLOSED:
if (digitalRead(buttonPin)) {
enterTransition(T_OPENING, "Opening");
}
break;
case T_CLOSING:
close();
if (position <= closePos) {
enterState(S_CLOSED, "Closed");
}
break;
}
logPosition();
}
/******************************************************************
Private Functions
******************************************************************/
void Door::open() {
position++;
doorDrive.write(position);
}
void Door::close() {
position++;
doorDrive.write(position);
}
void Door::logPosition() {
if (lastPosition != position) {
Serial.println(createIdentifierFor(name) + "@ position " + position);
}
lastPosition = position;
}
void Door::enterState(Door::DoorStates newState, String newStateName) {
state = newState;
Serial.println(createIdentifierFor(name) + "Entered State: " + newStateName);
}
void Door::enterTransition(Door::DoorStates newTransition, String newTransitionName) {
state = newTransition;
Serial.println(createIdentifierFor(name) + "Entered Transition: " + newTransitionName);
}
#pragma once
#include <Arduino.h>
#include <Servo.h>
class Door {
public:
Door(String name, int buttonPin, int servoPin, int openPos, int closePos); // openPos muss grösser als closePos sein
void begin();
void loop();
private:
enum DoorStates{S_OPEN, T_OPENING, T_CLOSING, S_CLOSED};
DoorStates state;
String name;
int position;
int lastPosition;
int buttonPin;
int servoPin;
int openPos;
int closePos;
Servo doorDrive;
void open();
void close();
void logPosition();
void enterState(Door::DoorStates newState, String newStateName);
void enterTransition(Door::DoorStates newTransition, String newTransitionName);
};
\ No newline at end of file
// Hinwei: Der nachfolgende Code ist ein Nachbau der Übung "8.2 lecture turtorial doors".
#include <Arduino.h>
#include "Door.h"
const int SERVO_PIN1{3};
const int SERVO_PIN2{3};
const int BUTTON_PIN1{3};
const int BUTTON_PIN2{3};
Door door1("Door 1", BUTTON_PIN1, SERVO_PIN1, 180, 90);
Door door2("Door 2", BUTTON_PIN2, SERVO_PIN2, 180, 90);
void setup() {
Serial.begin(9600);
door1.begin();
door2.begin();
}
void loop() {
door1.loop();
door2.loop();
delay(10);
}
\ No newline at end of file
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
{
"C_Cpp_Runner.cCompilerPath": "C:/Users/adria/.platformio/packages/toolchain-atmelavr/bin/avr-gcc.exe",
"C_Cpp_Runner.cppCompilerPath": "C:/Users/adria/.platformio/packages/toolchain-atmelavr/bin/avr-g++.exe",
"C_Cpp_Runner.debuggerPath": "C:/Users/adria/.platformio/packages/toolchain-atmelavr/bin/avr-gdb.exe",
"C_Cpp_Runner.cStandard": "gnu11",
"C_Cpp_Runner.cppStandard": "gnu++11",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [
"C:/Users/adria/Documents/Schule/OST/Repositories/praktika-grulait/Uebung_8.2_lecture-tutorial-doors/src",
"C:/Users/adria/Documents/Schule/OST/Repositories/praktika-grulait/Uebung_8.2_lecture-tutorial-doors/.pio/libdeps/uno/Servo/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/cores/arduino",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/variants/standard",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/HID/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
"C:/Users/adria/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
""
],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
\ No newline at end of file
<diagram program="umletino" version="15.1"><zoom_level>10</zoom_level></diagram>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment