Skip to content
Snippets Groups Projects
Commit 6f90cf57 authored by Mattis Lamprecht's avatar Mattis Lamprecht
Browse files

Alle Dateien reinkopieren

parent 6af9a76a
No related branches found
No related tags found
No related merge requests found
.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/matti/.platformio/packages/toolchain-atmelavr/bin/avr-gcc.exe",
"C_Cpp_Runner.cppCompilerPath": "C:/Users/matti/.platformio/packages/toolchain-atmelavr/bin/avr-g++.exe",
"C_Cpp_Runner.debuggerPath": "C:/Users/matti/.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/matti/Repositories/praktika-grulait/3PosDoor/include",
"C:/Users/matti/Repositories/praktika-grulait/3PosDoor/src",
"C:/Users/matti/.platformio/packages/framework-arduino-avr/cores/arduino",
"C:/Users/matti/.platformio/packages/framework-arduino-avr/variants/standard",
"C:/Users/matti/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
"C:/Users/matti/.platformio/packages/framework-arduino-avr/libraries/HID/src",
"C:/Users/matti/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
"C:/Users/matti/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
"C:/Users/matti/.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
#include "Door.h"
String createIdentifierFor(String name) {
return "[" + name + "] ";
}
Door::Door(String name, int buttonPin, int servoPin, int openPos, int closePos)
: name{name}, buttonPin{buttonPin}, servoPin{servoPin}, openPos{openPos}, closePos{closePos}
{
state = S_CLOSED;
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();
}
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
/*
Door Class
Written by Felix Nyffenegger
Refactored by Lukas Kretschmar =)
*/
#include <Arduino.h>
#include <Servo.h>
class Door
{
public:
Door(String name, int buttonPin, int servoPin, int openPos, int closePos);
void begin();
void loop();
private:
enum DoorStates{S_OPEN, T_OPENING, T_CLOSING, S_CLOSED};
String name;
int position;
int lastPosition;
int buttonPin;
int servoPin;
int openPos;
int closePos;
DoorStates state;
Servo doorDrive;
void open();
void close();
void logPosition();
void enterState(Door::DoorStates newState, String newStateName);
void enterTransition(Door::DoorStates newTransition, String newTransitionName);
};
#include <Arduino.h>
#include "Door.h"
const int SERVO_PIN1{3};
const int SERVO_PIN2{6};
const int BUTTON_PIN1{2};
const int BUTTON_PIN2{7};
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
<circuit type="simulide_1.0" rev="1007" stepSize="1000000" stepsPS="1000000" NLsteps="100000" animate="0" >
<item itemtype="Fixed Voltage" CircId="Fixed Voltage-54" mainComp="false" Show_id="false" Show_Val="true" Pos="-280,-164" rotation="0" hflip="1" vflip="1" label="Fixed Voltage-54" idLabPos="-64,-24" labelrot="0" valLabPos="-16,8" valLabRot="0" Out="true" Voltage="5 V" />
<item itemtype="Fixed Voltage" CircId="Fixed Voltage-52" mainComp="false" Show_id="false" Show_Val="true" Pos="-280,-208" rotation="0" hflip="1" vflip="1" label="Fixed Voltage-52" idLabPos="-64,-24" labelrot="0" valLabPos="-16,8" valLabRot="0" Out="true" Voltage="5 V" />
<item itemtype="Servo" CircId="Servo-42" mainComp="false" Show_id="true" Show_Val="false" Pos="-12,-164" rotation="0" hflip="1" vflip="1" label="Servo-2" idLabPos="-16,-40" labelrot="0" valLabPos="0,0" valLabRot="0" Speed="0.2 _sec/60º" Input_High_V="2.5 V" Input_Low_V="2.5 V" Input_Imped="1e+09 Ω" />
<item itemtype="Rail" CircId="Rail-41" mainComp="false" ShowProp="Voltage" Show_id="false" Show_Val="true" Pos="-92,-180" rotation="0" hflip="1" vflip="1" label="Rail-3" idLabPos="-16,-24" labelrot="0" valLabPos="-6,-22" valLabRot="0" Voltage="5 V" />
<item itemtype="Ground" CircId="Ground-40" mainComp="false" Show_id="false" Show_Val="false" Pos="-100,-164" rotation="90" hflip="1" vflip="1" label="Ground-4" idLabPos="-16,8" labelrot="0" valLabPos="0,0" valLabRot="0" />
<item itemtype="Ground" CircId="Ground-4" mainComp="false" Show_id="false" Show_Val="false" Pos="-100,-248" rotation="90" hflip="1" vflip="1" label="Ground-4" idLabPos="-16,8" labelrot="0" valLabPos="0,0" valLabRot="0" />
<item itemtype="Rail" CircId="Rail-3" mainComp="false" ShowProp="Voltage" Show_id="false" Show_Val="true" Pos="-92,-264" rotation="0" hflip="1" vflip="1" label="Rail-3" idLabPos="-16,-24" labelrot="0" valLabPos="-6,-22" valLabRot="0" Voltage="5 V" />
<item itemtype="Subcircuit" CircId="Uno-2" mainComp="false" Show_id="true" Show_Val="false" Pos="-332,-152" rotation="90" hflip="1" vflip="1" label="Arduino Uno-2" idLabPos="100,-21" labelrot="0" valLabPos="0,0" valLabRot="0" Logic_Symbol="false">
<mainCompProps itemtype="MCU" CircId="2_mega328-109" mainComp="true" Show_id="false" Show_Val="false" Pos="20,20" rotation="0" hflip="1" vflip="1" label="2_mega328-109" idLabPos="0,-20" labelrot="0" valLabPos="-16,20" valLabRot="0" Frequency="16 MHz" Program="../.pio/build/uno/firmware.hex" Auto_Load="false" Rst_enabled="true" Ext_Osc="true" Wdt_enabled="false" />
</item>
<item itemtype="Servo" CircId="Servo-1" mainComp="false" Show_id="true" Show_Val="false" Pos="-12,-248" rotation="0" hflip="1" vflip="1" label="Servo-1" idLabPos="-16,-40" labelrot="0" valLabPos="0,0" valLabRot="0" Speed="0.2 _sec/60º" Input_High_V="2.5 V" Input_Low_V="2.5 V" Input_Imped="1e+09 Ω" />
<item itemtype="Connector" uid="Connector-6" startpinid="Rail-3-outnod" endpinid="Servo-1-in0" pointList="-76,-264,-60,-264" />
<item itemtype="Connector" uid="Connector-11" startpinid="Ground-4-Gnd" endpinid="Servo-1-in1" pointList="-84,-248,-60,-248" />
<item itemtype="Connector" uid="Connector-43" startpinid="Ground-40-Gnd" endpinid="Servo-42-in1" pointList="-84,-164,-60,-164" />
<item itemtype="Connector" uid="Connector-45" startpinid="Rail-41-outnod" endpinid="Servo-42-in0" pointList="-76,-180,-60,-180" />
<item itemtype="Connector" uid="Connector-50" startpinid="Uno-2-3" endpinid="Servo-1-in2" pointList="-180,-112,-180,-232,-60,-232" />
<item itemtype="Connector" uid="Connector-51" startpinid="Servo-42-in2" endpinid="Uno-2-6" pointList="-60,-148,-204,-148,-204,-112" />
<item itemtype="Connector" uid="Connector-55" startpinid="Uno-2-2" endpinid="Fixed Voltage-52-outnod" pointList="-172,-112,-172,-208,-264,-208" />
<item itemtype="Connector" uid="Connector-56" startpinid="Uno-2-7" endpinid="Fixed Voltage-54-outnod" pointList="-212,-112,-212,-164,-264,-164" />
</circuit>
\ 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